scijit.interpolate.sproot

scijit.interpolate.sproot(tck, mest=10)

Find the roots of a cubic spline.

Parameters:
tcktuple of (t, c, k)

Spline representation: knot vector, B-spline coefficients, degree. k must be 3. len(c) must be at least len(t) - 4; a longer c is accepted and the excess ignored.

mestint, optional

Size of the root buffer, and therefore the maximum number of roots returned. Default 10. mest=0 returns an empty array. A NEGATIVE mest means 3 * (len(t) - 7), FITPACK’s own worst case (len(t) - 7 knot intervals, each holding at most 3 roots of a cubic), so it never truncates.

Returns:
zero1-D float64 ndarray

The roots in [t[3], t[n-4]], ascending; possibly empty. Truncated to mest entries when the spline has more roots than that.

Raises:
ValueError

k != 3, or len(c) < len(t) - 4.

TypeError

len(t) < 8, or a knot vector failing FITPACK’s data check t1<=..<=t4<t5<..<tn-3<=..<=tn.

Warns:
RuntimeWarning

The number of zeros exceeds mest, when mest binds and roots were dropped. The warning is issued through a numba.objmode block, which runs its body in the interpreter, so warnings.catch_warnings and -W see it from compiled and uncompiled callers alike.

See also

scipy.interpolate.sproot

The scipy routine this mirrors.

Notes

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

A root that coincides with a knot is missed, and a tangential (double) root is not found. Both are FITPACK properties.

prange-safe: yes.

Examples

>>> import numpy as np
>>> from numba import njit
>>> from scijit.interpolate import splrep, sproot
>>> x = np.linspace(0, 4, 60)
>>> tck = splrep(x, np.sin(x))
>>> @njit
... def zeros(tck):
...     return sproot(tck)
>>> np.round(zeros(tck), 8)
array([3.14159265])