code: def assert_at_least_k_non_zero_entries(
      tensor: type_alias.TensorLike,
      k: int = 1,
      name: str = "assert_at_least_k_non_zero_entries",
  ) -> tf.Tensor:
      """Checks if `tensor` has at least k non-zero entries in the last dimension.
  
      Given a tensor with `M` dimensions in its last axis, this function checks
      whether at least `k` out of `M` dimensions are non-zero.
  
      Note:
        In the following, A1 to An are optional batch dimensions.
  
      Args:
        tensor: A tensor of shape `[A1, ..., An, M]`.
        k: An integer, corresponding to the minimum number of non-zero entries.
        name: A name for this op. Defaults to 'assert_at_least_k_non_zero_entries'.
  
      Raises:
        InvalidArgumentError: If `tensor` has less than `k` non-zero entries in its
          last axis.
  
      Returns:
        The input tensor, 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)
  
          indicator = tf.cast(
              tf.math.greater(tensor, 0.0), dtype=tensor.dtype
          )
          indicator_sum = tf.reduce_sum(input_tensor=indicator, axis=-1)
          assert_op = tf.debugging.assert_greater_equal(
              indicator_sum, tf.cast(k, dtype=tensor.dtype)
          )
          with tf.control_dependencies([assert_op]):
              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 7 for calling a global function with example usage: assert_at_least_k_non_zero_entries(tensor, k, name) and returns: tensor, tf