code: def log1psquare(x, name=None):
      """Numerically stable calculation of `log(1 + x**2)` for small or large `|x|`.
  
      For sufficiently large `x` we use the following observation:
  
      ```none
      log(1 + x**2) =   2 log(|x|) + log(1 + 1 / x**2)
                    --> 2 log(|x|)  as x --> inf
      ```
  
      Numerically, `log(1 + 1 / x**2)` is `0` when `1 / x**2` is small relative to
      machine epsilon.
  
      Args:
        x: Float `Tensor` input.
        name: Python string indicating the name of the TensorFlow operation.
          Default value: `'log1psquare'`.
  
      Returns:
        log1psq: Float `Tensor` representing `log(1. + x**2.)`.
      """
      with tf.name_scope(name or "log1psquare"):
          x = tf.convert_to_tensor(x, dtype_hint=tf.float32, name="x")
          dtype = dtype_util.as_numpy_dtype(x.dtype)
  
          eps = np.finfo(dtype).eps.astype(np.float64)
          is_large = tf.abs(x) > (eps**-0.5).astype(dtype)
  
          # Mask out small x's so the gradient correctly propagates.
          abs_large_x = tf.where(
              is_large, tf.abs(x), tf.ones([], x.dtype)
          )
          return tf.where(
              is_large,
              dtype(2.0) * tf.math.log(abs_large_x),
              tf.math.log1p(tf.square(x)),
          )
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
label_desc: Use image node_id 1 for calling a global function with example usage: log1psquare(x, name) and returns: tf