code: def _maybe_validate_perm(
      initial_rightmost_transposed_ndims, perm, validate_args, name=None
  ):
      """Checks that `perm` is valid."""
      with tf.name_scope(name or "maybe_validate_perm"):
          assertions = []
          if not dtype_util.is_integer(perm.dtype):
              raise TypeError("`perm` must be integer type")
  
          msg = "`perm` must be a vector."
          if tensorshape_util.rank(perm.shape) is not None:
              if tensorshape_util.rank(perm.shape) != 1:
                  raise ValueError(
                      msg[:-1]
                      + ", saw rank: {}.".format(
                          tensorshape_util.rank(perm.shape)
                      )
                  )
          elif validate_args:
              assertions += [
                  assert_util.assert_rank(perm, 1, message=msg),
                  assert_util.assert_equal(
                      tf.size(perm),
                      initial_rightmost_transposed_ndims,
                      message="The number of elements of `perm` must not "
                      "change from the value set when the `Transpose` "
                      "bijector was constructed.",
                  ),
              ]
  
          perm_ = tf.get_static_value(perm)
          msg = "`perm` must be a valid permutation vector."
          if perm_ is not None:
              if not np.all(
                  np.arange(np.size(perm_)) == np.sort(perm_)
              ):
                  raise ValueError(
                      msg[:-1] + ", saw: {}.".format(perm_)
                  )
          elif validate_args:
              assertions += [
                  assert_util.assert_equal(
                      ps.sort(perm),
                      ps.range(ps.size(perm, out_type=perm.dtype)),
                      message=msg,
                  )
              ]
  
          return assertions
  
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 distribution_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 2 for calling a global function with example usage: _maybe_validate_perm(initial_rightmost_transposed_ndims, perm, validate_args, name) and returns: assertions