code: def test_kernel_gradient():
      rng = np.random.RandomState(0)
      hm = HammingKernel(length_scale=2.0)
      X = rng.randint(0, 4, (5, 3))
      K, K_gradient = hm(X, eval_gradient=True)
      assert_array_equal(K_gradient.shape, (5, 5, 1))
  
      def eval_kernel_for_theta(theta, kernel):
          kernel_clone = kernel.clone_with_theta(theta)
          K = kernel_clone(X, eval_gradient=False)
          return K
  
      K_gradient_approx = _approx_fprime(
          hm.theta, eval_kernel_for_theta, 1e-10, (hm,)
      )
      assert_array_almost_equal(K_gradient_approx, K_gradient, 4)
  
      hm = HammingKernel(length_scale=[1.0, 1.0, 1.0])
      K_gradient_approx = _approx_fprime(
          hm.theta, eval_kernel_for_theta, 1e-10, (hm,)
      )
      K, K_gradient = hm(X, eval_gradient=True)
      assert_array_equal(K_gradient.shape, (5, 5, 3))
      assert_array_almost_equal(K_gradient_approx, K_gradient, 4)
  
      X = rng.randint(0, 4, (3, 2))
      hm = HammingKernel(length_scale=[0.1, 2.0])
      K_gradient_approx = _approx_fprime(
          hm.theta, eval_kernel_for_theta, 1e-10, (hm,)
      )
      K, K_gradient = hm(X, eval_gradient=True)
      assert_array_equal(K_gradient.shape, (3, 3, 2))
      assert_array_almost_equal(K_gradient_approx, K_gradient, 4)
  
imports: import numpy
  from scipy import optimize
  from scipy.spatial.distance import pdist, squareform
  from numpy.testing import assert_array_almost_equal
  from numpy.testing import assert_array_equal
  import pytest
  from skopt.learning.gaussian_process import GaussianProcessRegressor
  from skopt.learning.gaussian_process.kernels import ConstantKernel
  from skopt.learning.gaussian_process.kernels import DotProduct
  from skopt.learning.gaussian_process.kernels import ExpSineSquared
  from skopt.learning.gaussian_process.kernels import HammingKernel
  from skopt.learning.gaussian_process.kernels import Matern
  from skopt.learning.gaussian_process.kernels import RationalQuadratic
  from skopt.learning.gaussian_process.kernels import RBF
  from skopt.learning.gaussian_process.kernels import WhiteKernel
label_desc: Use image node_id 10 for calling a global function with example usage: test_kernel_gradient() and returns: K