a
    a                    @   sz  g d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlm Z m!Z! dd Z"G dd dZ#dd Z$dd Z%G dd deZ&G dd dZ'G dd de'Z(G dd de'Z)G dd  d Z*G d!d" d"Z+d#d$ej,fd%d&Z-G d'd( d(e(Z.dS )))interp1dinterp2dlagrangePPolyBPolyNdPPolyRegularGridInterpolatorinterpn    N)	array	transposesearchsorted
atleast_1d
atleast_2dravelpoly1dasarrayintp)comb)prod   )fitpack)dfitpack)_fitpack)_Interpolator1D)_ppoly)RectBivariateSpline)_ndim_coords_from_arrays)make_interp_splineBSplinec                 C   sx   t | }td}t|D ]Z}t|| }t|D ]8}||kr>q0| | | |  }|td| |  g| 9 }q0||7 }q|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.

    Examples
    --------
    Interpolate :math:`f(x) = x^3` by 3 points.

    >>> from scipy.interpolate import lagrange
    >>> x = np.array([0, 1, 2])
    >>> y = x**3
    >>> poly = lagrange(x, y)

    Since there are only 3 points, 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
    array([ 3., -2.,  0.])

                  ?)lenr   range)xwMpjptkZfac r*   m/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/scipy/interpolate/interpolate.pyr      s    /
r   c                   @   s$   e Zd ZdZdddZdd	d
ZdS )r   a<  
    interp2d(x, y, z, kind='linear', copy=True, bounds_error=False,
             fill_value=None)

    Interpolate over a 2-D grid.

    `x`, `y` and `z` are arrays of values used to approximate some function
    f: ``z = f(x, y)`` which returns a scalar value `z`. This class returns a
    function whose call method uses spline interpolation to find the value
    of new points.

    If `x` and `y` represent a regular grid, consider using
    `RectBivariateSpline`.

    If `z` is a vector value, consider using `interpn`.

    Note that calling `interp2d` with NaNs present in input values results in
    undefined behaviour.

    Methods
    -------
    __call__

    Parameters
    ----------
    x, y : array_like
        Arrays defining the data point coordinates.

        If the points lie on a regular grid, `x` can specify the column
        coordinates and `y` the row coordinates, for example::

          >>> x = [0,1,2];  y = [0,3]; z = [[1,2,3], [4,5,6]]

        Otherwise, `x` and `y` must specify the full coordinates for each
        point, for example::

          >>> x = [0,1,2,0,1,2];  y = [0,0,0,3,3,3]; z = [1,2,3,4,5,6]

        If `x` and `y` are multidimensional, they are flattened before use.
    z : array_like
        The values of the function to interpolate at the data points. If
        `z` is a multidimensional array, it is flattened before use.  The
        length of a flattened `z` array is either
        len(`x`)*len(`y`) if `x` and `y` specify the column and row coordinates
        or ``len(z) == len(x) == len(y)`` if `x` and `y` specify coordinates
        for each point.
    kind : {'linear', 'cubic', 'quintic'}, optional
        The kind of spline interpolation to use. Default is 'linear'.
    copy : bool, optional
        If True, the class makes internal copies of x, y and z.
        If False, references may be used. The default is to copy.
    bounds_error : bool, optional
        If True, when interpolated values are requested outside of the
        domain of the input data (x,y), a ValueError is raised.
        If False, then `fill_value` is used.
    fill_value : number, optional
        If provided, the value to use for points outside of the
        interpolation domain. If omitted (None), values outside
        the domain are extrapolated via nearest-neighbor extrapolation.

    See Also
    --------
    RectBivariateSpline :
        Much faster 2-D interpolation if your input data is on a grid
    bisplrep, bisplev :
        Spline interpolation based on FITPACK
    BivariateSpline : a more recent wrapper of the FITPACK routines
    interp1d : 1-D version of this function

    Notes
    -----
    The minimum number of data points required along the interpolation
    axis is ``(k+1)**2``, with k=1 for linear, k=3 for cubic and k=5 for
    quintic interpolation.

    The interpolator is constructed by `bisplrep`, with a smoothing factor
    of 0. If more control over smoothing is needed, `bisplrep` should be
    used directly.

    Examples
    --------
    Construct a 2-D grid and interpolate on it:

    >>> from scipy import interpolate
    >>> x = np.arange(-5.01, 5.01, 0.25)
    >>> y = np.arange(-5.01, 5.01, 0.25)
    >>> xx, yy = np.meshgrid(x, y)
    >>> z = np.sin(xx**2+yy**2)
    >>> f = interpolate.interp2d(x, y, z, kind='cubic')

    Now use the obtained interpolation function and plot the result:

    >>> import matplotlib.pyplot as plt
    >>> xnew = np.arange(-5.01, 5.01, 1e-2)
    >>> ynew = np.arange(-5.01, 5.01, 1e-2)
    >>> znew = f(xnew, ynew)
    >>> plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
    >>> plt.show()
    linearTFNc                    s~  t |}t |}t|}|jt|t| k}|r|jdkrZ|jt|t|fkrZtdt|dd  |d d kst	|}	||	 }|d d |	f }t|dd  |d d kst	|}	||	 }||	d d f }t |j
}n<t |}t|t|krtdt|t|kr"tddddd	}
z|
|  }}W nN ty } z4td
t| ddtt|
 d|W Y d }~n
d }~0 0 |stj|||||dd| _nhtj|||d d d d ||dd
\}}}}}}}|d | |d | |d || d || d   ||f| _|| _|| _ fdd|||fD \| _| _| _t|t| | _| _t|t| | _| _d S )N   zdWhen on a regular grid with x.size = m and y.size = n, if z.ndim == 2, then z must have shape (n, m)r   z8x and y must have equal lengths for non rectangular gridz3Invalid length for input z for non rectangular grid      )r,   cubicZquinticzUnsupported interpolation type z, must be either of z, .r   )kxkysc                    s   g | ]}t | d qS )copy)r
   ).0ar6   r*   r+   
<listcomp>       z%interp2d.__init__.<locals>.<listcomp>)r   r   sizer!   ndimshape
ValueErrornpallargsortTKeyErrorreprjoinmapr   Zbisplreptckr   Zregrid_smthbounds_error
fill_valuer#   yzZaminZamaxx_minx_maxy_miny_max)selfr#   rK   rL   kindr7   rI   rJ   Zrectangular_gridr'   Zinterpolation_typesr3   r4   eZnxZtxnytycfpZierr*   r6   r+   __init__   sf    


