code: def rank_from_shape(shape_tensor_fn, tensorshape=None):
      """Computes `rank` given a `Tensor`'s `shape`."""
      # Note: this function will implicitly interpret scalar "shapes" as length-1
      # vectors.
      if tensorshape is None:
          shape_tensor = (
              shape_tensor_fn()
              if callable(shape_tensor_fn)
              else shape_tensor_fn
          )
          shape_tensor_ = tf.get_static_value(shape_tensor)
          if shape_tensor_ is not None:
              shape_tensor = np.int32(shape_tensor_)
          elif not hasattr(shape_tensor, "shape"):
              shape_tensor = tf.convert_to_tensor(shape_tensor)
          ndims_ = tensorshape_util.num_elements(shape_tensor.shape)
          ndims_fn = lambda: tf.size(shape_tensor)
      else:
          ndims_ = tensorshape_util.rank(tensorshape)
          ndims_fn = lambda: tf.size(  # pylint: disable=g-long-lambda
              shape_tensor_fn()
              if callable(shape_tensor_fn)
              else shape_tensor_fn
          )
      return ndims_fn() if ndims_ is None else np.int32(ndims_)
  
imports: import decorator
  import numpy
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal.backend import numpy
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import control_flow_case
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 9 for calling a global function with example usage: rank_from_shape(shape_tensor_fn, tensorshape) and returns: unknown