sage.core.interpolation

Filename : interpolation.py Description : Short description of the file

Created on 2026-01-23 02:36:43

__author__ = Narenraju Nagarajan __copyright__ = Copyright 2026, ProjectName __license__ = MIT Licence __version__ = 0.0.1 __maintainer__ = Narenraju Nagarajan __affiliation__ = N/A __email__ = N/A __status__ = [‘inProgress’, ‘Archived’, ‘inUsage’, ‘Debugging’]

GitHub Repository: NULL

Documentation: NULL

Functions

torch_linear_interp(x, xp, fp)

1D linear interpolation, compatible with jnp.interp / np.interp.

torch_scipylike_cubic_interp(x, xp, fp)

1D piecewise cubic (Hermite) interpolation, similar to

torch_catmull_rom_cubic_interp(xs, y, x0, dx)

Fast cubic interpolation on a uniform grid (Catmull-Rom).

torch_natural_cubic_coeffs(xp, fp)

Compute second derivatives for a natural cubic spline.

torch_natural_cubic_interp(x, xp, fp, M[, derivative])

Compute a natural cubic spline interpolation of fp at points x using nodes xp.

Module Contents

torch_linear_interp(x, xp, fp)[source]

1D linear interpolation, compatible with jnp.interp / np.interp.

Parameters:
  • x (torch.Tensor, shape (...,)) – Query points.

  • xp (torch.Tensor, shape (N,)) – Monotonically increasing node x-coordinates.

  • fp (torch.Tensor, shape (N,)) – Function values at xp.

Returns:

Linearly interpolated values at x.

Return type:

torch.Tensor, shape (...,)

torch_scipylike_cubic_interp(x, xp, fp)[source]

1D piecewise cubic (Hermite) interpolation, similar to scipy.interpolate.CubicSpline with finite-difference slopes.

Parameters:
  • x (torch.Tensor, shape (...,)) – Query points.

  • xp (torch.Tensor, shape (N,)) – Monotonically increasing node x-coordinates.

  • fp (torch.Tensor, shape (N,)) – Function values at xp.

Returns:

Cubic-interpolated values at x.

Return type:

torch.Tensor, shape (...,)

torch_catmull_rom_cubic_interp(xs, y, x0, dx)[source]

Fast cubic interpolation on a uniform grid (Catmull-Rom).

Parameters:
Returns:

(…,) interpolated values

torch_natural_cubic_coeffs(xp, fp)[source]

Compute second derivatives for a natural cubic spline. Equivalent to gsl_interp_cspline.

xp: (N,) strictly increasing fp: (N,) returns: M (N,) second derivatives

torch_natural_cubic_interp(x, xp, fp, M, derivative=False)[source]

Compute a natural cubic spline interpolation of fp at points x using nodes xp. Matches gsl_spline_eval from LAL as much as possible.

Parameters:
  • x (Tensor) – Points where the interpolated values are desired (…,).

  • xp (Tensor) – Monotonically increasing node points (N,).

  • fp (Tensor) – Function values at nodes xp (N,).

  • M (float or Tensor) – Total mass scaling factor, used to convert to physical units if needed.

Returns:

Interpolated values at x using a natural cubic spline.

Return type:

Tensor

# NOTE: # LAL computes certain derivatives using a natural cubic spline # (gsl_interp_cspline), which enforces global C2 smoothness and # zero second derivatives at the endpoints. # # Say we look at the example of enforcing time of coalescence at t=0. # The phase is differentiated to compute a time shift that enforces coalescence # at t = 0. Using a local or non-natural cubic interpolant changes dPhase/df at # f_final. This produces an incorrect time shift, resulting in a constant # phase error that propagates across the entire waveform # (inspiral, merger, ringdown). # # To remain consistent with the C/LAL implementation, the same natural cubic # spline must be used here.

Example usage: M = torch_natural_cubic_spline_coeffs(freqs_fixed, phase_fixed) phi_interp = lambda f: torch_natural_cubic_interp(f, freqs_fixed, phase_fixed, M) t_corr = torch_grad(phi_interp, (f_final,)) / (2 * torch.pi)