2$zinterp2d.__init__r	   c                 C   sD  t |}t |}|jdks$|jdkr,td|sLtj|dd}tj|dd}| js\| jdur|| jk || jkB }|| j	k || j
kB }t|}t|}	| jr|s|	rtd| j| jf| j	| j
ff t||| j||}
t|
}
t|
}
| jdur&|r| j|
dd|f< |	r&| j|
|ddf< t|
dkr<|
d }
t|
S )a  Interpolate the function.

        Parameters
        ----------
        x : 1-D array
            x-coordinates of the mesh on which to interpolate.
        y : 1-D array
            y-coordinates of the mesh on which to interpolate.
        dx : int >= 0, < kx
            Order of partial derivatives in x.
        dy : int >= 0, < ky
            Order of partial derivatives in y.
        assume_sorted : bool, optional
            If False, values of `x` and `y` can be in any order and they are
            sorted first.
            If True, `x` and `y` have to be arrays of monotonically
            increasing values.

        Returns
        -------
        z : 2-D array with shape (len(y), len(x))
            The interpolated values.
        r   z!x and y should both be 1-D arrays	mergesortrR   Nz-Values out of range; x must be in %r, y in %rr	   )r   r=   r?   r@   sortrI   rJ   rM   rN   rO   rP   anyr   ZbisplevrH   r   r   r!   r
   )rQ   r#   rK   dxZdyassume_sortedZout_of_bounds_xZout_of_bounds_yZany_out_of_bounds_xZany_out_of_bounds_yrL   r*   r*   r+   __call__   s:    



zinterp2d.__call__)r,   TFN)r	   r	   F)__name__
__module____qualname____doc__rX   r_   r*   r*   r*   r+   r   Y   s
   d  
9r   c                 C   s   | j }t|t|krt|ddd |ddd D ]\}}|dkr4||kr4 qq4| jdkrx| j |krxt|| j|  } |  S td|||f dS )z7Helper to check that arr_from broadcasts up to shape_toNr.   r   zE%s argument must be able to broadcast up to shape %s but had shape %s)	r>   r!   zipr<   r@   Zonesdtyper   r?   )Zarr_fromZshape_tonameZ
shape_fromtfr*   r*   r+   _check_broadcast_up_to5  s    &ri   c                 C   s   t | to| dkS )z?Helper to check if fill_value == "extrapolate" without warningsextrapolate)
isinstancestr)rJ   r*   r*   r+   _do_extrapolateF  s    
rm   c                   @   s   e Zd ZdZddddejdfddZed	d
 Zej	dd
 Zdd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r   a  
    Interpolate a 1-D function.

    `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 : (N,) array_like
        A 1-D array of real values.
    y : (...,N,...) 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`.
    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
        Specifies the axis of `y` along which to interpolate.
        Interpolation defaults to the last axis of `y`.
    copy : bool, optional
        If True, the class makes internal copies of x and y.
        If False, references to `x` and `y` are used. 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``.

          .. 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 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()
    r,   r.   TNFc	                 C   sx  t j| |||d || _|| _|dv r>ddddd| }	d}n(t|trR|}	d}n|dvrftd	| t|| jd
}t|| jd
}|stj	|dd}
||
 }tj
||
|d}|jdkrtd|jdkrtdt|jjtjs|tj}||j | _|| _| | j| _|| _~~|| _|| _|dv rd}|dkrxd| _| jd | _| jdd | jdd  | _| jj| _qX|dkrd| _| jd | _| jdd | jdd  | _| jj| _n|dkrd| _d| _t | jtj! | _"| jj#| _n|dkr(d| _d| _t | jtj!| _"| jj#| _n\| jjtjkoD| jjtjk}|oV| jjdk}|oft$| }|rz| jj%| _n
| jj&| _n|	d }d}| j| j }}|	dkr*t'| j}|( r| j|  }|j)dkrtdt*t+| jt,| jt-| j}d}t'| j( r*t.| j}d}t/|||	dd| _0|rN| jj1| _n
| jj2| _t-| j|k rttd| dS )z- Initialize a 1-D linear interpolation class.axis)ZzeroZslinearZ	quadraticr1   r	   r   r-   r/   Zspline)r,   nearest
nearest-uppreviousnextz8%s is unsupported: Use fitpack routines for other types.r6   rY   rZ   z,the x array must have exactly one dimension.z-the y array must have at least one dimension.rp   leftg       @Nr.   rq   rightrr   rs   Fz`x` array is all-nanT)r)   Zcheck_finitez,x and y arrays must have at least %d entries)3r   rX   rI   r7   rk   intNotImplementedErrorr
   r@   rB   Ztaker=   r?   
issubclassre   typeinexactastypefloat_ro   rK   Z_reshape_yi_yr#   _kindrJ   _sidex_bds	__class___call_nearest_call_ind	nextafterinf_x_shift_call_previousnextrm   _call_linear_np_call_linearisnanr\   r<   ZlinspaceZnanminZnanmaxr!   Z	ones_liker   _spline_call_nan_spline_call_spline)rQ   r#   rK   rR   ro   r7   rI   rJ   r^   orderindminvalZcondZrewrite_nanxxyymaskZsxr*   r*   r+   rX     s    











zinterp1d.__init__c                 C   s   | j S )zThe fill value.)_fill_value_origrQ   r*   r*   r+   rJ   4  s    zinterp1d.fill_valuec                 C   s  t |r$| jrtdd| _d| _n| jjd | j | jj| jd d   }t|dkr\d}t|t	rt|dkrt
|d t
|d g}d}tdD ]}t|| ||| ||< qnt
|}t||d	gd }|\| _| _d| _| jd u rd| _|| _d S )
Nz.Cannot extrapolate and raise at the same time.FTr   r	   r   r-   )zfill_value (below)zfill_value (above)rJ   )rm   rI   r?   _extrapolaterK   r>   ro   r!   rk   tupler@   r   r"   ri   _fill_value_below_fill_value_abover   )rQ   rJ   Zbroadcast_shapeZbelow_abovenamesiir*   r*   r+   rJ   :  s<    

