code: def _test_slicing(
      self, data, kernel_name, kernel, feature_dim, feature_ndims
  ):
      example_ndims = data.draw(hps.integers(min_value=0, max_value=2))
      batch_shape = kernel.batch_shape
      slices = data.draw(tfp_hps.valid_slices(batch_shape))
      slice_str = "kernel[{}]".format(
          ", ".join(tfp_hps.stringify_slices(slices))
      )
      # Make sure the slice string appears in Hypothesis' attempted example log
      hp.note("Using slice " + slice_str)
      if not slices:  # Nothing further to check.
          return
      sliced_zeros = np.zeros(batch_shape)[slices]
      sliced_kernel = kernel[slices]
      hp.note("Using sliced kernel {}.".format(sliced_kernel))
      hp.note("Using sliced zeros {}.".format(sliced_zeros.shape))
  
      # Check that slicing modifies batch shape as expected.
      self.assertAllEqual(sliced_zeros.shape, sliced_kernel.batch_shape)
  
      xs = tf.identity(
          data.draw(
              kernel_hps.kernel_input(
                  batch_shape=[],
                  example_ndims=example_ndims,
                  feature_dim=feature_dim,
                  feature_ndims=feature_ndims,
              )
          )
      )
  
      # Check that apply of sliced kernels executes.
      with tfp_hps.no_tf_rank_errors():
          results = self.evaluate(
              kernel.apply(xs, xs, example_ndims=example_ndims)
          )
          hp.note("Using results shape {}.".format(results.shape))
          sliced_results = self.evaluate(
              sliced_kernel.apply(xs, xs, example_ndims=example_ndims)
          )
  
      # Come up with the slices for apply (which must also include example dims).
      apply_slices = (
          tuple(slices)
          if isinstance(slices, collections.abc.Sequence)
          else (slices,)
      )
      apply_slices += tuple([slice(None)] * example_ndims)
  
      # Check that applying a sliced kernel produces the same results as slicing
      # the results from the original.
      self.assertAllClose(
          results[apply_slices], sliced_results, rtol=1e-5
      )
  
file_path: probability/tensorflow_probability/python/math/psd_kernels/psd_kernel_properties_test.py
imports: import collections
  from absl.testing import parameterized
  import hypothesis
  from hypothesis import strategies
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import hypothesis_testlib
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.psd_kernels import hypothesis_testlib
label_desc: Use image node_id 1 for calling the PSDKernelSlicingTest obj's underlying member method code with example usage: obj._test_slicing(data, kernel_name, kernel, feature_dim, feature_ndims) without return types