code: def testGradient(self):
      num_categories = [5, 3]
      x1_cat = np.stack(
          [np.random.randint(n, size=(10,)) for n in num_categories],
          axis=-1,
      )
      x2_cat = np.stack(
          [np.random.randint(n, size=(8,)) for n in num_categories],
          axis=-1,
      )
  
      x1_cont = np.ones([x1_cat.shape[0], 2]).astype(np.float32)
      x2_cont = np.ones([x2_cat.shape[0], 2]).astype(np.float32)
      x1 = fswc.ContinuousAndCategoricalValues(x1_cont, x1_cat)
      x2 = fswc.ContinuousAndCategoricalValues(x2_cont, x2_cat)
  
      sd_continuous = np.random.uniform(size=[2], high=10.0).astype(
          np.float32
      )
      sd_categorical = [
          np.random.uniform(size=[n], high=10.0).astype(np.float32)
          for n in num_categories
      ]
      sd = (sd_continuous, sd_categorical)
  
      def _kernel_mat_first_entry(sd):
          sd_cont, cat_diags = sd
          base_kernel = exponentiated_quadratic.ExponentiatedQuadratic()
          cat_ops = [tf.linalg.LinearOperatorDiag(d) for d in cat_diags]
          kernel = fswec.FeatureScaledWithEmbeddedCategorical(
              base_kernel,
              categorical_embedding_operators=cat_ops,
              continuous_scale_diag=sd_cont,
              validate_args=True,
          )
          return kernel.matrix(x1, x2)[0, 0]
  
      y, grad = gradient.value_and_gradient(
          _kernel_mat_first_entry, sd, auto_unpack_single_arg=False
      )
      self.assertAllNotNone(tf.nest.flatten(grad))
      self.assertAllNotNan(y)
      self.assertAllAssertsNested(self.assertAllNotNan, grad)
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.psd_kernels import feature_scaled_with_categorical
  from tensorflow_probability.python.experimental.psd_kernels import feature_scaled_with_embedded_categorical
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.math.psd_kernels import exponentiated_quadratic
  from tensorflow_probability.python.math.psd_kernels import feature_scaled
  from tensorflow_probability.python.math.psd_kernels import matern
label_desc: Use image node_id 9 for calling the FeatureScaledWithCategoricalTest obj's underlying member method code with example usage: obj.testGradient() and returns: kernel