code: def assert_no_infs_or_nans(
      tensor: type_alias.TensorLike,
      name: str = "assert_no_infs_or_nans",
  ) -> tf.Tensor:
      """Checks a tensor for NaN and Inf values.
  
      Note:
        In the following, A1 to An are optional batch dimensions.
  
      Args:
        tensor: A tensor of shape `[A1, ..., An]` containing the values we want to
          check.
        name: A name for this op. Defaults to 'assert_no_infs_or_nans'.
  
      Raises:
        tf.errors.InvalidArgumentError: If any entry of the input is NaN or Inf.
  
      Returns:
        The input vector, with dependence on the assertion operator in the graph.
      """
      if not FLAGS[tfg_flags.TFG_ADD_ASSERTS_TO_GRAPH].value:
          return tensor
  
      with tf.name_scope(name):
          tensor = tf.convert_to_tensor(value=tensor)
  
          assert_ops = (
              tf.debugging.check_numerics(
                  tensor, message="Inf or NaN detected."
              ),
          )
          with tf.control_dependencies(assert_ops):
              return tf.identity(tensor)
  
file_path: graphics/tensorflow_graphics/util/asserts.py
imports: from typing import Optional
  from absl import flags
  import numpy
  import tensorflow
  from tensorflow_graphics.util import tfg_flags
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 1 for calling a global function with example usage: assert_no_infs_or_nans(tensor, name) and returns: tensor, tf