code: def safe_sum(x, alt_value=-np.inf, name=None):
      """Elementwise adds list members, replacing non-finite results with alt_value.
  
      Typically the `alt_value` is chosen so the `MetropolisHastings`
      `TransitionKernel` always rejects the proposal.
  
      Args:
        x: Python `list` of `Tensors` to elementwise add.
        alt_value: Python scalar used to replace any elementwise sums which would
          otherwise be non-finite.
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., "safe_sum").
  
      Returns:
        safe_sum: `Tensor` representing the elementwise sum of list of `Tensor`s
          `x` or `alt_value` where sums are non-finite.
  
      Raises:
        TypeError: if `x` is not list-like.
        ValueError: if `x` is empty.
      """
      with tf.name_scope(name or "safe_sum"):
          if not is_list_like(x):
              raise TypeError("Expected list input.")
          if not x:
              raise ValueError("Input should not be empty.")
          in_shape = x[0].shape
          x = tf.add_n(x)
          x = tf.where(
              tf.math.is_finite(x),
              x,
              tf.constant(alt_value, dtype=x.dtype),
          )
          tensorshape_util.set_shape(x, in_shape)
          return x
  
imports: import warnings
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import broadcast_util
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math.gradient import value_and_gradient
  from tensorflow.python.util import deprecation
label_desc: Use image node_id 11 for calling a global function with example usage: safe_sum(x, alt_value, name) and returns: x