code: def _maybe_check_valid_shape(shape, validate_args):
      """Check that a shape Tensor is int-type and otherwise sane."""
      if not dtype_util.is_integer(shape.dtype):
          raise TypeError(
              "`{}` dtype (`{}`) should be `int`-like.".format(
                  shape, dtype_util.name(shape.dtype)
              )
          )
  
      assertions = []
  
      message = "`{}` rank should be <= 1."
      if tensorshape_util.rank(shape.shape) is not None:
          if tensorshape_util.rank(shape.shape) > 1:
              raise ValueError(message.format(shape))
      elif validate_args:
          assertions.append(
              assert_util.assert_less(
                  tf.rank(shape), 2, message=message.format(shape)
              )
          )
  
      shape_ = tf.get_static_value(shape)
  
      message = "`{}` elements must have at most one `-1`."
      if shape_ is not None:
          if sum(shape_ == -1) > 1:
              raise ValueError(message.format(shape))
      elif validate_args:
          assertions.append(
              assert_util.assert_less(
                  tf.reduce_sum(tf.cast(tf.equal(shape, -1), tf.int32)),
                  2,
                  message=message.format(shape),
              )
          )
  
      message = (
          "`{}` elements must be either positive integers or `-1`."
      )
      if shape_ is not None:
          if np.any(shape_ < -1):
              raise ValueError(message.format(shape))
      elif validate_args:
          assertions.append(
              assert_util.assert_greater(
                  shape, -2, message=message.format(shape)
              )
          )
  
      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 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 3 for calling a global function with example usage: _maybe_check_valid_shape(shape, validate_args) and returns: assertions