code: def _temme_expansion(v, x, output_log_space=False):
      """Compute modified bessel functions using Temme's method."""
      # The implementation of this is based on [1].
      # [1] N. Temme, On the Numerical Evaluation of the Modified Bessel Function
      #   of the Third Kind. Journal of Computational Physics 19, 1975.
      dtype = dtype_util.common_dtype([v, x], tf.float32)
      numpy_dtype = dtype_util.as_numpy_dtype(dtype)
      v_less_than_zero = v < 0.0
      v = tf.math.abs(v)
      n = tf.math.round(v)
      # Use this to compute Kv(u, x) and Kv(u + 1., x)
      u = v - n
      x_abs = tf.math.abs(x)
  
      small_x = tf.where(x_abs <= 2.0, x_abs, numpy_dtype(0.1))
      large_x = tf.where(x_abs > 2.0, x_abs, numpy_dtype(1000.0))
      temme_kue, temme_kuep1 = _temme_series(
          u, small_x, output_log_space=output_log_space
      )
      cf_kue, cf_kuep1 = _continued_fraction_kv(
          u, large_x, output_log_space=output_log_space
      )
  
      kue = tf.where(x_abs <= 2.0, temme_kue, cf_kue)
      kuep1 = tf.where(x_abs <= 2.0, temme_kuep1, cf_kuep1)
  
      # Now use the forward recurrence for modified bessel functions
      # to compute Kv(v, x). That is,
      # K_{v + 1}(z) - (2v / z) K_v(z) - K_{v - 1}(z) = 0.
      # This is known to be forward numerically stable.
      # Note: This recurrence is also satisfied by K_v(z) * exp(z)
  
      def bessel_recurrence(index, kve, kvep1):
          if output_log_space:
              next_kvep1 = tfp_math.log_add_exp(
                  kvep1
                  + tf.math.log(u + index)
                  + numpy_dtype(np.log(2.0))
                  - tf.math.log(x_abs),
                  kve,
              )
          else:
              next_kvep1 = 2 * (u + index) * kvep1 / x_abs + kve
          kve = tf.where(index > n, kve, kvep1)
          kvep1 = tf.where(index > n, kvep1, next_kvep1)
          return index + 1.0, kve, kvep1
  
      _, kve, kvep1 = tf.while_loop(
          cond=lambda i, *_: tf.reduce_any(i <= n),
          body=bessel_recurrence,
          loop_vars=(tf.cast(1.0, dtype=dtype), kue, kuep1),
      )
  
      # Finally, it is known that the Wronskian
      # det(I_v * K'_v - K_v * I'_v) = - 1. / x. We can
      # use this to evaluate I_v by taking advantage of identities of Bessel
      # derivatives.
  
      if output_log_space:
          ive = -tf.math.log(x_abs) - tfp_math.log_add_exp(
              kve + tf.math.log(bessel_iv_ratio(v + 1.0, x)), kvep1
          )
      else:
          ive = tf.math.reciprocal(
              x_abs * (kve * bessel_iv_ratio(v + 1.0, x) + kvep1)
          )
  
      # We need to add a correction term for negative v.
  
      if output_log_space:
          log_ive = ive
          negative_v_correction = kve - 2.0 * x_abs
      else:
          log_ive = tf.math.log(ive)
          negative_v_correction = tf.math.log(kve) - 2.0 * x_abs
  
      coeff = 2 / np.pi * tf.math.sin(np.pi * u)
      coeff = (1.0 - 2.0 * tf.math.mod(n, 2.0)) * coeff
  
      lse, sign = tfp_math.log_sub_exp(
          log_ive,
          negative_v_correction + tf.math.log(tf.math.abs(coeff)),
          return_sign=True,
      )
      sign = tf.where(coeff < 0.0, sign, 1.0)
  
      log_ive_negative_v = tf.where(
          coeff < 0.0,
          lse,
          tfp_math.log_add_exp(
              log_ive,
              negative_v_correction + tf.math.log(tf.math.abs(coeff)),
          ),
      )
  
      z = u + tf.math.mod(n, 2.0)
  
      if output_log_space:
          ive = tf.where(v_less_than_zero, log_ive_negative_v, ive)
  
          ive = tf.where(
              tf.math.equal(x, 0.0),
              tf.where(
                  tf.math.equal(v, 0.0),
                  numpy_dtype(0.0),
                  numpy_dtype(-np.inf),
              ),
              ive,
          )
      else:
          ive = tf.where(
              v_less_than_zero,
              sign * tf.math.exp(log_ive_negative_v),
              ive,
          )
  
          ive = tf.where(
              tf.math.equal(x, 0.0),
              tf.where(
                  tf.math.equal(v, 0.0),
                  numpy_dtype(1.0),
                  numpy_dtype(0.0),
              ),
              ive,
          )
  
      ive = tf.where(
          tf.math.equal(x, 0.0) & v_less_than_zero,
          tf.where(
              tf.math.equal(z, tf.math.floor(z)),
              ive,
              numpy_dtype(np.inf),
          ),
          ive,
      )
  
      kve = tf.where(tf.math.equal(x, 0.0), numpy_dtype(np.inf), kve)
      ive = tf.where(x < 0.0, numpy_dtype(np.nan), ive)
      kve = tf.where(x < 0.0, numpy_dtype(np.nan), kve)
      return ive, kve
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.math import generic
label_desc: Use image node_id 14 for calling a global function with example usage: _temme_expansion(v, x, output_log_space) and returns: ive,  kve, unknown,  kve,  kvep1