code: def _bessel_iv_ratio_naive(v, z):
      """Compute bessel_iv_ratio(v, z)."""
      dtype = dtype_util.common_dtype([v, z], tf.float32)
      v = tf.convert_to_tensor(v, dtype=dtype)
      z = tf.convert_to_tensor(z, dtype=dtype)
  
      # I(v, z) == I(-v, z) when v is an integer.
      v_is_integer = tf.math.equal(tf.math.floor(v), v)
      v = tf.where((v < 0.0) & v_is_integer, -v, v)
  
      np_finfo = np.finfo(dtype_util.as_numpy_dtype(dtype))
      tolerance = tf.cast(np_finfo.resolution, dtype=dtype)
  
      safe_to_use_perron = z > v
  
      def gauss_term_fn(iteration_count, v, z):
          """Terms for the Gauss continued fraction."""
          return (
              tf.math.square(z)
              / 4.0
              / ((v + iteration_count - 1) * (v + iteration_count))
          )
  
      # The Gauss continued fraction converges faster for z < v.
      # For z > v, set z to something much less than v.
      safe_z_less_v = tf.where(safe_to_use_perron, v / 1000.0, z)
  
      # We use forward recurrence for the Gauss continued fraction.
      # This is so that we can do early termination.
      # There are a few reasons why this doesn't overflow:
      # * All partial numerators / denominators are positive.
      # * Partial numerators approach zero as 1 / n**2, where
      #   n is the iteration count.
      # * All partial numerators are less than 1.
      # Combined with the recurrence, this ensures no overflow.
      # as the number of iterations -> infinity.
      gauss_cf = _compute_general_continued_fraction(
          # Use a max of 200 steps. Almost always we will be much less
          # than this.
          200,
          [v, safe_z_less_v],
          tolerance=tolerance,
          partial_numerator_fn=gauss_term_fn,
      )
      # Add the zeroth term for the Gauss continued fraction.
      gauss_cf = tf.math.reciprocal((1.0 + gauss_cf) * 2.0 * v / z)
  
      # For the Perron CF we use the backward recurrence. This is because
      # generally the backward recurrence is more numerically stable
      # than forward recurrence, especially with negative terms.
      # We use a flat 50 steps. Anecdotally, for z > v, convergence is
      # much faster than that.
  
      # The Perron continued fraction converges much faster for z >> v.
      # For z < v, set z to something much greater than v.
      safe_z_greater_v = tf.where(~safe_to_use_perron, 1000.0 * v, z)
  
      def perron_term_fn(iteration_count, v, z):
          """Terms for the Perron continued fraction."""
          return (
              -0.5
              * z
              * (v + iteration_count - 0.5)
              / (
                  (v + z + (iteration_count - 1.0) / 2.0)
                  * (v + z + iteration_count / 2.0)
              )
          )
  
      total_perron_iteration_count = 50
  
      def _backward_cf_one_step(iteration_count, cf):
          cf = perron_term_fn(
              total_perron_iteration_count - iteration_count,
              v,
              safe_z_greater_v,
          ) / (1.0 + cf)
          return [iteration_count + 1.0, cf]
  
      # For the Perron CF, we omit the first numerator because it
      # has a different form.
  
      _, perron_cf = tf.while_loop(
          cond=lambda i, _: i < total_perron_iteration_count - 1,
          body=_backward_cf_one_step,
          # Use 50 iterations. Empirically, the Perron continued fraction
          # converges much faster than this.
          loop_vars=[
              tf.cast(0.0, dtype=dtype),
              tf.zeros_like(safe_z_greater_v),
          ],
      )
      first_term = (
          -0.5 * z * (v + 0.5) / ((v + z / 2.0) * (v + z + 0.5))
      )
  
      perron_cf = first_term / (1.0 + perron_cf)
  
      # Add the zeroth term for the Perron continued fraction.
      perron_zeroth_term = (z + 2 * v) / z
      perron_cf = tf.math.reciprocal(
          perron_zeroth_term * (1.0 + perron_cf)
      )
      return tf.where(safe_to_use_perron, perron_cf, gauss_cf)
  
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 3 for calling a global function with example usage: _bessel_iv_ratio_naive(v, z) and returns: tf, unknown, unknown, list