c                 C   s   t || j| jS N)r@   interpr#   rK   rQ   x_newr*   r*   r+   r   \  s    zinterp1d._call_linear_npc                 C   s   t | j|}|dt| jd t}|d }|}| j| }| j| }| j| }| j| }|| || d d d f  }	|	|| d d d f  | }
|
S )Nr   )r   r#   clipr!   r{   rv   r}   )rQ   r   x_new_indiceslohiZx_loZx_hiZy_loZy_hiZslopey_newr*   r*   r+   r   `  s    



zinterp1d._call_linearc                 C   s<   t | j|| jd}|dt| jd t}| j| }|S )z5 Find nearest neighbor interpolated y_new = f(x_new).Zsider	   r   )	r   r   r   r   r!   r#   r{   r   r}   rQ   r   r   r   r*   r*   r+   r   }  s    
zinterp1d._call_nearestc                 C   sN   t | j|| jd}|d| j t| j| j t}| j	|| j d  }|S )z6Use previous/next neighbor of x_new, y_new = f(x_new).r   r   )
r   r   r   r   r   r!   r#   r{   r   r}   r   r*   r*   r+   r     s    zinterp1d._call_previousnextc                 C   s
   |  |S r   )r   r   r*   r*   r+   r     s    zinterp1d._call_splinec                 C   s   |  |}tj|d< |S )N.)r   r@   nan)rQ   r   outr*   r*   r+   r     s    

zinterp1d._call_nan_splinec                 C   sL   t |}| | |}| jsH| |\}}t|dkrH| j||< | j||< |S Nr	   )r   r   r   _check_boundsr!   r   r   )rQ   r   r   below_boundsabove_boundsr*   r*   r+   	_evaluate  s    

zinterp1d._evaluatec                 C   sP   || j d k }|| j d k}| jr2| r2td| jrH| rHtd||fS )a  Check 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.
        r	   r.   z2A value in x_new is below the interpolation range.z2A value in x_new is above the interpolation range.)r#   rI   r\   r?   )rQ   r   r   r   r*   r*   r+   r     s    zinterp1d._check_bounds)r`   ra   rb   rc   r@   r   rX   propertyrJ   setterr   r   r   r   r   r   r   r   r*   r*   r*   r+   r   L  s$   c
 

!r   c                   @   sP   e Zd ZdZdZdddZdd Zedd	d
Zdd Z	dddZ
dddZdS )
_PPolyBasez%Base class for piecewise polynomials.)rV   r#   rj   ro   Nr	   c                 C   s  t || _t j|t jd| _|d u r,d}n|dkr<t|}|| _| jjdk rVt	dd|  krr| jjd k sn t	d|| jjd f || _
|dkrt | j|d | _t | j|d | _| jjdkrt	d	| jjdk rt	d
| jjdk rt	d| jjd dkrt	d| jjd | jjd kr:t	dt | j}t |dksnt |dksnt	d| | jj}t j| j|d| _d S )Nre   Tperiodicr-   z2Coefficients array must be at least 2-dimensional.r	   r   z axis=%s must be between 0 and %szx 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   rV   ascontiguousarrayfloat64r#   boolrj   r=   r?   ro   Zrollaxisr<   r>   diffrA   
_get_dtypere   )rQ   rV   r#   rj   ro   r]   re   r*   r*   r+   rX     s@     z_PPolyBase.__init__c                 C   s0   t |t js t | jjt jr&t jS t jS d S r   r@   
issubdtypecomplexfloatingrV   re   complex_r|   rQ   re   r*   r*   r+   r     s
    z_PPolyBase._get_dtypec                 C   s2   t | }||_||_||_|du r(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.
        NT)object__new__rV   r#   ro   rj   )clsrV   r#   rj   ro   rQ   r*   r*   r+   construct_fast  s    

z_PPolyBase.construct_fastc                 C   s0   | j jjs| j  | _ | jjjs,| j | _dS )zr
        c and x may be modified by the user. The Cython code expects
        that they are C contiguous.
        N)r#   flagsc_contiguousr7   rV   r   r*   r*   r+   _ensure_c_contiguous   s    

z_PPolyBase._ensure_c_contiguousc           	      C   s  |durt d t|}t|}|jdk r8td|jdkrJtd|jd |jd krrtd|j|j|jdd | jjdd ks|j| jjkrtd	|j| jj|j	dkrdS t
|}t|dkst|dkstd
| jd | jd kr^|d |d ks td|d | jd kr:d}n"|d | jd krTd}ntdnV|d |d ksxtd|d | jd krd}n"|d | jd krd}ntd| |j}t|jd | jjd }tj|| jjd |jd  f| jjdd  |d}|dkrz| j||| jjd  dd| jjd f< ||||jd  d| jjd df< tj| j|f | _nh|dkr|||| jjd  dd|jd f< | j|||jd  d|jd df< tj|| jf | _|| _dS )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.
        right
            Deprecated argument. Has no effect.

            .. deprecated:: 0.19
        Nz*`right` is deprecated and will be removed.r-   zinvalid dimensions for cr   zinvalid dimensions for xr	   z(Shapes of x {} and c {} are incompatiblez-Shapes of c {} and self.c {} are incompatiblez`x` is not sorted.r.   z,`x` is in the different order than `self.x`.appendprependz9`x` is neither on the left or on the right from `self.x`.r   )warningswarnr@   r   r=   r?   r>   formatrV   r<   r   rA   r#   r   re   maxzerosZr_)	rQ   rV   r#   ru   r]   actionre   Zk2c2r*   r*   r+   extend*  sd    




,



,
*&
&&z_PPolyBase.extendc                 C   s&  |du r| j }t|}|j|j }}tj| tjd}|dkrr| jd || jd  | jd | jd    }d}tj	t
|t| jjdd f| jjd}|   | |||| ||| jjdd  }| jdkr"tt|j}|||| j  |d|  ||| j d  }||}|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]``.
        Nr   r   r	   r.   Fr-   )rj   r@   r   r>   r=   r   r   r|   r#   emptyr!   r   rV   re   r   r   reshapero   listr"   r   )rQ   r#   nurj   x_shapeZx_ndimr   lr*   r*   r+   r_     s"    
