def reduce_batch_minus_min_and_max(
    x: common_types.TensorType,
    reduce_instance_dims: bool) -> Tuple[tf.Tensor, tf.Tensor]:
  """Computes the -min and max of a tensor x.

  NOTE: For TF versions < 2.4, if all feature values are NaNs, the -min and max
  will both be -inf (consistent with`tf.reduce_max`).

  Args:
    x: A `Tensor` or `CompositeTensor`.
    reduce_instance_dims: A bool indicating whether this should collapse the
      batch and instance dimensions to arrive at a single scalar output, or only
      collapse the batch dimension and outputs a vector of the same shape as the
      input.

  Returns:
    The computed tensor's (batch -min, batch max) pair.
  """
  # In TF < 2.3, neg(x) would throw an exception, if x was tf.int16. Hence, cast
  # to tf.int32.
  if x.dtype in (tf.uint8, tf.uint16, tf.int16):
    x = tf.cast(x, tf.int32)

  elif x.dtype == tf.uint32 or x.dtype == tf.uint64:
    raise TypeError('Tensor type %r is not supported' % x.dtype)

  if reduce_instance_dims:
    if isinstance(x, tf.SparseTensor):
      x = x.values
    elif isinstance(x, tf.RaggedTensor):
      x = x.flat_values

    x_batch_max = tf.reduce_max(input_tensor=x)
    x_batch_minus_min = tf.reduce_max(input_tensor=tf.zeros_like(x) - x)
    return x_batch_minus_min, x_batch_max

  elif isinstance(x, tf.SparseTensor):
    return _sparse_minus_reduce_min_and_reduce_max(x)

  x_batch_max = tf.reduce_max(input_tensor=x, axis=0)
  if isinstance(x, tf.RaggedTensor):
    x_batch_minus_min = tf.reduce_max(input_tensor=tf.math.negative(x), axis=0)
    missing_value = _get_missing_value(x.dtype)
    return (x_batch_minus_min.to_tensor(default_value=missing_value),
            x_batch_max.to_tensor(default_value=missing_value))
  else:
    # TODO(iindyk): switch to `tf.math.negative` when analyzer cache will get
    # invalidated next time.
    return (tf.reduce_max(input_tensor=0 - x, axis=0), x_batch_max)
Computes the -min and max of a tensor x.

  NOTE: For TF versions < 2.4, if all feature values are NaNs, the -min and max
  will both be -inf (consistent with`tf.reduce_max`).

  Args:
    x: A `Tensor` or `CompositeTensor`.
    reduce_instance_dims: A bool indicating whether this should collapse the
      batch and instance dimensions to arrive at a single scalar output, or only
      collapse the batch dimension and outputs a vector of the same shape as the
      input.

  Returns:
    The computed tensor's (batch -min, batch max) pair.
  
tensorflow_transform/tf_utils.py