n-D spline class

class cubicmultispline.Spline(interval, yv, boundary_condition_type=None, boundary_condition_value=None)

Multidimensional cubic spline interpolation using tensor product B-splines.

This class implements multidimensional cubic spline interpolation by constructing tensor products of 1D B-spline basis functions. The interpolation supports various boundary conditions and can evaluate function values, gradients, and Hessians.

The implementation uses a recursive approach to compute coefficients and a vectorized evaluation method for efficiency.

_ndim

Number of dimensions

_interval

List of (start, end, n_points) tuples for each dimension

_boundary_condition_type

Boundary conditions for each dimension

_boundary_condition_value

Boundary condition values for each dimension

_coeff

Multidimensional array of spline coefficients

_knots

List of knot vectors for each dimension

property coeff: ndarray

Get multidimensional spline coefficients.

Returns:

Multidimensional array of spline coefficients with shape (n1+2, n2+2, …, nd+2) where ni is the number of points in dimension i

Return type:

np.ndarray

eval_spline(x)

Evaluate multidimensional spline and its derivatives.

Computes spline values, gradients, and Hessians at specified evaluation points using a vectorized tensor product approach. Based on the methodology from DOI 10.1007/s10614-007-9092-4, Section 3.2.

Parameters:

x (np.ndarray) – Evaluation points of shape (N, d) where N is number of points and d is number of dimensions

Returns:

  • f (np.ndarray) – Function values at evaluation points, shape (N,)

  • grad (np.ndarray) – Gradient vectors at evaluation points, shape (N, d)

  • hess (np.ndarray) – Hessian matrices at evaluation points, shape (N, d, d)

Notes

The evaluation uses a vectorized approach that efficiently computes contributions from all active basis functions (up to 4^d per point).

static recursive_spline(interval, yv, boundary_condition_type, boundary_condition_value)

Recursively compute multidimensional spline coefficients.

Uses a recursive approach to compute tensor product spline coefficients. For each dimension, 1D splines are computed along the other dimensions, then combined using another 1D spline.

Parameters:
  • interval (Tuple[Tuple[float, float, int]]) – Intervals for remaining dimensions

  • yv (ndarray) – Function values for remaining dimensions

  • boundary_condition_type (Tuple[Tuple[str, str]]) – Boundary conditions for remaining dimensions

  • boundary_condition_value (Tuple[Tuple[float, float]]) – Boundary condition values for remaining dimensions

Returns:

Flattened array of multidimensional spline coefficients

Return type:

ndarray