cupyx.scipy.interpolate.NdPPoly#

class cupyx.scipy.interpolate.NdPPoly(c, x, extrapolate=None)[source]#

Piecewise tensor product polynomial

The value at point xp = (x', y', z', ...) is evaluated by first computing the interval indices i such that:

x[0][i[0]] <= x' < x[0][i[0]+1]
x[1][i[1]] <= y' < x[1][i[1]+1]
...

and then computing:

S = sum(c[k0-m0-1,...,kn-mn-1,i[0],...,i[n]]
        * (xp[0] - x[0][i[0]])**m0
        * ...
        * (xp[n] - x[n][i[n]])**mn
        for m0 in range(k[0]+1)
        ...
        for mn in range(k[n]+1))

where k[j] is the degree of the polynomial in dimension j. This representation is the piecewise multivariate power basis.

Parameters:
  • c (ndarray, shape (k0, ..., kn, m0, ..., mn, ...)) – Polynomial coefficients, with polynomial order kj and mj+1 intervals for each dimension j.

  • x (ndim-tuple of ndarrays, shapes (mj+1,)) – Polynomial breakpoints for each dimension. These must be sorted in increasing order.

  • extrapolate (bool, optional) – Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. Default: True.

Variables:
  • x (tuple of ndarrays) – Breakpoints.

  • c (ndarray) – Coefficients of the polynomials.

See also

PPoly

piecewise polynomials in 1D

Notes

High-order polynomials in the power basis can be numerically unstable.

Methods

__call__(x, nu=None, extrapolate=None)[source]#

Evaluate the piecewise polynomial or its derivative

Parameters:
  • x (array-like) – Points to evaluate the interpolant at.

  • nu (tuple, optional) – Orders of derivatives to evaluate. Each must be non-negative.

  • extrapolate (bool, optional) – Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.

Returns:

y – Interpolated values. Shape is determined by replacing the interpolation axis in the original array with the shape of x.

Return type:

array-like

Notes

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals are considered half-open, [a, b), except for the last interval which is closed [a, b].

antiderivative(nu)[source]#

Construct a new piecewise polynomial representing the antiderivative. Antiderivative is also the indefinite integral of the function, and derivative is its inverse operation.

Parameters:

nu (ndim-tuple of int) – Order of derivatives to evaluate for each dimension. If negative, the derivative is returned.

Returns:

pp – Piecewise polynomial of order k2 = k + n representing the antiderivative of this polynomial.

Return type:

PPoly

Notes

The antiderivative returned by this function is continuous and continuously differentiable to order n-1, up to floating point rounding error.

classmethod construct_fast(c, x, extrapolate=None)[source]#

Construct the piecewise polynomial without making checks.

Takes the same parameters as the constructor. Input arguments c and x must be arrays of the correct shape and type. The c array can only be of dtypes float and complex, and x array must have dtype float.

derivative(nu)[source]#

Construct a new piecewise polynomial representing the derivative.

Parameters:

nu (ndim-tuple of int) – Order of derivatives to evaluate for each dimension. If negative, the antiderivative is returned.

Returns:

pp – Piecewise polynomial of orders (k[0] - nu[0], …, k[n] - nu[n]) representing the derivative of this polynomial.

Return type:

NdPPoly

Notes

Derivatives are evaluated piecewise for each polynomial segment, even if the polynomial is not differentiable at the breakpoints. The polynomial intervals in each dimension are considered half-open, [a, b), except for the last interval which is closed [a, b].

integrate(ranges, extrapolate=None)[source]#

Compute a definite integral over a piecewise polynomial.

Parameters:
  • ranges (ndim-tuple of 2-tuples float) – Sequence of lower and upper bounds for each dimension, [(a[0], b[0]), ..., (a[ndim-1], b[ndim-1])]

  • extrapolate (bool, optional) – Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.

Returns:

ig – Definite integral of the piecewise polynomial over [a[0], b[0]] x … x [a[ndim-1], b[ndim-1]]

Return type:

array_like

integrate_1d(a, b, axis, extrapolate=None)[source]#

Compute NdPPoly representation for one dimensional definite integral The result is a piecewise polynomial representing the integral:

\[p(y, z, ...) = \int_a^b dx\, p(x, y, z, ...)\]

where the dimension integrated over is specified with the axis parameter.

Parameters:
  • a (float) – Lower and upper bound for integration.

  • b (float) – Lower and upper bound for integration.

  • axis (int) – Dimension over which to compute the 1-D integrals

  • extrapolate (bool, optional) – Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs.

Returns:

ig – Definite integral of the piecewise polynomial over [a, b]. If the polynomial was 1D, an array is returned, otherwise, an NdPPoly object.

Return type:

NdPPoly or array-like

__eq__(value, /)#

Return self==value.

__ne__(value, /)#

Return self!=value.

__lt__(value, /)#

Return self<value.

__le__(value, /)#

Return self<=value.

__gt__(value, /)#

Return self>value.

__ge__(value, /)#

Return self>=value.