code: def _temme_series(v, z, output_log_space=False):
      """Computes Kve(v, z) and Kve(v + 1., z) via Power series expansion."""
      # This is based on:
      # [1] N. Temme, On the Numerical Evaluation of the Modified Bessel Function
      #   of the Third Kind. Journal of Computational Physics 19, 1975.
      # [2] Numerical Recipes in C. The Art of Scientific Computing,
      #   2nd Edition, 1992
      # We will assume |z| <= 2. and |v| < 0.5 for fast convergence.
      dtype = dtype_util.common_dtype([v, z], tf.float32)
      numpy_dtype = dtype_util.as_numpy_dtype(dtype)
      tol = tf.cast(np.finfo(numpy_dtype).eps, dtype=dtype)
  
      # The initial series term is defined by 6.7.39 in [2]. We compute
      # related coefficients and quantities.
      (
          coeff1,
          coeff2,
          gamma1pv_inv,
          gamma1mv_inv,
      ) = _evaluate_temme_coeffs(v)
  
      z_sq = tf.math.square(z)
  
      logzo2 = tf.math.log(z / 2.0)
      mu = -v * logzo2
      sinc_v = tf.where(
          tf.math.equal(v, 0.0),
          numpy_dtype(1.0),
          tf.math.sin(np.pi * v) / (np.pi * v),
      )
      sinhc_mu = tf.where(
          tf.math.equal(mu, 0.0),
          numpy_dtype(1.0),
          tf.math.sinh(mu) / mu,
      )
      # These are defined in 6.7.17 in [2].
      initial_f = (
          coeff1 * tf.math.cosh(mu) + coeff2 * -logzo2 * sinhc_mu
      ) / sinc_v
      initial_p = 0.5 * tf.math.exp(mu) / gamma1pv_inv
      initial_q = 0.5 * tf.math.exp(-mu) / gamma1mv_inv
      max_iterations = 1000
  
      def body_fn(should_stop, index, f, p, q, coeff, kv_sum, kvp1_sum):
          f = tf.where(
              should_stop,
              f,
              (index * f + p + q)
              / (tf.math.square(index) - tf.math.square(v)),
          )
          p = tf.where(should_stop, p, p / (index - v))
          q = tf.where(should_stop, q, q / (index + v))
          h = p - index * f
          # c_k = (z ** 2 / 4) ** k / (k!)
          coeff = tf.where(
              should_stop, coeff, coeff * z_sq / (4 * index)
          )
          kv_sum = tf.where(should_stop, kv_sum, kv_sum + coeff * f)
          kvp1_sum = tf.where(
              should_stop, kvp1_sum, kvp1_sum + coeff * h
          )
          index = index + 1
          should_stop = (
              tf.math.abs(coeff * f) < tf.math.abs(kv_sum) * tol
          ) | (index > max_iterations)
          return should_stop, index, f, p, q, coeff, kv_sum, kvp1_sum
  
      _, _, _, _, _, _, kv_sum, kvp1_sum = tf.while_loop(
          cond=lambda stop, *_: tf.reduce_any(~stop),
          body=body_fn,
          loop_vars=(
              tf.zeros_like(initial_f, dtype=tf.bool),
              tf.cast(1.0, dtype),
              initial_f,
              initial_p,
              initial_q,
              tf.ones_like(initial_p),
              initial_f,
              initial_p,
          ),
      )
  
      log_kve = tf.math.log(kv_sum) + z
      log_kvep1 = tf.math.log(2.0 * kvp1_sum) + z - tf.math.log(z)
      if output_log_space:
          return log_kve, log_kvep1
  
      return tf.math.exp(log_kve), tf.math.exp(log_kvep1)
  
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 12 for calling a global function with example usage: _temme_series(v, z, output_log_space) and returns: tf,  tf, should_stop,  index,  f,  p,  q,  coeff,  kv_sum,  kvp1_sum, log_kve,  log_kvep1