gradgraph.optimization.tf.interp module

batch_linear_interp_1d(x, x_ref_min, x_ref_max, y_ref, clamp=True, fill_value_below=0.0, fill_value_above=0.0)[source]

Perform batched differentiable 1D linear interpolation with shape safety.

Parameters:
  • x (array_like) – Array of shape (batch, n_interp) containing x values to interpolate.

  • x_ref_min (array_like or scalar) – Array of shape (batch,) or a scalar representing the start of the reference grid.

  • x_ref_max (array_like or scalar) – Array of shape (batch,) or a scalar representing the end of the reference grid.

  • y_ref (array_like) – Array of shape (batch, nx) containing y values at regularly spaced grid points.

  • clamp (bool, optional) – If True, clamps x to the range [x_ref_min, x_ref_max]. Default is True.

  • fill_value_below (scalar, optional) – Scalar value to use for out-of-bound handling below x_ref_min if clamp is False. Default is 0.0.

  • fill_value_above (scalar, optional) – Scalar value to use for out-of-bound handling above x_ref_max if clamp is False. Default is 0.0.

Returns:

y_interp – Array of shape (batch, n_interp) containing the interpolated y values.

Return type:

array_like

Notes

This function assumes that y_ref is defined on a regularly spaced grid between x_ref_min and x_ref_max. The interpolation is performed in a batched manner, allowing for efficient computation over multiple sets of input data.

Examples

>>> import numpy as np
>>> x = np.array([[0.5, 1.5], [2.0, 3.0]])
>>> x_ref_min = np.array([0.0, 1.0])
>>> x_ref_max = np.array([2.0, 3.0])
>>> y_ref = np.array([[0.0, 1.0, 2.0], [1.0, 2.0, 3.0]])
>>> batch_linear_interp_1d(x, x_ref_min, x_ref_max, y_ref)
array([[0.5, 1.5],
       [2.0, 3.0]])