scijit.interpolate.splev

scijit.interpolate.splev(x, tck, der=0, ext=0)

Evaluate a spline or one of its derivatives.

Parameters:
xfloat or array_like of float

Points to evaluate at. The result keeps x’s shape, so a scalar gives a rank-0 array.

tcktuple of (t, c, k)

Spline representation, as returned by splrep or splprep: knot vector, coefficients (padded form accepted) and degree. A c that holds one array per curve dimension, which is what splprep returns, is evaluated one dimension at a time and the result is a list.

derint, optional

Derivative order, 0 <= der <= k. Default 0, the spline itself.

extint, optional

Behaviour for points outside [t[k], t[n-k-1]]: 0 extrapolates, 1 returns 0, 2 raises ValueError, 3 returns the boundary value. Default 0.

Returns:
yfloat64 ndarray, shaped like x, or a list of idim of them

Spline values, or der-th derivative values. A list, one entry per curve dimension, when c holds one array per dimension.

Raises:
ValueError

If der is outside 0..k, if ext is outside 0..3, if x is empty, if c holds fewer than len(t) - k - 1 coefficients, or if ext == 2 and a point of x lies outside the knot range.

See also

scipy.interpolate.splev

The scipy routine this mirrors.

Notes

  • A BSpline instance is a valid tck in scipy. This unpacks a 3-tuple.

prange-safe: yes.

Examples

>>> import numpy as np
>>> from numba import njit
>>> from scijit.interpolate import splrep, splev
>>> x = np.linspace(0, 4, 40)
>>> tck = splrep(x, np.sin(x))
>>> @njit
... def evaluate(tck, q):
...     return splev(q, tck)
>>> np.round(evaluate(tck, np.array([0.5, 1.5, 2.5])), 8)
array([0.47942552, 0.99749473, 0.598472  ])
>>> @njit
... def slope(tck, q):
...     return splev(q, tck, 1)
>>> np.round(slope(tck, np.array([0.5, 1.5, 2.5])), 8)
array([ 0.87758567,  0.07074248, -0.80114689])