,*0
z_PPolyBase.__call__)Nr	   )Nr	   )N)r	   N)r`   ra   rb   rc   	__slots__rX   r   classmethodr   r   r   r_   r*   r*   r*   r+   r     s   
.

Ur   c                   @   sf   e Zd ZdZdd ZdddZdddZdd
dZdddZdddZ	e
dddZe
dddZd	S )r   aL  
    Piecewise polynomial in terms of coefficients and breakpoints

    The polynomial between ``x[i]`` and ``x[i + 1]`` is written in the
    local power basis::

        S = sum(c[m, i] * (xp - x[i])**(k-m) for m in range(k+1))

    where ``k`` is the degree of the polynomial.

    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 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.
    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__
    derivative
    antiderivative
    integrate
    solve
    roots
    extend
    from_spline
    from_bernstein_basis
    construct_fast

    See also
    --------
    BPoly : piecewise polynomials in the Bernstein basis

    Notes
    -----
    High-order polynomials in the power basis can be numerically
    unstable. Precision problems can start to appear for orders
    larger than 20-30.
    c                 C   s:   t | j| jjd | jjd d| j||t|| d S Nr	   r   r.   )r   evaluaterV   r   r>   r#   r   rQ   r#   r   rj   r   r*   r*   r+   r     s    "zPPoly._evaluater   c                 C   s   |dk r|  | S |dkr(| j }n| jd| ddf  }|jd dkrptjd|jdd  |jd}tt	|jd dd|}||t
dfd|jd    9 }| || j| j| jS )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
        -------
        pp : PPoly
            Piecewise polynomial of order k2 = k - 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 are considered half-open,
        ``[a, b)``, except for the last interval which is closed
        ``[a, b]``.
        r	   Nr   r   r   r.   r   )antiderivativerV   r7   r>   r@   r   re   specpocharangeslicer=   r   r#   rj   ro   )rQ   r   r   factorr*   r*   r+   
derivative  s     zPPoly.derivativec                 C   s  |dkr|  | S tj| jjd | | jjd f| jjdd  | jjd}| j|d| < tt| jjd dd|}|d|   |t	dfd|j
d      < |   t||jd |jd d| j|d  | jdkrd	}n| 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.
        r	   r   r-   Nr   r.   r   r   F)r   r@   r   rV   r>   re   r   r   r   r   r=   r   r   fix_continuityr   r#   rj   r   ro   )rQ   r   rV   r   rj   r*   r*   r+   r      s     ..

zPPoly.antiderivativeNc                 C   s(  |du r| j }d}||k r(|| }}d}tjt| jjdd f| jjd}|   |dkr| jd | jd  }}|| }|| }	t	|	|\}
}|
dkrt
j| j| jjd | jjd d| j||d|d	 ||
9 }n
|d ||| |  }|| }t|}||krLt
j| j| jjd | jjd d| j||d|d	 ||7 }nt
j| j| jjd | jjd d| j||d|d	 ||7 }t
j| j| jjd | jjd d| j||| | | d|d	 ||7 }n8t
j| j| jjd | jjd d| j||t||d	 ||9 }|| jjdd S )
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]
        Nr   r.   r-   r   r   r	   F)r   )rj   r@   r   r   rV   r>   re   r   r#   divmodr   	integrater   fill
empty_liker   )rQ   r9   brj   signZ	range_intxsxeperiodinterval	n_periodsrt   Zremainder_intr*   r*   r+   r   V  sZ    
$






zPPoly.integrater   Tc                 C   s   |du r| j }|   t| jjtjr0tdt|}t	
| j| jjd | jjd d| j|t|t|}| jjdkr|d S tjt| jjdd td}t|D ]\}}|||< q|| jjdd S dS )a  
        Find real solutions of the 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]``:

        >>> 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 polynomialsr	   r   r.   r-   r   )rj   r   r@   r   rV   re   r   r?   floatr   Z
real_rootsr   r>   r#   r   r=   r   r   r   	enumerate)rQ   rK   discontinuityrj   rZr2r   rootr*   r*   r+   solve  s     0"
zPPoly.solvec                 C   s   |  d||S )a_  
        Find real roots of the 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   )rQ   r   rj   r*   r*   r+   roots  s    zPPoly.rootsc           	      C   s   t |tr&|j\}}}|du r0|j}n
|\}}}tj|d t|d f|jd}t|ddD ]>}t	j
|dd ||d}|t|d  ||| ddf< q\| |||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.
        Nr   r   r.   )Zder)rk   r   rH   rj   r@   r   r!   re   r"   r   Zsplevr   gammar   )	r   rH   rj   rg   rV   r)   cvalsmrK   r*   r*   r+   from_spline  s    

 $zPPoly.from_splinec              	   C   s   t |tstdt| t|j}|jjd d }d|jj	d  }t
|j}t|d D ]|}d| t|| |j|  }t||d D ]L}	t|| |	| d|	  }
|||	   ||
 |tdf|  |	  7  < qq^|du r|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.
        zC.from_bernstein_basis only accepts BPoly instances. Got %s instead.r	   r   r   r-   r.   N)rk   r   	TypeErrorry   r@   r   r#   rV   r>   r=   
zeros_liker"   r   r   rj   r   ro   )r   bprj   r]   r)   restrV   r9   r   r5   valr*   r*   r+   from_bernstein_basis)  s     
2zPPoly.from_bernstein_basis)r   )r   )N)r   TN)TN)N)N)r`   ra   rb   rc   r   r   r   r   r   r   r   r   r   r*   r*   r*   r+   r     s   :
,
6
R
H
r   c                   @   s~   e Zd ZdZdd ZdddZdddZdd
dZdddZe	jje_e
dddZe
dddZedd Zedd Zd	S )r   ay	  Piecewise polynomial in terms of coefficients and breakpoints.

    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                 C   s:   t | j| jjd | jjd d| j||t|| d S r   )r   Zevaluate_bernsteinrV   r   r>   r#   r   r   r*   r*   r+   r     s    zBPoly._evaluater   c                 C   s   |dk r|  | S |dkr:| }t|D ]}| }q(|S |dkrN| j }nTd| jjd  }| jjd d }t| j	dt
df|  }|tj| jdd | }|jd dkrtjd|jdd  |jd}| || j	| j| jS )	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.

        r	   r   r   r-   Nrn   r   r   )r   r"   r   rV   r7   r=   r>   r@   r   r#   r   r   re   r   rj   ro   )rQ   r   r   r)   r   r   r]   r*   r*   r+   r     s     
