code: def test_kernel_gradient(kernel):
      # Compare analytic and numeric gradient of kernels.
      K, K_gradient = kernel(X, eval_gradient=True)
  
      assert K_gradient.shape[0] == X.shape[0]
      assert K_gradient.shape[1] == X.shape[0]
      assert K_gradient.shape[2] == kernel.theta.shape[0]
  
      def eval_kernel_for_theta(theta):
          kernel_clone = kernel.clone_with_theta(theta)
          K = kernel_clone(X, eval_gradient=False)
          return K
  
      K_gradient_approx = _approx_fprime(
          kernel.theta, eval_kernel_for_theta, 1e-10
      )
  
      assert_almost_equal(K_gradient, K_gradient_approx, 4)
  
imports: from inspect import signature
  import numpy
  import pytest
  from sklearn.base import clone
  from sklearn.gaussian_process.kernels import RBF, CompoundKernel, ConstantKernel, DotProduct, Exponentiation, ExpSineSquared, KernelOperator, Matern, PairwiseKernel, RationalQuadratic, WhiteKernel, _approx_fprime
  from sklearn.metrics.pairwise import PAIRWISE_KERNEL_FUNCTIONS, euclidean_distances, pairwise_kernels
  from sklearn.utils._testing import assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_kernel_gradient(kernel) and returns: K