L i7:4gdZddlmZddlZddlmZmZmZmZm Z ddl m Z ddl mZddl mZddlmZdd lmZdd lmZdd lmZdd lmZmZd ZdZGddZdZdZGddeZGddZ Gdde Z!Gdde Z"GddZ#y))interp1dinterp2dlagrangePPolyBPolyNdPPoly)prodN)arrayasarrayintppoly1d searchsorted)copy_if_needed)comb) _fitpack_py)_Interpolator1D)_ppoly)_ndim_coords_from_arrays)make_interp_splineBSplinect|}td}t|D]M}t||}t|D]*}||k(r ||||z }|td|| g|z z},||z }O|S)a Return a Lagrange interpolating polynomial. Given two 1-D arrays `x` and `w,` returns the Lagrange interpolating polynomial through the points ``(x, w)``. Warning: This implementation is numerically unstable. Do not expect to be able to use more than about 20 points even if they are chosen optimally. Parameters ---------- x : array_like `x` represents the x-coordinates of a set of datapoints. w : array_like `w` represents the y-coordinates of a set of datapoints, i.e., f(`x`). Returns ------- lagrange : `numpy.poly1d` instance The Lagrange interpolating polynomial. Notes ----- The name of this function refers to the fact that the returned object represents a Lagrange polynomial, the unique polynomial of lowest degree that interpolates a given set of data [1]_. It computes the polynomial using Newton's divided differences formula [2]_; that is, it works with Newton basis polynomials rather than Lagrange basis polynomials. For numerical calculations, the barycentric form of Lagrange interpolation (`scipy.interpolate.BarycentricInterpolator`) is typically more appropriate. References ---------- .. [1] Lagrange polynomial. *Wikipedia*. https://en.wikipedia.org/wiki/Lagrange_polynomial .. [2] Newton polynomial. *Wikipedia*. https://en.wikipedia.org/wiki/Newton_polynomial Examples -------- Interpolate :math:`f(x) = x^3` by 3 points. >>> import numpy as np >>> from scipy.interpolate import lagrange >>> x = np.array([0, 1, 2]) >>> y = x**3 >>> poly = lagrange(x, y) Since there are only 3 points, the Lagrange polynomial has degree 2. Explicitly, it is given by .. math:: \begin{aligned} L(x) &= 1\times \frac{x (x - 2)}{-1} + 8\times \frac{x (x-1)}{2} \\ &= x (-2 + 3x) \end{aligned} >>> from numpy.polynomial.polynomial import Polynomial >>> Polynomial(poly.coef[::-1]).coef array([ 0., -2., 3.]) >>> import matplotlib.pyplot as plt >>> x_new = np.arange(0, 2.1, 0.1) >>> plt.scatter(x, y, label='data') >>> plt.plot(x_new, Polynomial(poly.coef[::-1])(x_new), label='Polynomial') >>> plt.plot(x_new, 3*x_new**2 - 2*x_new + 0*x_new, ... label=r"$3 x^2 - 2 x$", linestyle='-.') >>> plt.legend() >>> plt.show() g?)lenr range)xwMpjptkfacs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/interpolate/_interpolate.pyrrsT AAs A 1X AaD\q +AAvA$qt)C &#!u&s* *B  + R Ha`interp2d` has been removed in SciPy 1.14.0. For legacy code, nearly bug-for-bug compatible replacements are `RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for scattered 2D data. In new code, for regular grids use `RegularGridInterpolator` instead. For scattered data, prefer `LinearNDInterpolator` or `CloughTocher2DInterpolator`. For more details see https://scipy.github.io/devdocs/tutorial/interpolate/interp_transition_guide.html ceZdZdZ ddZy)ra interp2d(x, y, z, kind='linear', copy=True, bounds_error=False, fill_value=None) Class for 2D interpolation (deprecated and removed) .. versionremoved:: 1.14.0 `interp2d` has been removed in SciPy 1.14.0. For legacy code, nearly bug-for-bug compatible replacements are `RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for scattered 2D data. In new code, for regular grids use `RegularGridInterpolator` instead. For scattered data, prefer `LinearNDInterpolator` or `CloughTocher2DInterpolator`. For more details see :ref:`interp-transition-guide`. Nc ttN)NotImplementedErrorerr_mesg)selfryzkindcopy bounds_error fill_values r$__init__zinterp2d.__init__s !(++r%)linearTFN)__name__ __module__ __qualname____doc__r2r%r$rr}s(HM ,r%rcj|j}t|t|k\r~t|ddd|dddD]\}}|dk7s ||k7snR|jdk7r2|j|k7r#t j ||j |z}|jSt|d|d|)z7Helper to check that arr_from broadcasts up to shape_toNrz0 argument must be able to broadcast up to shape z but had shape ) shaperzipsizenponesdtyperavel ValueError)arr_fromshape_toname shape_fromtfs r$_check_broadcast_up_torIsJ 8}J'2 4R4(89 $DAqAv!q& $}}!hnn&@778X^^># # v!!) /*G HHr%c0t|txr|dk(S)z?Helper to check if fill_value == "extrapolate" without warnings extrapolate) isinstancestr)r1s r$_do_extrapolaterNs z3 ' ( - ')r%ceZdZdZddddej dfdZedZejd Zd Z d Z d Z d Z dZdZdZdZdZy)ra Interpolate a 1-D function (legacy). .. legacy:: class For a guide to the intended replacements for `interp1d` see :ref:`tutorial-interpolate_1Dsection`. `x` and `y` are arrays of values used to approximate some function f: ``y = f(x)``. This class returns a function whose call method uses interpolation to find the value of new points. Parameters ---------- x : (npoints, ) array_like A 1-D array of real values. y : (..., npoints, ...) array_like A N-D array of real values. The length of `y` along the interpolation axis must be equal to the length of `x`. Use the ``axis`` parameter to select correct axis. Unlike other interpolators, the default interpolation axis is the last axis of `y`. kind : str or int, optional Specifies the kind of interpolation as a string or as an integer specifying the order of the spline interpolator to use. The string has to be one of 'linear', 'nearest', 'nearest-up', 'zero', 'slinear', 'quadratic', 'cubic', 'previous', or 'next'. 'zero', 'slinear', 'quadratic' and 'cubic' refer to a spline interpolation of zeroth, first, second or third order; 'previous' and 'next' simply return the previous or next value of the point; 'nearest-up' and 'nearest' differ when interpolating half-integers (e.g. 0.5, 1.5) in that 'nearest-up' rounds up and 'nearest' rounds down. Default is 'linear'. axis : int, optional Axis in the ``y`` array corresponding to the x-coordinate values. Unlike other interpolators, defaults to ``axis=-1``. copy : bool, optional If ``True``, the class makes internal copies of x and y. If ``False``, references to ``x`` and ``y`` are used if possible. The default is to copy. bounds_error : bool, optional If True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If False, out of bounds values are assigned `fill_value`. By default, an error is raised unless ``fill_value="extrapolate"``. fill_value : array-like or (array-like, array_like) or "extrapolate", optional - if a ndarray (or float), this value will be used to fill in for requested points outside of the data range. If not provided, then the default is NaN. The array-like must broadcast properly to the dimensions of the non-interpolation axes. - If a two-element tuple, then the first element is used as a fill value for ``x_new < x[0]`` and the second element is used for ``x_new > x[-1]``. Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a single array-like argument meant to be used for both bounds as ``below, above = fill_value, fill_value``. Using a two-element tuple or ndarray requires ``bounds_error=False``. .. versionadded:: 0.17.0 - If "extrapolate", then points outside the data range will be extrapolated. .. versionadded:: 0.17.0 assume_sorted : bool, optional If False, values of `x` can be in any order and they are sorted first. If True, `x` has to be an array of monotonically increasing values. Attributes ---------- fill_value Methods ------- __call__ See Also -------- splrep, splev Spline interpolation/smoothing based on FITPACK. UnivariateSpline : An object-oriented wrapper of the FITPACK routines. interp2d : 2-D interpolation Notes ----- Calling `interp1d` with NaNs present in input values results in undefined behaviour. Input values `x` and `y` must be convertible to `float` values like `int` or `float`. If the values in `x` are not unique, the resulting behavior is undefined and specific to the choice of `kind`, i.e., changing `kind` will change the behavior for duplicates. Examples -------- >>> import numpy as np >>> import matplotlib.pyplot as plt >>> from scipy import interpolate >>> x = np.arange(0, 10) >>> y = np.exp(-x/3.0) >>> f = interpolate.interp1d(x, y) >>> xnew = np.arange(0, 9, 0.1) >>> ynew = f(xnew) # use interpolation function returned by `interp1d` >>> plt.plot(x, y, 'o', xnew, ynew, '-') >>> plt.show() r3r:TNFc  tj||||||_||_|s t|_|dvr ddddd|} d}n't |t r|} d}n|dvrt|d t||j }t||j }|s4tj|d } || }tj|| |}|jdk7r td |jdk(r tdt|jj tj"s|j%tj&}||jz|_||_|j-|j*|_||_~~||_|dvrd} |dk(r\d|_|j0dz |_|j6dd|j6ddz|_|j8j:|_n|dk(r\d|_|j0dz |_|j6dd|j6ddz|_|j8j:|_n|dk(rd|_d|_tj@|j0tjB |_"|j8jF|_tI|rI|jKtjLtj|j*d|f}n|dk(rd|_d|_tj@|j0tjB|_"|j8jF|_tI|r|jKtj|j*d|tjLf}nVtjtj&tjt f} |j0j| vxr|j*j| v} | xr|j*jdk(} | xr tI| } | r|j8jN|_n|j8jP|_n dz} d}|j0|j.}}| dkDr tjR|j0}|jUr|j0|}|jVdk(r tdtjXtjZ|j0tj\|j0t_|j0}d}tjR|j.jUr!tj`|j.}d}tc||| d|_2|r|j8jf|_n|j8jh|_t_|j0| krtd| d||_5y)z- Initialize a 1-D linear interpolation class.axis)zeroslinear quadraticcubicrrspline)r3nearest nearest-uppreviousnextz6 is unsupported: Use fitpack routines for other types.)r/ mergesort)r.z,the x array must have exactly one dimension.z-the y array must have at least one dimension.rZleftg@Nr:r[rightr\r]Fz`x` array is all-nanT)r" check_finitez"x and y arrays must have at least z entries)6rr2r0r/rrLintr)r r>argsorttakendimrB issubclassr@typeinexactastypefloat64rRr, _reshape_yi_yr_kind_sidex_bds __class__ _call_nearest_call_ind nextafterinf_x_shift_call_previousnextrN0_check_and_update_bounds_error_for_extrapolationnan_call_linear_np _call_linearisnananyr=linspacenanminnanmaxr ones_liker_spline_call_nan_spline _call_spliner1)r+rr,r.rRr/r0r1 assume_sortedorderindminval np_dtypescond rewrite_nanxxyymasksxs r$r2zinterp1d.__init__s   q!$7( &DI < <1"#a1157ED c "ED ""%/B'BC C !$)) $ !$)) $**Q[1C#A3T*A 66Q;KL L 66Q;LM M!'',, 3$A166M ""466* q J JFy $ !VVc\ !ZZ^djj"o= !^^99 %% !VVc\ !ZZ^djj"o= !^^99 ##  " TVVbffW = !^^>> ":.IIK"$&&"''$&&"d*C!DJ$  " TVVRVV < !^^>> ":.IIK"$''$&&!T":BFF!CJ XXbjj1288C=A vv||y0NTVV\\Y5N0 q 0?OJ$? ?!%!?!?DJ!%!r rrI_fill_value_below_fill_value_abover0r)r+r1broadcast_shape below_abovenamesiis r$r1zinterp1d.fill_valuesO : &  A A C $D 0!+- $vv||JTYY7#vv||DIIMN; interprr,r+x_news r$rzzinterp1d._call_linear_npsyy//r%cvt|j|}|jdt|jdz j t }|dz }|}|j|}|j|}|j |}|j |}||z ||z dddfz } | ||z dddfz|z} | S)Nr)rrcliprrirbrl) r+r x_new_indiceslohix_lox_hiy_loy_hislopey_news r$r{zinterp1d._call_linears%TVVU3 &**1c$&&k!m<CCCH Q  vvbzvvbzwwr{wwr{ag 66ut|QW--4 r%ct|j||j}|jdt |j dz j t}|j|}|S)z5 Find nearest neighbor interpolated y_new = f(x_new).siderr) rrornrrrrir rlr+rrrs r$rqzinterp1d._call_nearestsZ%TZZTZZH &**1c$&&k!m<CCDI  & r%c,t|j||j}|jd|jz t |j |jz jt}|j||jzdz }|S)z6Use previous/next neighbor of x_new, y_new = f(x_new).rr) rrvrnrrsrrrir rlrs r$rwzinterp1d._call_previousnext sz%T]]E K &**1TYY;+.tvv;tyy+@BBH&,  dii/12 r%c$|j|Sr()rrs r$rzinterp1d._call_splines||E""r%cN|j|}tj|d<|S)N.)rr>ry)r+routs r$rzinterp1d._call_nan_splines"ll5!66C r%ct|}|j||}|js@|j|\}}t |dkDr|j ||<|j ||<|SNr)r rrr _check_boundsrrr)r+rr below_bounds above_boundss r$ _evaluatezinterp1d._evaluate sm 4'  )-););E)B &L,5zA~'+&<&<l#&*&<&<l# r%c||jdk}||jdkD}|jrG|jr7|tj|}t d|d|jdd|jrG|jr7|tj|}t d|d|jdd||fS)aCheck the inputs for being in the bounds of the interpolated data. Parameters ---------- x_new : array Returns ------- out_of_bounds : bool array The mask on x_new of values that are out of the bounds. rr:z A value (z=) in x_new is below the interpolation range's minimum value (z).z=) in x_new is above the interpolation range's maximum value ()rr0r}r>argmaxrB)r+rrrbelow_bounds_valueabove_bounds_values r$rzinterp1d._check_bounds/s tvvay( tvvbz)   !1!1!3!&ryy'>!? y);(<=IIMPQ SUWX X   !1!1!3!&ryy'>!? y);(<=IIMPR TVXY Y \))r%)r4r5r6r7r>ryr2propertyr1setterrxrzr{rqrwrrrrr8r%r$rrsjX#+"&&$P%d%% ++<" 0:" # *r%rcHeZdZdZdZd dZdZed dZdZ dZ d d Z y) _PPolyBasez%Base class for piecewise polynomials.)crrKrRNcLtj||_tj|tj|_|d}n|dk7r t |}||_|jjdkr tdd|cxkr|jjdz ks*ntd|d |jjdz ||_ |dk7rRtj|j|dzd|_tj|j|dzd|_|j jdk7r td |j jdkr td |jjdkr td |jjddk(r td |jjd|j jdz k7r tdtj|j }tj|dk\s#tj|dks td|j!|jj"}tj|j||_y)Nr@TperiodicrWz2Coefficients array must be at least 2-dimensional.rrzaxis=z must be between 0 and zx must be 1-dimensionalz!at least 2 breakpoints are neededz!c must have at least 2 dimensionsz&polynomial must be at least of order 0z"number of coefficients != len(x)-1z.`x` must be strictly increasing or decreasing.)r>r rascontiguousarrayrjrboolrKrerBrRmoveaxisr=r;diffall _get_dtyper@)r+rrrKrRdxr@s r$r2z_PPolyBase.__init__TsA%%arzz:  K J &{+K& 66;;?./ /T+DFFKK!O+uTF*A$&&++a-QR R 19[[a3DF[[a3DF 66;;! 67 7 66;;?@A A 66;;?@A A 66<<?a EF F 66<<?dffkk!m +AB B WWTVV_rQw266"'?MN N -%%dffE:r%ctj|tjs8tj|jjtjrtj Stj Sr(r> issubdtypecomplexfloatingrr@ complex128rjr+r@s r$rz_PPolyBase._get_dtypeF == 2 2 3-- b.@.@A== :: r%cptj|}||_||_||_|d}||_|S)aH 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. T)object__new__rrrRrK)clsrrrKrRr+s r$construct_fastz_PPolyBase.construct_fasts?~~c"  K& r%c|jjjs|jj|_|jjjs |jj|_yy)zr c and x may be modified by the user. The Cython code expects that they are C contiguous. N)rflags c_contiguousr/rrs r$_ensure_c_contiguousz_PPolyBase._ensure_c_contiguoussM vv||((VV[[]DFvv||((VV[[]DF)r%cHtj|}tj|}|jdkr td|jdk7r td|jd|jdk7r&td|jd|jd|jdd |j jdd k7s#|j|j jk7r0td |jd |j jd|j dk(ry tj|}tj|dk\s#tj|dks td |jd |jdk\rQ|d |dk\s td|d|jd k\rd}nt|d |jdkrd}n\td|d |dks td|d|jd krd}n#|d |jdk\rd}n td|j|j}t|jd|j jd}tj||j jd|jdzf|j jdd z|}|dk(r|j |||j jdz d d |j jdf<||||jdz d |j jdd f<tj|j|f|_ ||_y |dk(r||||j jdz d d |jdf<|j |||jdz d |jdd f<tj||jf|_ ||_y )a Add additional breakpoints and coefficients to the polynomial. Parameters ---------- c : ndarray, size (k, m, ...) Additional coefficients for polynomials in intervals. Note that the first additional interval will be formed using one of the ``self.x`` end points. x : ndarray, size (m,) Additional breakpoints. Must be sorted in the same order as ``self.x`` and either to the right or to the left of the current breakpoints. Notes ----- This method is not thread safe and must not be executed concurrently with other methods available in this class. Doing so may cause unexpected errors or numerical output mismatches. rWzinvalid dimensions for crzinvalid dimensions for xrz Shapes of x z and c  are incompatibleNz Shapes of c z and self.c z`x` is not sorted.r:z,`x` is in the different order than `self.x`.appendprependz9`x` is neither on the left or on the right from `self.x`.r)r>r rerBr;rr=rrrrr@maxzerosr_)r+rrractionr@k2c2s r$extendz_PPolyBase.extends, JJqM JJqM 66A:78 8 66Q;78 8 771: #|AGG9GAGG9DUVW W 7712;$&&,,qr* *aff .Cqwwi|DFFLL>ARS  66Q;  WWQZrQw266"'?12 2 66": "R5AaD= "122ttvvbz!!2$&&)#" "122R5AaD= "122ttvvbz!!2$&&)#" "122( TVV\\!_ - XXr466<<?QWWQZ78466<<;KK! X 8<Br$&&,,q/!"$4TVV\\!_$44 534Br!''!*}~tvv||A// 0UU46619%DF  y 34Br$&&,,q/!"KQWWQZK/ 0.2ffBr!''!*}~qwwqz{* +UU1dff9%DFr%c| |j}tj|}|j|j}}tj |j tj}|dk(rD|jd||jdz |jd|jdz zz}d}tjt|t|jjddf|jj}|j|j|||||j!||jjddz}|j"dk7rZt%t'|j}||||j"z|d|z|||j"zdz}|j)|}|S)aX Evaluate the piecewise polynomial or its derivative. Parameters ---------- x : array_like Points to evaluate the interpolant at. nu : int, optional Order of derivative to evaluate. Must be non-negative. extrapolate : {bool, 'periodic', None}, optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. If None (default), use `self.extrapolate`. Returns ------- y : array_like Interpolated values. Shape is determined by replacing the interpolation axis in the original array with the shape of x. 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]``. Nrrrr:FrW)rKr>r r;rerrArjremptyrr rr@rrreshaperRlistr transpose)r+rnurKx_shapex_ndimrls r$__call__z_PPolyBase.__call__sq<  **K JJqM''166  "** = * $q Q]tvvbzDFF1I/EFFAKhhATVV\\!"%5 67tvv||L !!# q"k3/kk'DFFLL$445 99>U388_%A& )*QwZ7!F499rr@specpocharangeslicererrrKrR)r+rrfactors r$ derivativezPPoly.derivativeos0 6&&s+ + 7B"a%%'B 88A;! $!"-RXX>B299RXXa[!R8"= feDk^grwwqy&99::""2tvvt/?/?KKr%c l|dkr|j| Stj|jjd|z|jjdf|jjddz|jj }|j|d| t jtj|jjddd|}|d| xxx|tdfd|jdz zzzccc|jtj|j|jd|jdd|j|dz |j dk(rd }n |j }|j#||j||j$S) a= 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 : int, optional Order of antiderivative to evaluate. Default is 1, i.e., compute the first integral. If negative, the derivative is returned. Returns ------- pp : PPoly Piecewise polynomial of order k2 = k + n representing the antiderivative of this polynomial. Notes ----- The antiderivative returned by this function is continuous and continuously differentiable to order n-1, up to floating point rounding error. If antiderivative is computed and ``self.extrapolate='periodic'``, it will be set to False for the returned instance. This is done because the antiderivative is no longer periodic and its correct evaluation outside of the initially given x interval is difficult. rrrWNrr:r(rF)rr>rrr;r@rrrrrerrfix_continuityrrrKrrR)r+rrrrKs r$rzPPoly.antiderivativesa< 7??B3' ' HHdffll1o*DFFLLO> !!#aii AGGAJC"ffb1f .   z )K**K""1dffk499EEr%Nc | |j}d}||kr||}}d}tjt|jj ddf|jj }|j|dk(rP|jd|jd}}||z }||z } t| |\} } | dkDrttj|jj|jj d|jj dd|j||d| || z}n|jd|||z |zz}|| z}tj|} ||krutj|jj|jj d|jj dd|j||d| || z }ngtj|jj|jj d|jj dd|j||d| || z }tj|jj|jj d|jj dd|j||| z|z|z d| || z }nwtj|jj|jj d|jj dd|j||t|| ||z}|j|jj ddS) a Compute a definite integral over a piecewise polynomial. Parameters ---------- a : float Lower integration bound b : float Upper integration bound extrapolate : {bool, 'periodic', None}, optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. If None (default), use `self.extrapolate`. Returns ------- ig : array_like Definite integral of the piecewise polynomial over [a, b] Nrr:rWrrrF)r)rKr>rr rr;r@rrdivmodr integraterfill empty_liker) r+abrKsign range_intxsxeperiodinterval n_periodsr_ remainder_ints r$rzPPoly.integrates*  **K q5aqADHHd466<<#346dffllK  !!# * $VVAYr B"WF1uH$Xv6OIt1}  FFNN466<<?DFFLLORHFFBEy:Y& q!a"f&&ADAMM)4MBw  FFNN466<<?DFFLLORHFFAq%]<]*   FFNN466<<?DFFLLORHFFAr5m=]*   FFNN466<<?DFFLLORHFFBT A  2E}N]*   tvv||A QD1d;/Y @ T   ab!122r%c | |j}|jtj|jj tj r tdt|}tj|jj|jjd|jjdd|j|t|t|}|jjdk(r|dStj t#|jjddt$}t'|D] \}}|||< |j|jjddS)a Find real solutions of the equation ``pp(x) == y``. Parameters ---------- y : float, optional Right-hand side. Default is zero. discontinuity : bool, optional Whether to report sign changes across discontinuities at breakpoints as roots. extrapolate : {bool, 'periodic', None}, optional If bool, determines whether to return roots from the polynomial extrapolated based on first and last intervals, 'periodic' works the same as False. If None (default), use `self.extrapolate`. Returns ------- roots : ndarray Roots of the polynomial(s). If the PPoly object describes multiple polynomials, the return value is an object array whose each element is an ndarray containing the roots. Notes ----- This routine works only on real-valued polynomials. If the piecewise polynomial contains sections that are identically zero, the root list will contain the start point of the corresponding interval, followed by a ``nan`` value. If the polynomial is discontinuous across a breakpoint, and there is a sign change across the breakpoint, this is reported if the `discont` parameter is True. Examples -------- Finding roots of ``[x**2 - 1, (x - 1)**2]`` defined on intervals ``[-2, 1], [1, 2]``: >>> import numpy as np >>> from scipy.interpolate import PPoly >>> pp = PPoly(np.array([[1, -4, 3], [1, 0, 0]]).T, [-2, 1, 2]) >>> pp.solve() array([-1., 1.]) Nz0Root finding is only for real-valued polynomialsrrr:rWr)rKrr>rrr@rrBfloatr real_rootsrr;rrrerr r enumerate)r+r, discontinuityrKrr2rroots r$solvez PPoly.solve#s/b  **K !!# ==r'9'9 :78 8 !H   dffnnTVV\\!_dffll1orR"ffam)<";/ 1 66;;! Q4K$tvv||AB/0?B&aL D2 ::dffll12./ /r%c(|jd||S)a[ Find real roots of the piecewise polynomial. Parameters ---------- discontinuity : bool, optional Whether to report sign changes across discontinuities at breakpoints as roots. extrapolate : {bool, 'periodic', None}, optional If bool, determines whether to return roots from the polynomial extrapolated based on first and last intervals, 'periodic' works the same as False. If None (default), use `self.extrapolate`. Returns ------- roots : ndarray Roots of the polynomial(s). If the PPoly object describes multiple polynomials, the return value is an object array whose each element is an ndarray containing the roots. See Also -------- PPoly.solve r)r)r+rrKs r$rootsz PPoly.rootsls6zz!]K88r%ct|tr|j\}}}||j}n|\}}}t j |dzt |dz f|j}t|ddD]B}tj|dd||}|tj|dzz |||z ddf<D|j|||S)a Construct a piecewise polynomial from a spline Parameters ---------- tck A spline, as returned by `splrep` or a BSpline object. extrapolate : bool or 'periodic', optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True. Examples -------- Construct an interpolating spline and convert it to a `PPoly` instance >>> import numpy as np >>> from scipy.interpolate import splrep, PPoly >>> x = np.linspace(0, 1, 11) >>> y = np.sin(2*np.pi*x) >>> tck = splrep(x, y, s=0) >>> p = PPoly.from_spline(tck) >>> isinstance(p, PPoly) True Note that this function only supports 1D splines out of the box. If the ``tck`` object represents a parametric spline (e.g. constructed by `splprep` or a `BSpline` with ``c.ndim > 1``), you will need to loop over the dimensions manually. >>> from scipy.interpolate import splprep, splev >>> t = np.linspace(0, 1, 11) >>> x = np.sin(2*np.pi*t) >>> y = np.cos(2*np.pi*t) >>> (t, c, k), u = splprep([x, y], s=0) Note that ``c`` is a list of two arrays of length 11. >>> unew = np.arange(0, 1.01, 0.01) >>> out = splev(unew, (t, c, k)) To convert this spline to the power basis, we convert each component of the list of b-spline coefficients, ``c``, into the corresponding cubic polynomial. >>> polys = [PPoly.from_spline((t, cj, k)) for cj in c] >>> polys[0].c.shape (4, 14) Note that the coefficients of the polynomials `polys` are in the power basis and their dimensions reflect just that: here 4 is the order (degree+1), and 14 is the number of intervals---which is nothing but the length of the knot array of the original `tck` minus one. Optionally, we can stack the components into a single `PPoly` along the third dimension: >>> cc = np.dstack([p.c for p in polys]) # has shape = (4, 14, 2) >>> poly = PPoly(cc, polys[0].x) >>> np.allclose(poly(unew).T, # note the transpose to match `splev` ... out, atol=1e-15) True Nrrr:)der)rLrtckrKr>rrr@rrsplevrgammar) rr!rKrGrr"cvalsmr,s r$ from_splinezPPoly.from_splinesF c7 #ggGAq!"!oo GAq!!a%Q*!'':q"b! 0A!!!CR5A 1Q3/E!a%(O 0!!%K88r%c t|tstdt|dt j |j }|jjddz }d|jjdz z}t j|j}t|dzD]y}d|zt||z|j|z}t||dzD]C} t||z | |z d| zz} ||| z xx|| z|tdf|z| zz z cc<E{| |j}|j||j ||j S) a Construct a piecewise polynomial in the power basis from a polynomial in Bernstein basis. Parameters ---------- bp : BPoly A Bernstein basis polynomial, as created by BPoly extrapolate : bool or 'periodic', optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True. z8.from_bernstein_basis only accepts BPoly instances. Got instead.rrr(rWr:N)rLr TypeErrorrgr>rrrr;re zeros_likerrrrKrrR) rbprKrr"restrr rsvals r$from_bernstein_basiszPPoly.from_bernstein_basissR"e$##'8*I78 8WWRTT] DDJJqMA  ! $ MM"$$ qs DA1WtAqz)BDDG3F1ac] D1Q3!nQw.!A#&3,U4[N4,?)@!)CCC D D  ..K!!!RTT;@@r%rr()rTN)TN) r4r5r6r7rrrrrrrr&r/r8r%r$rr0s[8t?*LX4FlP3dG0R9:N9N9`!A!Ar%rceZdZdZdZd dZd dZd dZdZe jje_e d dZ e dd Z e d Ze d Zy)rav Piecewise polynomial in the Bernstein basis. The polynomial between ``x[i]`` and ``x[i + 1]`` is written in the Bernstein polynomial basis:: S = sum(c[a, i] * b(a, k; x) for a in range(k+1)), where ``k`` is the degree of the polynomial, and:: b(a, k; x) = binom(k, a) * t**a * (1 - t)**(k - a), with ``t = (x - x[i]) / (x[i+1] - x[i])`` and ``binom`` is the binomial coefficient. Parameters ---------- c : ndarray, shape (k, m, ...) Polynomial coefficients, order `k` and `m` intervals x : ndarray, shape (m+1,) Polynomial breakpoints. Must be sorted in either increasing or decreasing order. extrapolate : bool, optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True. axis : int, optional Interpolation axis. Default is zero. Attributes ---------- x : ndarray Breakpoints. c : ndarray Coefficients of the polynomials. They are reshaped to a 3-D array with the last dimension representing the trailing dimensions of the original coefficient array. axis : int Interpolation axis. Methods ------- __call__ extend derivative antiderivative integrate construct_fast from_power_basis from_derivatives See also -------- PPoly : piecewise polynomials in the power basis Notes ----- Properties of Bernstein polynomials are well documented in the literature, see for example [1]_ [2]_ [3]_. References ---------- .. [1] https://en.wikipedia.org/wiki/Bernstein_polynomial .. [2] Kenneth I. Joy, Bernstein polynomials, http://www.idav.ucdavis.edu/education/CAGDNotes/Bernstein-Polynomials.pdf .. [3] E. H. Doha, A. H. Bhrawy, and M. A. Saker, Boundary Value Problems, vol 2011, article ID 829546, :doi:`10.1155/2011/829543`. Examples -------- >>> from scipy.interpolate import BPoly >>> x = [0, 1] >>> c = [[1], [2], [3]] >>> bp = BPoly(c, x) This creates a 2nd order polynomial .. math:: B(x) = 1 \times b_{0, 2}(x) + 2 \times b_{1, 2}(x) + 3 \times b_{2, 2}(x) \\ = 1 \times (1-x)^2 + 2 \times 2 x (1 - x) + 3 \times x^2 c tj|jj|jjd|jjdd|j ||t ||yr)revaluate_bernsteinrrr;rrrs r$rzBPoly._evaluateVsP!! FFNN466<<?DFFLLOR @ FFAr4 ,c 3r%c|dkr|j| S|dkDr$|}t|D]}|j}|S|dk(r|jj }nd|jj dz z}|jj ddz }tj|jdtdf|z}|tj|jdz|z }|j ddk(r1tjd|j ddz|j}|j||j|j|jS) a Construct a new piecewise polynomial representing the derivative. Parameters ---------- nu : int, optional Order of derivative to evaluate. Default is 1, i.e., compute the first derivative. If negative, the antiderivative is returned. Returns ------- bp : BPoly Piecewise polynomial of order k - nu representing the derivative of this polynomial. rrr(rWNrQrr)rrrrr/rer;r>rrrrr@rrKrR)r+rr+r"rr,rs r$rzBPoly.derivative[s/" 6&&s+ + 6B2Y %]]_ %I 7BDFFKKM*D Q!#A$d !4T!9:BRWWTVV!,,r1B 88A;! $!"-RXX>B""2tvvt/?/?KKr%c |dkr|j| S|dkDr$|}t|D]}|j}|S|j|j}}|j d}t j|dzf|j ddz|j}t j|d|z |dddf<|dd|ddz }||dtdfd|jd z zzz}|ddddfxxt j||ddfdddz cc<|jd k(rd }n |j}|j||||jS) a Construct a new piecewise polynomial representing the antiderivative. Parameters ---------- nu : int, optional Order of antiderivative to evaluate. Default is 1, i.e., compute the first integral. If negative, the derivative is returned. Returns ------- bp : BPoly Piecewise polynomial of order k + nu representing the antiderivative of this polynomial. Notes ----- If antiderivative is computed and ``self.extrapolate='periodic'``, it will be set to False for the returned instance. This is done because the antiderivative is no longer periodic and its correct evaluation outside of the initially given x interval is difficult. rrNrrQ.r:r(rWrF)rrrrrr;r>rr@cumsumrrerKrrR) r+rr+r"rrrdeltarKs r$rzBPoly.antiderivativesa. 7??B3' ' 6B2Y )&&( )Ivvtvv1 GGAJ XXqsfqwwqr{*!'' :ii*Q.12s7 !"#2 eT5;''166!8*<<== 1QR4BIIbAhQ/44   z )K**K""2q+DII"FFr%Nc|j}| |j}|dk7r||_|dk(r||krd}n||}}d}|jd|jd}}||z }||z } t| |\} } | ||||z z} |||z |zz}|| z}||kr| ||||z z } || zS| ||||z ||| z|z|z z||z z } || zS||||z S)at Compute a definite integral over a piecewise polynomial. Parameters ---------- a : float Lower integration bound b : float Upper integration bound extrapolate : {bool, 'periodic', None}, optional Whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. If None (default), use `self.extrapolate`. Returns ------- array_like Definite integral of the piecewise polynomial over [a, b] rrr:r)rrKrr) r+r r rKibr rrrrrr_ress r$rzBPoly.integratesF. "  **K * $(BN * $ Av!1VVAYr B"WF1uH$Xv6OItr"v2/Ca"f&&ADABwr!ur!u}$#: r"v1~29q=2+=(>>BGG#: a52a5= r%cJt|jjd|jd}|j|j||jjdz |_|j|||jdz }tj |||Sr)rrr; _raise_degreerr)r+rrr"s r$rz BPoly.extends~  Q ,##DFFA Q,?@   q!aggaj. 1  q!,,r%c t|tstdt|dt j |j }|jjddz }d|jjdz z}t j|j}t|dzD]n}|j|t|||z z |tdf|z||z zz}t||z |dzD]} || xx|t| ||z zz cc<!p| |j}|j||j ||j S)a Construct a piecewise polynomial in Bernstein basis from a power basis polynomial. Parameters ---------- pp : PPoly A piecewise polynomial in the power basis extrapolate : bool or 'periodic', optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True. z4.from_power_basis only accepts PPoly instances. Got r(rrr(rWN)rLrr)rgr>rrrr;rer*rrrrKrrR) rpprKrr"r,rr rr s r$from_power_basiszBPoly.from_power_basiss<"e$##'8*I78 8WWRTT] DDJJqMA  ! $ MM"$$ qs .ATT!WtAqs|+b%+1D.E!.LLF1Q3!_ .!a1-- . .  ..K!!!RTT;@@r%c <tj|}t|tk7r tdtj|dd|ddz dkr tdt|dz } t fdt |D}|dg|z}nYt|ttjzr|g|z}t |t |}t d|Dr td g}t |D]N} | | dz} } || t| t| } } n|| dz}t|d zt| } t|| z t| } t|| z t| } | | z|k7r;d || d t| d || dzd t| d|| d }t|| t| kr| t| ks tdtj|| || dz| d| | d| }t||kr"tj||t|z }|j|Qtj|}||j!dd||S#t$r}td|d}~wwxYw)a< Construct a piecewise polynomial in the Bernstein basis, compatible with the specified values and derivatives at breakpoints. Parameters ---------- xi : array_like sorted 1-D array of x-coordinates yi : array_like or list of array_likes ``yi[i][j]`` is the ``j``\ th derivative known at ``xi[i]`` orders : None or int or array_like of ints. Default: None. Specifies the degree of local polynomials. If not None, some derivatives are ignored. extrapolate : bool or 'periodic', optional If bool, determines whether to extrapolate to out-of-bounds points based on first and last intervals, or to return NaNs. If 'periodic', periodic extrapolation is used. Default is True. Notes ----- If ``k`` derivatives are specified at a breakpoint ``x``, the constructed polynomial is exactly ``k`` times continuously differentiable at ``x``, unless the ``order`` is provided explicitly. In the latter case, the smoothness of the polynomial at the breakpoint is controlled by the ``order``. Deduces the number of derivatives to match at each end from ``order`` and the number of derivatives available. If possible it uses the same number of derivatives from each end; if the number is odd it tries to take the extra one from y2. In any case if not enough derivatives are available at one end or another it draws enough to make up the total from the other end. If the order is too high and not enough derivatives are available, an exception is raised. Examples -------- >>> from scipy.interpolate import BPoly >>> BPoly.from_derivatives([0, 1], [[1, 2], [3, 4]]) Creates a polynomial `f(x)` of degree 3, defined on ``[0, 1]`` such that `f(0) = 1, df/dx(0) = 2, f(1) = 3, df/dx(1) = 4` >>> BPoly.from_derivatives([0, 1, 2], [[0, 1], [0], [2]]) Creates a piecewise polynomial `f(x)`, such that `f(0) = f(1) = 0`, `f(2) = 2`, and `df/dx(0) = 1`. Based on the number of derivatives provided, the order of the local polynomials is 2 on ``[0, 1]`` and 1 on ``[1, 2]``. Notice that no restriction is imposed on the derivatives at ``x = 1`` and ``x = 2``. Indeed, the explicit form of the polynomial is:: f(x) = | x * (1 - x), 0 <= x < 1 | 2 * (x - 1), 1 <= x <= 2 So that f'(1-0) = -1 and f'(1+0) = 2 z&xi and yi need to have the same lengthrNrz)x coordinates are not in increasing orderc3^K|]$}t|t|dzz&ywrN)r).0iyis r$ z)BPoly.from_derivatives..}s*@!C1JR!W-@s*-z0Using a 1-D array for y? Please .reshape(-1, 1).c3&K|] }|dk ywrr8)rBos r$rEz)BPoly.from_derivatives..s*a16*szOrders must be positive.rWzPoint z has z derivatives, point z derivatives, but order z requestedz0`order` input incompatible with length y1 or y2.)r>r rrBr}rrr)rLrbintegerminr_construct_from_derivativesr;rswapaxes)rxirDordersrKr%r"errCy1y2n1n2nmesgr s ` r$from_derivativeszBPoly.from_derivatives2s@ZZ^ r7c"g EF F 66"QR&2bq6/Q& 'HI I GaK @uQx@@A >VaZF&# "23 AAs6{#A*6** !;<< q AUBqsGBay R#b'B1IaKAs2w'RR)RR)7a< AuSWI5I"QqS'RWr7)#;F1I;jR%T**c"g "B-$&9::11"Q%AaC24Sb'2cr7DA1vz''1s1v:6 HHQK1 4 JJqM1::a#R55W B  s4J J JJc htj|tj|}}|jdd|jddk7r&td|jd|jd|j|j}}tj |tj s$tj |tj rtj}ntj}t|t|}}||z} tj||zf|jddz|} td|D]d} || tj| | z | z ||z | zz| | <td| D](} | | xxd| | zzt| | z| | zzcc<*ftd|D]y} || tj| | z | z d| zz||z | zz| | dz <td| D]3} | | dz xxd| dzzt| | dzz| | | zzzcc<5{| S) aLCompute the coefficients of a polynomial in the Bernstein basis given the values and derivatives at the edges. Return the coefficients of a polynomial in the Bernstein basis defined on ``[xa, xb]`` and having the values and derivatives at the endpoints `xa` and `xb` as specified by `ya` and `yb`. The polynomial constructed is of the minimal possible degree, i.e., if the lengths of `ya` and `yb` are `na` and `nb`, the degree of the polynomial is ``na + nb - 1``. Parameters ---------- xa : float Left-hand end point of the interval xb : float Right-hand end point of the interval ya : array_like Derivatives at `xa`. ``ya[0]`` is the value of the function, and ``ya[i]`` for ``i > 0`` is the value of the ``i``\ th derivative. yb : array_like Derivatives at `xb`. Returns ------- array coefficient array of a polynomial having specified derivatives Notes ----- This uses several facts from life of Bernstein basis functions. First of all, .. math:: b'_{a, n} = n (b_{a-1, n-1} - b_{a, n-1}) If B(x) is a linear combination of the form .. math:: B(x) = \sum_{a=0}^{n} c_a b_{a, n}, then :math: B'(x) = n \sum_{a=0}^{n-1} (c_{a+1} - c_{a}) b_{a, n-1}. Iterating the latter one, one finds for the q-th derivative .. math:: B^{q}(x) = n!/(n-q)! \sum_{a=0}^{n-q} Q_a b_{a, n-q}, with .. math:: Q_a = \sum_{j=0}^{q} (-)^{j+q} comb(q, j) c_{j+a} This way, only `a=0` contributes to :math: `B^{q}(x = xa)`, and `c_q` are found one by one by iterating `q = 0, ..., na`. At ``x = xb`` it's the same with ``a = n - q``. rNz Shapes of ya z and yb rrrr:)r>r r;rBr@rrrrjrrrrrr) xaxbyaybdtadtbdtnanbrSrqr s r$rJz!BPoly._construct_from_derivativess nBBB 88AB<288AB< 'z"((;LM 88RXXS MM#r11 2}}S""4"45BBR#b'B G HHbeX ,B 7q" 8Aa5499QUA.."r'A=AaD1a[ 8!qs d1aj01Q477 8 8 q" @AediiAq11R!G;rBwlJAqbdG1a[ @1"Q$B!A#;a151"Q$?? @ @ r%c |dk(r|S|jddz }tj|jd|zf|jddz|j}t |jdD]W}||t ||z}t |dzD]2}|||zxx|t ||zt ||z||zz z cc<4Y|S)a Raise a degree of a polynomial in the Bernstein basis. Given the coefficients of a polynomial degree `k`, return (the coefficients of) the equivalent polynomial of degree `k+d`. Parameters ---------- c : array_like coefficient array, 1-D d : integer Returns ------- array coefficient array, 1-D array of length `c.shape[0] + d` Notes ----- This uses the fact that a Bernstein polynomial `b_{a, k}` can be identically represented as a linear combination of polynomials of a higher degree `k+d`: .. math:: b_{a, k} = comb(k, a) \sum_{j=0}^{d} b_{a+j, k+d} \ comb(d, j) / comb(k+d, a+j) rrNr)r;r>rr@rr)rdr"rr rHr s r$r;zBPoly._raise_degrees8 6H GGAJNhh Q(17712;6aggFqwwqz" rU staticmethodrJr;r8r%r$rrsTl3 3Lj6Gp>!@-  &&..FN A ADv6v6pUUn%%r%rcfeZdZdZddZeddZdZdZddZ dZ d Z d Z d Z dd Zdd Zy)raW 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. Attributes ---------- x : tuple of ndarrays Breakpoints. c : ndarray Coefficients of the polynomials. Methods ------- __call__ derivative antiderivative integrate integrate_1d construct_fast See also -------- PPoly : piecewise polynomials in 1D Notes ----- High-order polynomials in the power basis can be numerically unstable. Nc td|D|_tj||_|d}t ||_t|j}td|jDr tdtd|jDr td|jd|zkr tdtd |jDr td td t|j|d|z|jDr td |j|jj}tj|j| |_y)Nc3fK|])}tj|tj+yw)rN)r>rrjrBvs r$rEz#NdPPoly.__init__..ls$LQr++ARZZ@@Ls/1Tc3:K|]}|jdk7ywrA)rerhs r$rEz#NdPPoly.__init__..ss+qqvv{+z"x arrays must all be 1-dimensionalc3:K|]}|jdkyw)rWNr=rhs r$rEz#NdPPoly.__init__..us*aqvvz*rkz+x arrays must all contain at least 2 pointsrWz(c must have at least 2*len(x) dimensionsc3^K|]%}tj|dd|ddz dk'yw)rNr:r)r>r}rhs r$rEz#NdPPoly.__init__..ys.:arvvaeafnq():s+-z)x-coordinates are not in increasing orderc3FK|]\}}||jdz k7ywrArm)rBr r s r$rEz#NdPPoly.__init__..{s M41aqAFFQJMs!z/x and c do not agree on the number of intervalsr)rrr>r rrrKrr}rBrer<r;rr@r)r+rrrKrer@s r$r2zNdPPoly.__init__ksL!LLA  K ,466{ +DFF+ +AB B *466* *JK K 66AdF?GH H :466: :HI I M3qwwtAdF/CTVV+LM MNO O -%%dffE:r%cbtj|}||_||_|d}||_|S)aJ 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. T)rrrrrK)rrrrKr+s r$rzNdPPoly.construct_fasts8~~c"  K& r%ctj|tjs8tj|jjtjrtj Stj Sr(rrs r$rzNdPPoly._get_dtyperr%c|jjjs|jj|_t |j t st |j |_yyr()rrrr/rLrrrs r$rzNdPPoly._ensure_c_contiguoussFvv||((VV[[]DF$&&%(466]DF)r%c | |j}n t|}t|j}t |}|j }t j|jd|j dt j}|'t j|ft j}nQt j|t j}|jdk7s|j d|k7r tdt|j j d|}t|j j |d|z}t|j j d|zd}t j"|j j d|t j} t j$|j d|f|j j&} |j)t+j,|j j||||j| ||t|| | j|dd|j j d|zdzS)a 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 : array-like Interpolated values. Shape is determined by replacing the interpolation axis in the original array with the shape of x. 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]``. Nr:rrrz&invalid number of derivative orders nurW)rKrrrrr;r>rrrjrintcr rerBr rr rr@rr evaluate_nd) r+rrrKrerdim1dim2dim3ksrs r$rzNdPPoly.__call__s:  **K{+K466{ $Q '''  2qwwr{!;2:: N :4'1BBbgg.Bww!|rxx{d2 !IJJDFFLL$'(DFFLLaf-.DFFLL4)* XXdffll5D) 9hh D)> !!#466>>$d;66 ,  {{73B<$&&,,qvw*??@@r%cZ|dkr|j| |St|j}||z}|dk(rytdg|z}td| d||<|jt |}|j |dk(r;t|j }d||<tj||j}tjtj|j |dd|}dg|jz}td||<||t |z}||_y)zz Compute 1-D derivative along a selected dimension in-place May result to non-contiguous c array. rNrrr:)_antiderivative_inplacerrrrrr;rr>rr@rrrre)r+rrRreslrshprs r$_derivative_inplacezNdPPoly._derivative_inplaces 6//T: :466{d{ 7 +t#BTB3-BtHb "B 88D>Q rxx.CCI#RXX.B299RXXd^Q;R@VBGG^;4 fU2Yr%c @|dkr|j| |St|j}||z}tt |}|||dc|d<||<|tt ||j j z}|j j|}tj|jd|zf|jddz|j}||d| tjtj|jddd|}|d| xxx|tdfd|j dz zzzccctt |j }|||z|dc|d<|||z<|j|}|j!}t#j$|j'|jd|jdd|j||dz |j|}|j|}||_y)zu Compute 1-D antiderivative along a selected dimension May result to non-contiguous c array. rrNrr:r()r~rrrrrrerr>rr;r@rrrrr/rrr) r+rrRrepermrrrperm2s r$r{zNdPPoly._antiderivative_inplaces 7++RC6 6466{d{E$K "4j$q'Qdd5tvv{{344 FF  T " XXqwwqzB(17712;677$4RC299QWWQZB7< 4RCFE$K>GQVVAX,>>??U277^$%*49%5uQx"a%T " \\%  WWYbjj!bhhqk2F"ffTlBqD 2\\%  \\$ r%c|j|jj|j|j}t |D]\}}|j |||j|S)a$ 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 : NdPPoly Piecewise polynomial of orders (k[0] - nu[0], ..., k[n] - nu[n]) representing the derivative of this polynomial. 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]``. )rrr/rrKrr~rr+rrrRrSs r$rzNdPPoly.derivative,sf2    tvvt7G7G H } +GD! ! !!T * +  r%c|j|jj|j|j}t |D]\}}|j |||j|S)a 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 : PPoly Piecewise polynomial of order k2 = k + n representing the antiderivative of this polynomial. Notes ----- The antiderivative returned by this function is continuous and continuously differentiable to order n-1, up to floating point rounding error. )rrr/rrKrr{rrs r$rzNdPPoly.antiderivativeMsf4    tvvt7G7G H } /GD! % %a . /  r%c | |j}n t|}t|j}t ||z}|j }t t|j}|jd||||dz=|jd|||z|||zdz=|j|}tj|j|jd|jdd|j||}|j|||} |dk(r| j|jddS| j|jdd}|jd||j|dzdz} |j|| |S)a Compute NdPPoly representation for one dimensional definite integral The result is a piecewise polynomial representing the integral: .. math:: p(y, z, ...) = \int_a^b dx\, p(x, y, z, ...) where the dimension integrated over is specified with the `axis` parameter. Parameters ---------- a, 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 : NdPPoly or array-like Definite integral of the piecewise polynomial over [a, b]. If the polynomial was 1D, an array is returned, otherwise, an NdPPoly object. Nrrr:rKrW)rKrrrrbrrrreinsertrrrrr;r) r+r r rRrKrerswaprrrs r$ integrate_1dzNdPPoly.integrate_1dosu>  **K{+K466{4y4 FFE!&&M" AtDz" N AtD4K() q ! KK   1771:qwwqz2!F!%-8 ! :kk!QKk8 19;;qwwqr{+ + AGGABK(Au tAvw/A&&q!&E Er%c`t|j}| |j}n t|}t |drt||k7r t d|j |j}t|D]\}\}}tt|j}|jd|||z |||z dz=|j|}tj||j||} | j!|||} | j#|j$dd}|S)aq 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 : array_like Definite integral of the piecewise polynomial over [a[0], b[0]] x ... x [a[ndim-1], b[ndim-1]] N__len__z&Range not a sequence of correct lengthrrrW)rrrKrhasattrrBrrrrrrerrrrrrr;) r+rangesrKrerrSr r rrrs r$rzNdPPoly.integrates*466{  **K{+Kvy)S[D-@EF F !!# FF"6* )IAv1aff &D KK4q> *TAX\" D!A$$Qq {$KA++a +r r r r r scipy.specialspecialrscipy._lib._utilrrr_polyintrr _interpndr _bsplinesrrrr*rrIrNrrrrrr8r%r$rs K<<+%/2T v ,,4 H ) `*`*F ]]@LAJLA^jJjZnnr%