code: def _rank_from_shape(x):
      """Returns the rank implied by this shape."""
      if not hasattr(x, "shape"):
          return tf.TensorShape(x).rank
      else:
          # If the input is a Tensor, we can't make a `TensorShape` out of it
          # directly:
          # - In graph mode, `TensorShape` complains that it can't iterate over a
          #   Tensor.
          # - In eager mode, the underlying `Dimension` complains that a scalar
          #   integer Tensor is actually an ambiguous dimension, because it !=
          #   int(it).
          # However, the (static) size of `x` is also the rank of the Tensor
          # it represents, which is what we want.
          return tf.TensorShape(x.shape).num_elements()
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 4 for calling a global function with example usage: _rank_from_shape(x) and returns: tf, tf