zBPoly.derivativec           	      C   s4  |dkr|  | S |dkr:| }t|D ]}| }q(|S | j| j }}|jd }tj|d f|jdd  |jd}tj	|dd| |dddf< |dd |dd  }||dt
dfd|jd	    9 }|ddddf  tj	||ddf dddd 7  < | jd
krd}n| j}| j|||| jdS )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.
        r	   r   Nr   rn   .r.   r   r-   r   F)r   r"   r   rV   r#   r>   r@   r   re   Zcumsumr   r=   rj   r   ro   )	rQ   r   r   r)   rV   r#   r   deltarj   r*   r*   r+   r     s$    

$":zBPoly.antiderivativeNc                 C   s  |   }|du r| j}|dkr$||_|dkr ||kr<d}n|| }}d}| jd | jd  }}|| }|| }	t|	|\}
}|
||||  }||| |  }|| }||kr||||| 7 }n0||||| ||| | |  || 7 }|| S |||| S d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]

        Nr   r   r.   r	   )r   rj   r#   r   )rQ   r9   r   rj   ibr   r   r   r   r   r   rt   resr*   r*   r+   r     s,    

0zBPoly.integratec                 C   sZ   t | jjd |jd }| | j|| jjd  | _| |||jd  }t| |||S r   )r   rV   r>   _raise_degreer   r   )rQ   rV   r#   ru   r)   r*   r*   r+   r   V  s    zBPoly.extendc           
   
   C   s   t |tstdt| t|j}|jjd d }d|jj	d  }t
|j}t|d D ]l}|j| t|||  |tdf|  ||   }t|| |d D ]"}	||	  |t|	||  7  < qq^|du r|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.
        z?.from_power_basis only accepts PPoly instances. Got %s instead.r	   r   r   r-   N)rk   r   r   ry   r@   r   r#   rV   r>   r=   r   r"   r   r   rj   r   ro   )
r   pprj   r]   r)   r   rV   r9   r   r'   r*   r*   r+   from_power_basis]  s    
2"zBPoly.from_power_basisc              
      sf  t |}t|t kr"tdt |dd |dd  dkrLtdt|d }zt fddt|D }W n. ty } ztd|W Y d}~n
d}~0 0 |du rdg| }nBt|t	t j
fr|g| }t|t|}td	d |D rtd
g }t|D ]<}	 |	  |	d   }
}||	 du rFt|
t| }}n||	 d }t|d t|
}t|| t|}t|| t|}|| |krd||	 t|
||	d  t|||	 f }t||t|
kr|t|kstdt||	 ||	d  |
d| |d| }t||k r:t||t| }|| qt |}| |dd||S )a4
  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 lengthr   Nr	   z)x coordinates are not in increasing orderc                 3   s*   | ]"}t  | t  |d    V  qdS r   N)r!   r8   iyir*   r+   	<genexpr>  r;   z)BPoly.from_derivatives.<locals>.<genexpr>z0Using a 1-D array for y? Please .reshape(-1, 1).c                 s   s   | ]}|d kV  qdS )r	   Nr*   )r8   or*   r*   r+   r
    r;   zOrders must be positive.r-   zPPoint %g has %d derivatives, point %g has %d derivatives, but order %d requestedz0`order` input incompatible with length y1 or y2.)r@   r   r!   r?   r\   r   r"   r   rk   rv   integerminr   _construct_from_derivativesr  r   Zswapaxes)r   xir	  Zordersrj   r   r)   rS   rV   r  y1y2Zn1Zn2nZmesgr   r*   r  r+   from_derivatives  s\    @
"
"
zBPoly.from_derivativesc              
   C   s  t |t | }}|jdd |jdd krFtd|j|j|j|j }}t |t jspt |t jrxt j}nt j	}t
|t
| }}|| }	t j|| f|jdd  |d}
td|D ]h}|| t|	| | ||  |  |
|< td|D ]0}|
|  d||  t|| |
|  8  <  qqtd|D ]}|| t|	| | d|  ||  |  |
| d < td|D ]@}|
| d   d|d  t||d  |
| |   8  < q|q8|
S )aG  Compute 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``.

        r   Nz*Shapes of ya {} and yb {} are incompatibler   r	   r.   )r@   r   r>   r?   r   re   r   r   r   r|   r!   r   r"   r   r   r   )ZxaxbZyaZybZdtaZdtbdtnanbr  rV   qr'   r*   r*   r+   r    s.    7"(06Bz!BPoly._construct_from_derivativesc              
   C   s   |dkr| S | j d d }tj| j d | f| j dd  | jd}t| j d D ]X}| | t|| }t|d D ]4}|||   |t|| t|| ||  7  < qtqR|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)

        r	   r   Nr   )r>   r@   r   re   r"   r   )rV   dr)   r   r9   rh   r'   r*   r*   r+   r  O  s    *4zBPoly._raise_degree)r   )r   )N)N)N)NN)r`   ra   rb   rc   r   r   r   r   r   r   r   r  r  staticmethodr  r  r*   r*   r*   r+   r   N  s   U
5
8
@

"w
Vr   c                   @   sv   e Zd ZdZdddZedddZdd Zd	d
 ZdddZ	dd Z
dd Zdd Zdd ZdddZdddZdS )r   aW  
    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                 C   s   t dd |D | _t|| _|d u r,d}t|| _t| j}tdd | jD r\t	dtdd | jD rxt	d|j
d| k rt	d	td
d | jD rt	dtdd t|j|d|  | jD rt	d| | jj}tj| j|d| _d S )Nc                 s   s   | ]}t j|t jd V  qdS )r   N)r@   r   r   r8   vr*   r*   r+   r
    r;   z#NdPPoly.__init__.<locals>.<genexpr>Tc                 s   s   | ]}|j d kV  qdS r  r=   r  r*   r*   r+   r
    r;   z"x arrays must all be 1-dimensionalc                 s   s   | ]}|j d k V  qdS )r-   Nr<   r  r*   r*   r+   r
    r;   z+x arrays must all contain at least 2 pointsr-   z(c must have at least 2*len(x) dimensionsc                 s   s0   | ](}t |d d |dd  dk V  qdS )r   Nr.   r	   )r@   r\   r  r*   r*   r+   r
    r;   z)x-coordinates are not in increasing orderc                 s   s    | ]\}}||j d  kV  qdS r  r  )r8   r9   r   r*   r*   r+   r
    r;   z/x and c do not agree on the number of intervalsr   )r   r#   r@   r   rV   r   rj   r!   r\   r?   r=   rd   r>   r   re   r   )rQ   rV   r#   rj   r=   re   r*   r*   r+   rX     s$    

