code: def _get_static_ndims(
      x,
      expect_static=False,
      expect_ndims=None,
      expect_ndims_no_more_than=None,
      expect_ndims_at_least=None,
  ):
      """Get static number of dimensions and assert that some expectations are met.
  
      This function returns the number of dimensions 'ndims' of x, as a Python int.
  
      The optional expect arguments are used to check the ndims of x, but this is
      only done if the static ndims of x is not None.
  
      Args:
        x:  A Tensor.
        expect_static:  Expect `x` to have statically defined `ndims`.
        expect_ndims:  Optional Python integer.  If provided, assert that x has
          number of dimensions equal to this.
        expect_ndims_no_more_than:  Optional Python integer.  If provided, assert
          that x has no more than this many dimensions.
        expect_ndims_at_least:  Optional Python integer.  If provided, assert that x
          has at least this many dimensions.
  
      Returns:
        ndims:  A Python integer.
  
      Raises:
        ValueError:  If any of the expectations above are violated.
      """
      ndims = tensorshape_util.rank(x.shape)
  
      if ndims is None:
          if expect_static:
              raise ValueError(
                  "Expected argument `x` to have statically defined `ndims`. "
                  "Found: {}.".format(x)
              )
          return
  
      if expect_ndims is not None:
          ndims_message = "Expected argument `x` to have ndims {}. Found tensor {}.".format(
              expect_ndims, x
          )
          if ndims != expect_ndims:
              raise ValueError(ndims_message)
  
      if expect_ndims_at_least is not None:
          ndims_at_least_message = "Expected argument `x` to have ndims >= {}. Found tensor {}.".format(
              expect_ndims_at_least, x
          )
          if ndims < expect_ndims_at_least:
              raise ValueError(ndims_at_least_message)
  
      if expect_ndims_no_more_than is not None:
          ndims_no_more_than_message = "Expected argument `x` to have ndims <= {}. Found tensor {}.".format(
              expect_ndims_no_more_than, x
          )
          if ndims > expect_ndims_no_more_than:
              raise ValueError(ndims_no_more_than_message)
  
      return ndims
  
file_path: probability/tensorflow_probability/python/stats/quantiles.py
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 6 for calling a global function with example usage: _get_static_ndims(x, expect_static, expect_ndims, expect_ndims_no_more_than, expect_ndims_at_least) and returns: ndims