import tensorflow as tf

      if (rightmost_transposed_ndims is None) == (perm is None):
        raise ValueError('Must specify exactly one of '
                         '`rightmost_transposed_ndims` and `perm`.')
      if rightmost_transposed_ndims is not None:
        rightmost_transposed_ndims = tf.convert_to_tensor(
            value=rightmost_transposed_ndims,
            dtype=np.int32,
            name='rightmost_transposed_ndims')
        rightmost_transposed_ndims_ = tf.get_static_value(
            rightmost_transposed_ndims)
        with tf.control_dependencies(_maybe_validate_rightmost_transposed_ndims(
            rightmost_transposed_ndims, validate_args)):
          rightmost_transposed_ndims = tf.identity(rightmost_transposed_ndims)
        perm = tf.range(
            start=rightmost_transposed_ndims - 1,
            limit=-1,
