scijit.interpolate.InterpolatedUnivariateSpline¶
- scijit.interpolate.InterpolatedUnivariateSpline(x, y, w=array([], dtype=float64), bbox=None, k=3, ext=0, check_finite=False)¶
Build an interpolating spline through every data point.
UnivariateSpline with the smoothing factor pinned at 0, so the spline passes through every data point.
- Parameters:
- x1-D float64 ndarray, length m
Abscissae, strictly increasing.
- y1-D float64 ndarray, length m
Ordinates.
- w1-D array_like of float, optional
Positive weights, length m.
Noneand a zero-length array both mean unit weights. Weights have no effect on the fit here, sinces = 0forces interpolation; measured identical knots andfp = 0with and without them, on both sides.- bbox(2,) array_like of float, optional
Boundary of the approximation interval;
None, in place of the pair or in one slot, meansx[0]/x[-1], and is the default. May only WIDEN.- kint, optional
Spline degree, 1 <= k <= 5. Default 3.
- extint or str, optional
Extrapolation mode: 0 or
'extrapolate', 1 or'zeros', 2 or'raise', 3 or'const'. Default 0.- check_finitebool, optional
Raise if x, y or w contains a NaN or an inf. Default False.
- Attributes:
- t1-D float64 ndarray
Full knot vector, including the repeated boundary knots.
- c1-D float64 ndarray
Coefficients in FITPACK’s padded form.
- kint
Spline degree.
- fpfloat
Sum of squared residuals, 0 for an exact interpolant.
- ierint
FITPACK status; expect -1 here, which means “interpolating spline” and is a SUCCESS, not an error.
- extint
The resolved extrapolation code, 0..3.
Methods
ev(x), ev_one(x), __getitem__(x), derivative_ev(x, nu), derivatives(x),
integral(a, b), roots(), get_knots(), get_coeffs(), get_residual()
- Returns:
- spl_InterpolatedUnivariateSpline
A jitclass instance carrying the attributes and methods below.
- Raises:
- ValueError
Non-finite input under check_finite, mismatched lengths, a bbox that is not length 2, k outside 1..5, an unknown ext,
m <= k, orx must be strictly increasing, the check that separates this class from LSQUnivariateSpline, where a duplicated x is allowed.
See also
scipy.interpolate.InterpolatedUnivariateSplineThe scipy class this mirrors.
Notes
spl(x)runs.evfor an array and.ev_onefor a scalar..ev(x),.ev_one(x)andspl[x]reach the same methods.spl(x, nu)andspl(x, nu, ext)carry scipy’s second and third positional parameters, andspl(x, nu=1)andspl(x, ext=1)carry them by keyword..ev(x, nu=1)takes the keyword inside@njitand not from the interpreter, where the jitclass method raisesTypeError; the call spelling works from both.scipy RE-CLASSES the instance by ier; a jitclass cannot, so ier is an attribute.
.derivative()/.antiderivative()returning new spline objects are absent, andderivatives(array)(scipy’s list return) is not available – pass one scalar at a time.ier = 10RAISES here. scipy warns and returns an object whose knot vector was never filled; a status that means “no approximation returned” is not carried into a usable object. ier of 1, 2 or 3 warns.A complex y raises
TypeError. scipy 1.18 accepts it, emits aComplexWarningand discards the imaginary part, returning a float64 spline.
Defaults work in both worlds.
InterpolatedUnivariateSplineis a plain@njitfactory, not the jitclass itself, soInterpolatedUnivariateSpline(x, y)compiles and runs inside@njitas well as from Python. The class it returns,_InterpolatedUnivariateSpline, takes every argument explicitly, because a jitclass constructor’s defaults are Python-only.Accuracy against scipy 1.18.0, max absolute difference: knots, coefficients, fp, values in range and extrapolating, integral, derivatives, roots and
derivative_ev(nu=1)all 0.0.prange-safe: yes.
Examples
>>> import numpy as np >>> from numba import njit >>> from scijit.interpolate import InterpolatedUnivariateSpline >>> x = np.linspace(0, 4, 40) >>> y = np.sin(x) >>> spl = InterpolatedUnivariateSpline(x, y) # fit once >>> float(np.round(spl(1.5), 8)) 0.99749473
Inside compiled code, integrating the interpolant over its domain:
>>> @njit ... def area(spl): ... return spl.integral(0.0, 4.0) >>> float(np.round(area(spl), 6)) 1.653643