(zNdPPoly.__init__c                 C   s,   t | }||_||_|du r"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.

        NT)r   r   rV   r#   rj   )r   rV   r#   rj   rQ   r*   r*   r+   r     s    
zNdPPoly.construct_fastc                 C   s0   t |t js t | jjt jr&t jS t jS d S r   r   r   r*   r*   r+   r     s
    zNdPPoly._get_dtypec                 C   s2   | j jjs| j  | _ t| jts.t| j| _d S r   )rV   r   r   r7   rk   r#   r   r   r*   r*   r+   r     s    
zNdPPoly._ensure_c_contiguousc              	   C   sl  |du r| j }nt|}t| j}t|}|j}tj|d|jd tj	d}|du rjtj
|ftjd}n0tj|tjd}|jdks|jd |krtdt| jjd| }t| jj|d|  }t| jjd| d }tj| jjd| tjd}	tj|jd |f| jjd}
|   t| j|||| j|	||t||
 |
|dd | jjd| d  S )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.   r   r   r	   z&invalid number of derivative orders nur-   )rj   r   r!   r#   r   r>   r@   r   r   r|   r   Zintcr   r=   r?   r   rV   r
   r   re   r   r   Zevaluate_nd)rQ   r#   r   rj   r=   r   Zdim1Zdim2Zdim3ksr   r*   r*   r+   r_     s6    
zNdPPoly.__call__c                 C   s   |dk r|  | |S t| j}|| }|dkr4dS tdg| }td| d||< | jt| }|j| dkrt|j}d||< tj	||j
d}tt|j| dd|}dg|j }td||< ||t| 9 }|| _dS )zz
        Compute 1-D derivative along a selected dimension in-place
        May result to non-contiguous c array.
        r	   Nr   r   r.   )_antiderivative_inplacer!   r#   r   rV   r   r>   r   r@   r   re   r   r   r   r=   )rQ   r   ro   r=   slr   Zshpr   r*   r*   r+   _derivative_inplace.  s$    

zNdPPoly._derivative_inplacec           	      C   s  |dkr|  | |S t| j}|| }tt|}|| |d  |d< ||< |tt|| jj }| j|}tj	|j
d | f|j
dd  |jd}||d| < tt|j
d dd|}|d|   |tdfd|jd      < tt|j}|||  |d  |d< ||| < ||}| }t||j
d |j
d d| j| |d  ||}||}|| _dS )zu
        Compute 1-D antiderivative along a selected dimension
        May result to non-contiguous c array.
        r	   r   Nr   r.   r   )r"  r!   r#   r   r"   rV   r=   r   r@   r   r>   re   r   r   r   r   r7   r   r   r   )	rQ   r   ro   r=   permrV   r   r   Zperm2r*   r*   r+   r   P  s0    
 ."


zNdPPoly._antiderivative_inplacec                 C   sB   |  | j | j| j}t|D ]\}}||| q |  |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]``.

        )r   rV   r7   r#   rj   r   r"  r   rQ   r   r&   ro   r  r*   r*   r+   r   x  s
    zNdPPoly.derivativec                 C   sB   |  | j | j| j}t|D ]\}}||| q |  |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.

        )r   rV   r7   r#   rj   r   r   r   r$  r*   r*   r+   r     s
    zNdPPoly.antiderivativec                 C   s(  |du r| j }nt|}t| j}t|| }| j}tt|j}|	d||  ||d = |	d|||   ||| d = |
|}tj||jd |jd d| j| |d}|j|||d}	|dkr|	|jdd S |	|jdd }| jd| | j|d d  }
| j||
|dS d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.

        Nr	   r   r.   rj   r-   )rj   r   r!   r#   rv   rV   r   r"   r=   insertr   r   r   r   r>   r   )rQ   r9   r   ro   rj   r=   rV   swapr&   r   r#   r*   r*   r+   integrate_1d  s,    


 zNdPPoly.integrate_1dc                 C   s   t | j}|du r| j}nt|}t|dr8t ||kr@td|   | j}t|D ]\}\}}t	t
|j}|d|||   ||| d = ||}tj|| j| |d}	|	j|||d}
|
|jdd }qV|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 lengthr   r%  r-   )r!   r#   rj   r   hasattrr?   r   rV   r   r   r"   r=   r&  r   r   r   r   r   r>   )rQ   rangesrj   r=   rV   r  r9   r   r'  r&   r   r*   r*   r+   r     s"    

