code: def relerr(result, truth):
      """Returns the relative error of `result` relative `truth`.
  
      The relative error is defined as
  
        |result - truth|
        ----------------
            |truth|
  
      The computation of that difference and ratio are done in 64-bit
      precision.
  
      Args:
        result: Tensor of values whose deviation to assess.
        truth: Tensor of values presumed correct.  Must broadcast with
          `result`.
  
      Returns:
        err: Float64 Tensor of elementwise relative error values.
  
      """
      result = tf.cast(result, dtype=tf.float64)
      truth = tf.cast(truth, dtype=tf.float64)
      err = tf.math.abs((result - truth) / truth)
      # If truth is 0 (in 64 bits!), the previous expression will give infinite
      # relative error for non-zero result (which is correct), and nan relative
      # error for zero result (which is incorrect).  This tf.where fixes that.
      return tf.where(
          result == truth, tf.constant(0.0, dtype=tf.float64), err
      )
  
file_path: probability/tensorflow_probability/python/internal/numerics_testing.py
imports: import functools
  from absl import logging
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 3 for calling a global function with example usage: relerr(result, truth) and returns: tf