docstr: Computes values of example in the docstring for function interpolate.
docstr_tok: ["Computes","values","of","example","in","the","docstring","for","function","interpolate","."]
code: def test_docstring_example(self):
      """Computes values of example in the docstring for function interpolate."""
      for dtype in [np.float32, np.float64]:
          times = tf.constant([2.0, 2.5, 3], dtype=dtype)
          strikes = tf.constant([16, 22, 35], dtype=dtype)
  
          times_data = tf.constant(
              [1.5, 2.5, 3.5, 4.5, 5.5], dtype=dtype
          )
          sigma_square_data = tf.constant(
              [
                  [0.15, 0.25, 0.35, 0.4, 0.45, 0.4],
                  [0.2, 0.35, 0.55, 0.45, 0.4, 0.6],
                  [0.3, 0.45, 0.25, 0.4, 0.5, 0.65],
                  [0.25, 0.25, 0.45, 0.25, 0.5, 0.55],
                  [0.35, 0.35, 0.25, 0.4, 0.55, 0.55],
              ],
              dtype=dtype,
          )
          total_variance = (
              tf.expand_dims(times_data, -1) * sigma_square_data
          )
          strike_data = tf.broadcast_to(
              tf.constant([15, 25, 35, 40, 50, 55], dtype=dtype), [5, 6]
          )
          interpolator = interpolation_2d.Interpolation2D(
              times_data, strike_data, total_variance, dtype=dtype
          )
          interpolated_vols = interpolator.interpolate(times, strikes)
          with self.subTest("CorrectDtype"):
              self.assertEqual(
                  interpolated_vols.dtype.as_numpy_dtype, dtype
              )
          with self.subTest("CorrectShape"):
              self.assertAllClose(
                  interpolated_vols.shape.as_list(), [3]
              )
          expected_vols = np.array([0.382399, 0.716694, 1.125])
          with self.subTest("CorrectResult"):
              self.assertAllClose(
                  interpolated_vols,
                  expected_vols,
                  rtol=1e-04,
                  atol=1e-04,
              )
  
file_path: tf-quant-finance/tf_quant_finance/math/interpolation/interpolation_2d/interpolation_2d_test.py
imports: import numpy
  import tensorflow.compat.v1
  import tf_quant_finance
  from tensorflow.python.framework import test_util
label_desc: Use image node_id 1 for calling the Interpolation2DTest obj's underlying member method code with example usage: obj.test_docstring_example() without return types