zNdPPoly.integrate)N)N)NN)N)N)r`   ra   rb   rc   rX   r   r   r   r   r_   r"  r   r   r   r(  r   r*   r*   r*   r+   r   x  s   >

A"(!"
=r   c                   @   sD   e Zd ZdZddejfddZdddZd	d
 Zdd Z	dd Z
dS )r   a  
    Interpolation on a regular grid in arbitrary dimensions

    The data must be defined on a regular grid; the grid spacing however may be
    uneven. Linear and nearest-neighbor interpolation are supported. After
    setting up the interpolator object, the interpolation method (*linear* or
    *nearest*) may be chosen at each evaluation.

    Parameters
    ----------
    points : tuple of ndarray of float, with shapes (m1, ), ..., (mn, )
        The points defining the regular grid in n dimensions.

    values : array_like, shape (m1, ..., mn, ...)
        The data on the regular grid in n dimensions.

    method : str, optional
        The method of interpolation to perform. Supported are "linear" and
        "nearest". This parameter will become the default for the object's
        ``__call__`` method. Default is "linear".

    bounds_error : bool, optional
        If True, when interpolated values are requested outside of the
        domain of the input data, a ValueError is raised.
        If False, then `fill_value` is used.

    fill_value : number, optional
        If provided, the value to use for points outside of the
        interpolation domain. If None, values outside
        the domain are extrapolated.

    Methods
    -------
    __call__

    Notes
    -----
    Contrary to LinearNDInterpolator and NearestNDInterpolator, this class
    avoids expensive triangulation of the input data by taking advantage of the
    regular grid structure.

    If any of `points` have a dimension of size 1, linear interpolation will
    return an array of `nan` values. Nearest-neighbor interpolation will work
    as usual in this case.

    .. versionadded:: 0.14

    Examples
    --------
    Evaluate a simple example function on the points of a 3-D grid:

    >>> from scipy.interpolate import RegularGridInterpolator
    >>> def f(x, y, z):
    ...     return 2 * x**3 + 3 * y**2 - z
    >>> x = np.linspace(1, 4, 11)
    >>> y = np.linspace(4, 7, 22)
    >>> z = np.linspace(7, 9, 33)
    >>> xg, yg ,zg = np.meshgrid(x, y, z, indexing='ij', sparse=True)
    >>> data = f(xg, yg, zg)

    ``data`` is now a 3-D array with ``data[i,j,k] = f(x[i], y[j], z[k])``.
    Next, define an interpolating function from this data:

    >>> my_interpolating_function = RegularGridInterpolator((x, y, z), data)

    Evaluate the interpolating function at the two points
    ``(x,y,z) = (2.1, 6.2, 8.3)`` and ``(3.3, 5.2, 7.1)``:

    >>> pts = np.array([[2.1, 6.2, 8.3], [3.3, 5.2, 7.1]])
    >>> my_interpolating_function(pts)
    array([ 125.80469388,  146.30069388])

    which is indeed a close approximation to
    ``[f(2.1, 6.2, 8.3), f(3.3, 5.2, 7.1)]``.

    See also
    --------
    NearestNDInterpolator : Nearest neighbor interpolation on unstructured
                            data in N dimensions

    LinearNDInterpolator : Piecewise linear interpolant on unstructured data
                           in N dimensions

    References
    ----------
    .. [1] Python package *regulargrid* by Johannes Buchner, see
           https://pypi.python.org/pypi/regulargrid/
    .. [2] Wikipedia, "Trilinear interpolation",
           https://en.wikipedia.org/wiki/Trilinear_interpolation
    .. [3] Weiser, Alan, and Sergio E. Zarantonello. "A note on piecewise linear
           and multilinear table interpolation in many dimensions." MATH.
           COMPUT. 50.181 (1988): 189-196.
           https://www.ams.org/journals/mcom/1988-50-181/S0025-5718-1988-0917826-0/S0025-5718-1988-0917826-0.pdf

    r,   Tc           	      C   s`  |dvrt d| || _|| _t|ds4t|}t||jkrXt dt||jf t|drt|drt|j	tj
s|t}|| _|d urt|j	}t|drtj||j	ddst d	t|D ]t\}}tt|d
kst d| t|jdkst d| |j| t|kst dt||j| |f qtdd |D | _|| _d S )Nr,   rp   Method '%s' is not definedr=   7There are %d point arrays, but values has %d dimensionsre   r{   Z	same_kind)ZcastingzDfill_value must be either 'None' or of a type compatible with valuesr   5The points in dimension %d must be strictly ascendingr   0The points in dimension %d must be 1-dimensional1There are %d points and %d values in dimension %dc                 S   s   g | ]}t |qS r*   r@   r   r8   r&   r*   r*   r+   r:   	  r;   z4RegularGridInterpolator.__init__.<locals>.<listcomp>)r?   methodrI   r*  r@   r   r!   r=   r   re   rz   r{   r   rJ   Zcan_castr   rA   r   r>   r   gridvalues)	rQ   pointsr6  r4  rI   rJ   Zfill_value_dtyper  r&   r*   r*   r+   rX   	  sJ    




z RegularGridInterpolator.__init__Nc              	   C   sZ  |du r| j n|}|dvr&td| t| j}t||d}|jd t| jkrftd|jd |f |j}|d|d }| jrt|j	D ]H\}}t
t
| j| d |kt
|| j| d kstd	| q| |j	\}}}	|d
kr| |||	}
n|dkr| |||	}
| js8| jdur8| j|
|	< |
|dd | jj|d  S )a6  
        Interpolation at coordinates

        Parameters
        ----------
        xi : ndarray of shape (..., ndim)
            The coordinates to sample the gridded data at

        method : str
            The method of interpolation to perform. Supported are "linear" and
            "nearest".

        Nr,  r-  r  r.   cThe requested sample points xi have dimension %d, but this RegularGridInterpolator has dimension %dr   r	   8One of the requested xi is out of bounds in dimension %dr,   rp   )r4  r?   r!   r5  r   r>   r   rI   r   rC   r@   logical_andrA   _find_indices_evaluate_linear_evaluate_nearestrJ   r6  )rQ   r  r4  r=   xi_shaper  r&   indicesnorm_distancesout_of_boundsresultr*   r*   r+   r_   	  sB    



