class_docstr: Test for tfp.math.interp_regular_1d_grid.
class_docstr_tok: ["Test","for","tfp.math.interp_regular_1d_grid","."]
docstr: Check correctness on a sinusoidal function.
docstr_tok: ["Check","correctness","on","a","sinusoidal","function","."]
code: def _check_sinusoid(
      self, x_shape, y_ref_shape, axis, fill_value, dtype=np.float32
  ):
      """Check correctness on a sinusoidal function."""
      positive_axis = axis if axis >= 0 else axis + len(y_ref_shape)
  
      x_ref_min = 0.0
      x_ref_max = 2 * np.pi
  
      # Create implied_x_ref, which has same shape = y_ref_shape.
      implied_x_ref_1d = np.linspace(
          x_ref_min, x_ref_max, y_ref_shape[axis], dtype=dtype
      )
      implied_x_ref = implied_x_ref_1d.copy()
      for _ in y_ref_shape[positive_axis + 1 :]:
          implied_x_ref = implied_x_ref[..., np.newaxis]
      for _ in y_ref_shape[:positive_axis]:
          implied_x_ref = implied_x_ref[np.newaxis, ...]
      implied_x_ref = implied_x_ref + np.zeros(y_ref_shape, dtype=dtype)
  
      y_ref = np.sin(implied_x_ref)
  
      # make sure some values are not in [x_ref_min, x_ref_max]
      x = np.linspace(
          x_ref_min - 0.5,
          x_ref_max + 0.5,
          np.int32(np.prod(x_shape)),
          dtype=dtype,
      ).reshape(x_shape)
  
      y = interpolation.interp_regular_1d_grid(
          x,
          x_ref_min,
          x_ref_max,
          y_ref,
          fill_value=fill_value,
          axis=axis,
      )
  
      expected_out_shape = (
          y_ref.shape[:positive_axis]
          + x_shape
          + y_ref.shape[positive_axis + 1 :]
      )
      self.assertAllEqual(expected_out_shape, y.shape)
  
      sp_func = scipy_interpolate.interp1d(
          implied_x_ref_1d,
          y_ref,
          kind="linear",
          axis=axis,
          bounds_error=False,  # Allow values outside range.
          fill_value=fill_value,
      )
      y_expected = sp_func(x)
      self.assertAllClose(
          self.evaluate(y), y_expected, atol=1e-5, rtol=0
      )
  
imports: import numpy
  from scipy import interpolate
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.math import interpolation
label_desc: Use image node_id 9 for calling the InterpRegular1DGridTest obj's underlying member method code with example usage: obj._check_sinusoid(x_shape, y_ref_shape, axis, fill_value, dtype) without return types