code: def _get_implied_vol(
      time, strike, paths, spot, discount_factor_fn, dtype
  ):
      discount_factor = discount_factor_fn(time)
      num_not_nan = tf.cast(
          paths.shape[0] - tf.math.count_nonzero(tf.math.is_nan(paths)),
          paths.dtype,
      )
      paths = tf.where(
          tf.math.is_nan(paths), tf.zeros_like(paths), paths
      )
      # Calculate reduce_mean of paths. Workaround for XLA compatibility.
      option_value = tf.math.divide_no_nan(
          tf.reduce_sum(tf.nn.relu(paths - strike)), num_not_nan
      )
      # ITM option value can't fall below intrinsic value.
      option_value = tf.maximum(option_value, spot - strike)
  
      iv = implied_vol(
          prices=discount_factor * option_value,
          strikes=strike,
          expiries=time,
          spots=spot,
          discount_factors=discount_factor,
          dtype=dtype,
          validate_args=False,
      )
      return iv
  
imports: import functools
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  import tf_quant_finance
  from tf_quant_finance.experimental.local_volatility import local_volatility_model
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 6 for calling a global function with example usage: _get_implied_vol(time, strike, paths, spot, discount_factor_fn, dtype) and returns: iv