code: def _nc2_log_prob(x, df, noncentrality):
      """Computes the log probability of a noncentral Chi2 random variable.
  
      Note: the (pseudo) log probability can be evaluate for nonpositive degrees of
      freedom as well, but the results might be wrong as `log_bessel_ive` does not
      return the sign of its result.
  
      Args:
        x: `tf.Tensor` of locations at which to compute the log probability.
        df: `tf.Tensor` of the degrees of freedom of the NC2 variate.
        noncentrality: `tf.Tensor` of the noncentrality of the NC2 variate.
  
      Returns:
        `tf.Tensor` of log probabilities.
      """
      numpy_dtype = dtype_util.as_numpy_dtype(df.dtype)
      log2 = numpy_dtype(np.log(2.0))
  
      safe_noncentrality_mask = noncentrality > 0.0
      safe_noncentrality = tf.where(
          safe_noncentrality_mask, noncentrality, 1.0
      )
  
      sqrt_x = tf.math.sqrt(x)
      sqrt_nc = tf.math.sqrt(safe_noncentrality)
  
      df_factor = 0.25 * df - 0.5
  
      log_prob = -log2 - 0.5 * tf.math.square(sqrt_x - sqrt_nc)
      log_prob = log_prob + tf.math.xlogy(df_factor, x)
      log_prob = log_prob - tf.math.xlogy(df_factor, safe_noncentrality)
      log_prob = log_prob + bessel.log_bessel_ive(
          2.0 * df_factor, sqrt_nc * sqrt_x
      )
  
      log_prob = tf.where(
          safe_noncentrality_mask,
          log_prob,
          chi2_lib.Chi2(df).log_prob(x),
      )
  
      return log_prob
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import chi2
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import poisson
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import special_math
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.math import bessel
  from tensorflow_probability.python.math import generic
  from tensorflow_probability.python.math import root_search
  import tensorflow_probability.python.random
label_desc: Use image node_id 1 for calling a global function with example usage: _nc2_log_prob(x, df, noncentrality) and returns: log_prob