code: def test_shape_slice(self):
      shape = [3, 2, 1]
      slice_ = slice(1, 2)
      slice_tensor = slice(tf.constant(1), tf.constant(2))
  
      # case: numpy input.
      self.assertEqual(
          ps.shape_slice(np.zeros(shape), slice_), shape[slice_]
      )
      self.assertEqual(
          ps.shape_slice(np.zeros(shape), slice_tensor), shape[slice_]
      )
  
      # case: static-shape Tensor input.
      self.assertEqual(
          ps.shape_slice(tf.zeros(shape), slice_), shape[slice_]
      )
      self.assertNotIsInstance(
          ps.shape_slice(tf.zeros(shape), slice_), tf.TensorShape
      )
      self.assertEqual(
          ps.shape_slice(tf.zeros(shape), slice_tensor), shape[slice_]
      )
      self.assertNotIsInstance(
          ps.shape_slice(tf.zeros(shape), slice_tensor), tf1.Dimension
      )
  
      if tf.executing_eagerly():
          return
  
      # Case: input is Tensor with fully unknown shape.
      zeros_pl = tf1.placeholder_with_default(
          tf.zeros(shape), shape=None
      )
      slice_pl = slice(
          tf1.placeholder_with_default(1, shape=[]),
          tf1.placeholder_with_default(2, shape=[]),
      )
      self.assertAllEqual(
          ps.shape_slice(zeros_pl, slice_), shape[slice_]
      )
      self.assertAllEqual(
          ps.shape_slice(zeros_pl, slice_tensor), shape[slice_]
      )
      self.assertAllEqual(
          ps.shape_slice(zeros_pl, slice_pl), shape[slice_]
      )
  
      # Case: input is Tensor with partially known shape.
      # The result should be static if slice_ is.
      zeros_partial_pl = tf1.placeholder_with_default(
          tf.zeros(shape), shape=tf.TensorShape([None, 2, 1])
      )
      self.assertEqual(
          ps.shape_slice(zeros_partial_pl, slice_), shape[slice_]
      )
      self.assertEqual(
          ps.shape_slice(zeros_partial_pl, slice_tensor), shape[slice_]
      )
      self.assertAllEqual(
          ps.shape_slice(zeros_partial_pl, slice_pl), shape[slice_]
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 5 for calling the ShapeTest obj's underlying member method code with example usage: obj.test_shape_slice() without return types