z RegularGridInterpolator.__call__c                 C   s   t d fd| jjt|   }tjdd |D  }d}|D ]V}d}t|||D ]$\}	}
}|t|	|
kd| |9 }qN|t	| j| ||  7 }q:|S )Nr   c                 S   s   g | ]}||d  gqS r   r*   r  r*   r*   r+   r:   	  r;   z<RegularGridInterpolator._evaluate_linear.<locals>.<listcomp>r   r    r   )
r   r6  r=   r!   	itertoolsproductrd   r@   wherer   )rQ   r?  r@  rA  Zvsliceedgesr6  Zedge_indicesZweighteir  r	  r*   r*   r+   r<  	  s    z(RegularGridInterpolator._evaluate_linearc                 C   s"   dd t ||D }| jt| S )Nc                 S   s&   g | ]\}}t |d k||d qS )g      ?r   )r@   rE  )r8   r  r	  r*   r*   r+   r:   	  s   z=RegularGridInterpolator._evaluate_nearest.<locals>.<listcomp>)rd   r6  r   )rQ   r?  r@  rA  Zidx_resr*   r*   r+   r=  	  s    z)RegularGridInterpolator._evaluate_nearestc                 C   s   g }g }t j|jd td}t|| jD ]\}}t ||d }d||dk < |jd |||jd k< || ||||  ||d  ||    | j	s(|||d k 7 }|||d k7 }q(|||fS )Nr   r   r	   r-   r.   )
r@   r   r>   r   rd   r5  r   r<   r   rI   )rQ   r  r?  r@  rA  r#   r5  r  r*   r*   r+   r;  	  s    
z%RegularGridInterpolator._find_indices)N)r`   ra   rb   rc   r@   r   rX   r_   r<  r=  r;  r*   r*   r*   r+   r   )	  s   b
)
1r   r,   Tc              	   C   s  |dvrt d| t|ds(t|}|j}|dkrF|dkrFt d|sb|du rb|dkrbt dt| |krt d	t| |f t| |kr|dkrt d
t| D ]r\}}tt|dkst d| t|jdkst d| |j	| t|kst dt||j	| |f qt
dd | D }	t|t|	d}|j	d t|	krjt d|j	d t|	f |rt|jD ]H\}}tt|	| d |kt||	| d kszt d| qz|dkrt| |d||d}
|
|S |dkrt| |d||d}
|
|S |dkr|j	}|d|j	d }tj|	d d |dddf k|dddf |	d d k|	d d |dddf k|dddf |	d d kfdd}t|dddf }t| d | d |dd }
|
||df ||df ||< ||t|< ||dd S dS )a,	  
    Multidimensional interpolation on regular grids.

    Parameters
    ----------
    points : tuple of ndarray of float, with shapes (m1, ), ..., (mn, )
        The points defining the regular grid in n dimensions.

    values : array_like, shape (m1, ..., mn, ...)
        The data on the regular grid in n dimensions.

    xi : ndarray of shape (..., ndim)
        The coordinates to sample the gridded data at

    method : str, optional
        The method of interpolation to perform. Supported are "linear" and
        "nearest", and "splinef2d". "splinef2d" is only supported for
        2-dimensional data.

    bounds_error : bool, optional
        If True, when interpolated values are requested outside of the
        domain of the input data, a ValueError is raised.
        If False, then `fill_value` is used.

    fill_value : number, optional
        If provided, the value to use for points outside of the
        interpolation domain. If None, values outside
        the domain are extrapolated.  Extrapolation is not supported by method
        "splinef2d".

    Returns
    -------
    values_x : ndarray, shape xi.shape[:-1] + values.shape[ndim:]
        Interpolated values at input coordinates.

    Notes
    -----

    .. versionadded:: 0.14

    Examples
    --------
    Evaluate a simple example function on the points of a regular 3-D grid:

    >>> from scipy.interpolate import interpn
    >>> def value_func_3d(x, y, z):
    ...     return 2 * x + 3 * y - z
    >>> x = np.linspace(0, 4, 5)
    >>> y = np.linspace(0, 5, 6)
    >>> z = np.linspace(0, 6, 7)
    >>> points = (x, y, z)
    >>> values = value_func_3d(*np.meshgrid(*points, indexing='ij'))

    Evaluate the interpolating function at a point

    >>> point = np.array([2.21, 3.12, 1.15])
    >>> print(interpn(points, values, point))
    [12.63]

    See also
    --------
    NearestNDInterpolator : Nearest neighbor interpolation on unstructured
                            data in N dimensions

    LinearNDInterpolator : Piecewise linear interpolant on unstructured data
                           in N dimensions

    RegularGridInterpolator : Linear and nearest-neighbor Interpolation on a
                              regular grid in arbitrary dimensions

    RectBivariateSpline : Bivariate spline approximation over a rectangular mesh

    )r,   rp   	splinef2dz[interpn only understands the methods 'linear', 'nearest', and 'splinef2d'. You provided %s.r=   r-   rH  zBThe method splinef2d can only be used for 2-dimensional input dataNz4The method splinef2d does not support extrapolation.r.  zSThe method splinef2d can only be used for scalar data with one point per coordinater   r/  r   r0  r1  c                 S   s   g | ]}t |qS r*   r2  r3  r*   r*   r+   r:   }
  r;   zinterpn.<locals>.<listcomp>r  r.   r8  r	   r9  r,   )r4  rI   rJ   rp   rn   )r?   r*  r@   r   r=   r!   r   rA   r   r>   r   r   rC   r:  r   r   r   r   ZevZlogical_not)r7  r6  r  r4  rI   rJ   r=   r  r&   r5  r   r>  Z	idx_validrB  r*   r*   r+   r   
  s    L






84 r   c                   @   s8   e Zd ZdZdddZdd Zdd	 Zedd
dZdS )_ppformze
    Deprecated piecewise polynomial class.

    New code should use the `PPoly` class instead.

    r   Fc                 C   sv   t jdtd |rt|}n
t|}t| || | j| _	| j
| _| j	jd | _|| _| jd | _| jd | _d S )Nz*_ppform is deprecated -- use PPoly instead)categoryr	   r.   )r   r   DeprecationWarningr@   r[   r   r   rX   rV   coeffsr#   breaksr>   Kr   r9   r   )rQ   rL  rM  r   r[   r*   r*   r+   rX   
  s    
z_ppform.__init__c                 C   s   t | |ddS )Nr	   F)r   r_   )rQ   r#   r*   r*   r+   r_   
  s    z_ppform.__call__c                 C   s2   t | |||| | j||| jk|| jk@  < |S r   )r   r   r   r9   r   r   r*   r*   r+   r   
  s    z_ppform._evaluatec           
      C   s   t |d }tj|d |ftd}t|ddD ]H}t|d }t|d d ||||}	|	| }	|	||| d d f< q.| |||dS )Nr   r   r.   )r   )	r!   r@   r   r   r"   r   r   r   Z	_bspleval)
r   Zxkr   r   r   NZsivalsr   Zfactr  r*   r*   r+   
fromspline
  s    z_ppform.fromsplineN)r   F)r   )	r`   ra   rb   rc   rX   r_   r   r   rP  r*   r*   r*   r+   rI  
  s   
rI  )/__all__rC  r   Znumpyr@   r
   r   r   r   r   r   r   r   r   Zscipy.specialZspecialr   r   Zscipy._lib._utilr    r   r   r   Zpolyintr   r   Zfitpack2r   Zinterpndr   Z	_bsplinesr   r   r   r   ri   rm   r   r   r   r   r   r   r   r   rI  r*   r*   r*   r+   <module>   s\   ,@ ]    b       .   4 g
 