code: def _assert_ndims_statically(
      x,
      expect_ndims=None,
      expect_ndims_at_least=None,
      expect_static=False,
  ):
      """Assert that Tensor x has expected number of dimensions."""
      ndims = tensorshape_util.rank(x.shape)
      if ndims is None:
          if expect_static:
              raise ValueError(
                  "Expected static ndims. Found: {}".format(x)
              )
          return
      if expect_ndims is not None and ndims != expect_ndims:
          raise ValueError(
              "ndims must be {}.  Found: {}".format(expect_ndims, ndims)
          )
      if (
          expect_ndims_at_least is not None
          and ndims < expect_ndims_at_least
      ):
          raise ValueError(
              "ndims must be at least {}. Found {}".format(
                  expect_ndims_at_least, ndims
              )
          )
  
imports: import itertools
  import numpy
  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 tensorshape_util
label_desc: Use image node_id 7 for calling a global function with example usage: _assert_ndims_statically(x, expect_ndims, expect_ndims_at_least, expect_static) without return types