code: def test_rank_from_shape(self):
      shape = [2, 4, 3]
      expected_rank = len(shape)
      v_ndarray = np.ones(shape)
  
      # case: shape_tensor is tuple
      rank = ps.rank_from_shape(shape_tensor_fn=v_ndarray.shape)
      self.assertEqual(rank, expected_rank)
  
      # case: shape_tensor is ndarray
      rank = ps.rank_from_shape(shape_tensor_fn=ps.shape(v_ndarray))
      self.assertEqual(rank, expected_rank)
  
      # case: tensorshape is fully defined
      v_tensor = tf.convert_to_tensor(v_ndarray)
      rank = ps.rank_from_shape(
          shape_tensor_fn=ps.shape(v_tensor), tensorshape=v_tensor.shape
      )
      self.assertEqual(rank, expected_rank)
  
      if not tf.executing_eagerly():
          # case: tensorshape is unknown, rank cannot be statically inferred
          v_dynamic = tf1.placeholder_with_default(
              v_ndarray, shape=None
          )
          rank = ps.rank_from_shape(
              shape_tensor_fn=lambda: ps.shape(v_dynamic),
              tensorshape=v_dynamic.shape,
          )
          self.assertEqual(self.evaluate(rank), expected_rank)
  
          # case: tensorshape is not provided, rank cannot be statically inferred
          rank = ps.rank_from_shape(
              shape_tensor_fn=lambda: ps.shape(v_dynamic)
          )
          self.assertEqual(self.evaluate(rank), expected_rank)
  
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 6 for calling the ShapeTest obj's underlying member method code with example usage: obj.test_rank_from_shape() without return types