docstr: Tests dupire_local_volatility correctness when dim=2.
docstr_tok: ["Tests","dupire_local_volatility","correctness","when","dim=2","."]
code: def test_dupire_local_volatility_2d(self, dupire_local_volatility):
      """Tests dupire_local_volatility correctness when dim=2."""
      dim = 2
      dtype = tf.float64
      tensors = build_scaled_tensors(dim)
      (
          val_date,
          expiries,
          expiry_times,
          strikes,
          iv,
          initial_spot,
      ) = tensors
  
      vs = build_volatility_surface(
          val_date, expiry_times, expiries, strikes, iv, dtype=dtype
      )
      dividend_yield = [0.0]
      r = tf.convert_to_tensor([0.0], dtype=dtype)
      discount_factor_fn = lambda t: tf.math.exp(-r * t)
  
      times = tf.convert_to_tensor([1.0, 2.0], dtype=dtype)
      times = tf.broadcast_to(times, [2, 2])
      spots = [[1.0, 1.5], [2.0, 2.5]]
      spots = tf.convert_to_tensor(spots, dtype=dtype)
      dupire_vols = dupire_local_volatility(
          times,
          spots,
          initial_spot,
          vs.volatility,
          discount_factor_fn,
          dividend_yield,
      )
      true_vols = [[0.22848, 0.3], [0.3, 0.3]]
      for i in range(2):
          self.assertAllClose(
              dupire_vols[:, i], true_vols[i], atol=0.05, rtol=0.005
          )
  
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 3 for calling the LocalVolatilityTest obj's underlying member method code with example usage: obj.test_dupire_local_volatility_2d(dupire_local_volatility) without return types