docstr: Test interpolation in y direction (cubic interpolation).
docstr_tok: ["Test","interpolation","in","y","direction","(","cubic","interpolation",")","."]
code: def test_interpolation_in_y_direction(self):
      """Test interpolation in y direction (cubic interpolation)."""
      for dtype in [np.float32, np.float64]:
          x_values = tf.constant(
              [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], dtype=dtype
          )
          y_values_list = [-1, 0, 1, 2, 2.5, 5, -1, 0, 1, 2, 2.5, 5]
          y_values = tf.constant(y_values_list, dtype=dtype)
  
          # Function at x=1.
          f1 = lambda x: x
          # Function as x=2
          f2 = lambda x: x**3
  
          # Interpolated cubic spline at x=1.
          def f1_interpolated(x):
              if x < 0:
                  return 0
              elif x >= 0 and x <= 2:
                  return x
              else:
                  return 2
  
          # Interpolated cubic spline at x=2.
          # Since we use *natural* cubic interpolation the spline that we
          # get is not the same as the original cubic polynomial.
          def f2_interpolated(x):
              if x < 2:
                  return 8
              elif x >= 2 and x <= 3:
                  return 4.5 * x**3 - 27 * x**2 + 68.5 * x - 57
              elif x >= 3 and x <= 4:
                  return -4.5 * x**3 + 54 * x**2 - 174.5 * x + 186
              else:
                  return 64
  
          x_data = tf.constant([1, 2], dtype=dtype)
          y_data = tf.constant([[0, 1, 2], [2, 3, 4]], dtype=dtype)
  
          z_data = tf.constant(
              [[f1(0), f1(1), f1(2)], [f2(2), f2(3), f2(4)]],
              dtype=dtype,
          )
  
          interpolator = interpolation_2d.Interpolation2D(
              x_data, y_data, z_data, dtype=dtype
          )
          result = interpolator.interpolate(x_values, y_values)
  
          with self.subTest("CorrectDtype"):
              self.assertEqual(result.dtype.as_numpy_dtype, dtype)
          with self.subTest("CorrectShape"):
              self.assertAllClose(result.shape.as_list(), [12])
          expected_result = np.array(
              [f1_interpolated(x) for x in y_values_list[:6]]
              + [f2_interpolated(x) for x in y_values_list[:6]]
          )
          with self.subTest("CorrectResults"):
              self.assertAllClose(
                  result, expected_result, 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 3 for calling the Interpolation2DTest obj's underlying member method code with example usage: obj.test_interpolation_in_y_direction() and returns: int, int, x, int, unknown, unknown, int