
    (ph_                         S r SSKJr  SSKrSSKJrJr  SSKJ	r	  SSK
Jr  / SQrSS	 jr " S
 S\	5      r " S S\5      rSS jr " S S\5      r " S S\5      rg)z;Interpolation algorithms using piecewise cubic polynomials.    )LiteralN)solvesolve_banded   )PPoly)	_isscalar)CubicHermiteSplinePchipInterpolatorpchip_interpolateAkima1DInterpolatorCubicSplinec                    [        [        R                  X45      u  p[        R                  " U R                  [        R
                  5      (       a  [        S5      eU R                  [        5      n [        R                  " UR                  [        R
                  5      (       a  [        nO[        nUb  [        R                  " U5      nUR                  UR                  :w  a  [        S5      e[        R                  " UR                  [        R
                  5      (       a  [        nUR                  USS9nUR                  USS9nX!R                  -  nU R                  S:w  a  [        S5      eU R                  S   S:  a  [        S	5      eU R                  S   UR                  U   :w  a  [        S
U S35      e[        R                  " [        R                  " U 5      5      (       d  [        S5      e[        R                  " [        R                  " U5      5      (       d  [        S5      eUb:  [        R                  " [        R                  " U5      5      (       d  [        S5      e[        R                  " U 5      n[        R                  " US:*  5      (       a  [        S5      e[        R                   " XS5      nUb  [        R                   " X2S5      nXXU4$ )a  Prepare input for cubic spline interpolators.

All data are converted to numpy arrays and checked for correctness.
Axes equal to `axis` of arrays `y` and `dydx` are moved to be the 0th
axis. The value of `axis` is converted to lie in
[0, number of dimensions of `y`).
z`x` must contain real values.z/The shapes of `y` and `dydx` must be identical.Fcopyr   z`x` must be 1-dimensional.r      z%`x` must contain at least 2 elements.zThe length of `y` along `axis`=z  doesn't match the length of `x`z$`x` must contain only finite values.z$`y` must contain only finite values.z'`dydx` must contain only finite values.z)`x` must be strictly increasing sequence.)mapnpasarray
issubdtypedtypecomplexfloating
ValueErrorastypefloatcomplexshapendimallisfinitediffanymoveaxis)xyaxisdydxr   dxs         K/var/www/html/venv/lib/python3.13/site-packages/scipy/interpolate/_cubic.pyprepare_inputr)      s'    rzzA6"DA	}}QWWb0011899	A	}}QWWb0011zz$77djj NOO==R%7%788E{{5u{-	U#A&&=Dvv{566wwqzA~@AAwwqzQWWT]":4& A3 3 4 	4 66"++a.!!?@@66"++a.!!?@@r{{4'8 9 9BCC	B	vvbAgDEE
AQA{{4q)!4    c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r	   H   a  Piecewise-cubic interpolator matching values and first derivatives.

The result is represented as a `PPoly` instance.

Parameters
----------
x : array_like, shape (n,)
    1-D array containing values of the independent variable.
    Values must be real, finite and in strictly increasing order.
y : array_like
    Array containing values of the dependent variable. It can have
    arbitrary number of dimensions, but the length along ``axis``
    (see below) must match the length of ``x``. Values must be finite.
dydx : array_like
    Array containing derivatives of the dependent variable. It can have
    arbitrary number of dimensions, but the length along ``axis``
    (see below) must match the length of ``x``. Values must be finite.
axis : int, optional
    Axis along which `y` is assumed to be varying. Meaning that for
    ``x[i]`` the corresponding values are ``np.take(y, i, axis=axis)``.
    Default is 0.
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), it is set to True.

Attributes
----------
x : ndarray, shape (n,)
    Breakpoints. The same ``x`` which was passed to the constructor.
c : ndarray, shape (4, n-1, ...)
    Coefficients of the polynomials on each segment. The trailing
    dimensions match the dimensions of `y`, excluding ``axis``.
    For example, if `y` is 1-D, then ``c[k, i]`` is a coefficient for
    ``(x-x[i])**(3-k)`` on the segment between ``x[i]`` and ``x[i+1]``.
axis : int
    Interpolation axis. The same axis which was passed to the
    constructor.

Methods
-------
__call__
derivative
antiderivative
integrate
roots

See Also
--------
Akima1DInterpolator : Akima 1D interpolator.
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.
CubicSpline : Cubic spline data interpolator.
PPoly : Piecewise polynomial in terms of coefficients and breakpoints

Notes
-----
If you want to create a higher-order spline matching higher-order
derivatives, use `BPoly.from_derivatives`.

References
----------
.. [1] `Cubic Hermite spline
        <https://en.wikipedia.org/wiki/Cubic_Hermite_spline>`_
        on Wikipedia.
c                   > Uc  Sn[        XXC5      u  pp$nUR                  UR                  S   /S/UR                  S-
  -  -   5      n[        R
                  " USS9U-  nUS S USS  -   SU-  -
  U-  n	[        R                  " S[        U5      S-
  4UR                  SS  -   U	R                  S9n
X-  U
S'   XS S -
  U-  U	-
  U
S'   US S U
S'   US S U
S	'   [        TU ])  XUS
9  X@l        g )NTr   r   r%   r      r      )extrapolate)r)   reshaper   r   r   r    emptylenr   super__init__r%   )selfr#   r$   r&   r%   r3   r'   dxrslopetc	__class__s              r(   r8   CubicHermiteSpline.__init__   s   K,Q4>qjj"((1+!
);;<"S(#2Yab!AI-4HHaQ!_qwwqr{2!''Bw!Sb	!S(1,!CRy!"v!;7	r*   r.   r   N)__name__
__module____qualname____firstlineno____doc__r8   __static_attributes____classcell__r>   s   @r(   r	   r	   H   s    @D r*   r	   c                   P   ^  \ rS rSrSrSU 4S jjr\S 5       r\S 5       rSr	U =r
$ )r
      ac	  PCHIP 1-D monotonic cubic interpolation.

``x`` and ``y`` are arrays of values used to approximate some function f,
with ``y = f(x)``. The interpolant uses monotonic cubic splines
to find the value of new points. (PCHIP stands for Piecewise Cubic
Hermite Interpolating Polynomial).

Parameters
----------
x : ndarray, shape (npoints, )
    A 1-D array of monotonically increasing real values. ``x`` cannot
    include duplicate values (otherwise f is overspecified)
y : ndarray, shape (..., npoints, ...)
    A N-D array of real values. ``y``'s length along the interpolation
    axis must be equal to the length of ``x``. Use the ``axis``
    parameter to select the interpolation axis.
axis : int, optional
    Axis in the ``y`` array corresponding to the x-coordinate values. Defaults
    to ``axis=0``.
extrapolate : bool, optional
    Whether to extrapolate to out-of-bounds points based on first
    and last intervals, or to return NaNs.

Methods
-------
__call__
derivative
antiderivative
roots

See Also
--------
CubicHermiteSpline : Piecewise-cubic interpolator.
Akima1DInterpolator : Akima 1D interpolator.
CubicSpline : Cubic spline data interpolator.
PPoly : Piecewise polynomial in terms of coefficients and breakpoints.

Notes
-----
The interpolator preserves monotonicity in the interpolation data and does
not overshoot if the data is not smooth.

The first derivatives are guaranteed to be continuous, but the second
derivatives may jump at :math:`x_k`.

Determines the derivatives at the points :math:`x_k`, :math:`f'_k`,
by using PCHIP algorithm [1]_.

Let :math:`h_k = x_{k+1} - x_k`, and  :math:`d_k = (y_{k+1} - y_k) / h_k`
are the slopes at internal points :math:`x_k`.
If the signs of :math:`d_k` and :math:`d_{k-1}` are different or either of
them equals zero, then :math:`f'_k = 0`. Otherwise, it is given by the
weighted harmonic mean

.. math::

    \frac{w_1 + w_2}{f'_k} = \frac{w_1}{d_{k-1}} + \frac{w_2}{d_k}

where :math:`w_1 = 2 h_k + h_{k-1}` and :math:`w_2 = h_k + 2 h_{k-1}`.

The end slopes are set using a one-sided scheme [2]_.


References
----------
.. [1] F. N. Fritsch and J. Butland,
       A method for constructing local
       monotone piecewise cubic interpolants,
       SIAM J. Sci. Comput., 5(2), 300-304 (1984).
       :doi:`10.1137/0905021`.
.. [2] see, e.g., C. Moler, Numerical Computing with Matlab, 2004.
       :doi:`10.1137/1.9780898717952`

c                 (  > [        XU5      u  pp#n[        R                  " U5      (       a  Sn[        U5      eUR	                  UR
                  S   4SUR                  S-
  -  -   5      nU R                  Xr5      n[        T	U ]%  XUSUS9  X0l
        g )Nz`PchipInterpolator` only works with real values for `y`. If you are trying to use the real components of the passed array, use `np.real` on the array before passing to `PchipInterpolator`.r   )r   r   r%   r3   )r)   r   iscomplexobjr   r4   r   r   _find_derivativesr7   r8   r%   )
r9   r#   r$   r%   r3   _msgxpdkr>   s
            r(   r8   PchipInterpolator.__init__   s    (t4aq??1WC S/!YY
}tQVVAX67##B*r{C	r*   c                 l   SU -  U-   U-  X-  -
  X-   -  n[         R                  " U5      [         R                  " U5      :g  n[         R                  " U5      [         R                  " U5      :g  [         R                  " U5      S[         R                  " U5      -  :  -  nU) U-  nSXE'   SX'   -  XG'   U$ )Nr   g      @        )r   signabs)h0h1m0m1dmaskmask2mmms           r(   
_edge_casePchipInterpolator._edge_case   s     dRi^be#0 wwqzRWWR[(+q	BrvvbzM0IJuoBGr*   c                 R   UR                   nUR                  S:X  a  U S S 2S 4   n US S 2S 4   nU SS  U S S -
  nUSS  US S -
  U-  nUR                   S   S:X  a/  [        R                  " U5      nXES'   XES'   UR	                  U5      $ [        R
                  " U5      nUSS  US S :g  USS  S:H  -  US S S:H  -  nSUSS  -  US S -   nUSS  SUS S -  -   n	[        R                  " SSS9   XS S -  XSS  -  -   X-   -  n
S S S 5        [        R                  " U5      nSUSS U'   SW
U)    -  USS U) '   [        R                  US   US   US   US   5      US'   [        R                  US   US	   US   US	   5      US'   UR	                  U5      $ ! , (       d  f       N= f)
Nr   r/   r   r   ignore)divideinvalidrU         ?)	r   r   r   
zeros_liker4   rV   errstater
   r`   )r#   r$   y_shapehkmkrR   smk	conditionw1w2whmeans              r(   rN   #PchipInterpolator._find_derivatives  s    ''66Q;!T'
A!T'
AqrUQsV^eafn"771:?q!BqEqE::g&&ggbkWCR(RVq[9RW\J	r!"vX3BVa3Bi [[(;CRj2f9,9F < ]]1!1R"VYJ%771R) ",,RUBqE2a5"Q%H1"--bfbfbfbfM2zz'"" <;s   .F
F&r.   r@   )rA   rB   rC   rD   rE   r8   staticmethodr`   rN   rF   rG   rH   s   @r(   r
   r
      s7    IV
   .# .#r*   r
   c                     [        XUS9nUS:X  a  U" U5      $ [        U5      (       a  UR                  U5      " U5      $ U Vs/ s H  oeR                  U5      " U5      PM     sn$ s  snf )a  
Convenience function for pchip interpolation.

xi and yi are arrays of values used to approximate some function f,
with ``yi = f(xi)``. The interpolant uses monotonic cubic splines
to find the value of new points x and the derivatives there.

See `scipy.interpolate.PchipInterpolator` for details.

Parameters
----------
xi : array_like
    A sorted list of x-coordinates, of length N.
yi : array_like
    A 1-D array of real values. `yi`'s length along the interpolation
    axis must be equal to the length of `xi`. If N-D array, use axis
    parameter to select correct axis.

    .. deprecated:: 1.13.0
        Complex data is deprecated and will raise an error in
        SciPy 1.15.0. If you are trying to use the real components of
        the passed array, use ``np.real`` on `yi`.

x : scalar or array_like
    Of length M.
der : int or list, optional
    Derivatives to extract. The 0th derivative can be included to
    return the function value.
axis : int, optional
    Axis in the yi array corresponding to the x-coordinate values.

Returns
-------
y : scalar or array_like
    The result, of length R or length M or M by R.

See Also
--------
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.

Examples
--------
We can interpolate 2D observed data using pchip interpolation:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.interpolate import pchip_interpolate
>>> x_observed = np.linspace(0.0, 10.0, 11)
>>> y_observed = np.sin(x_observed)
>>> x = np.linspace(min(x_observed), max(x_observed), num=100)
>>> y = pchip_interpolate(x_observed, y_observed, x)
>>> plt.plot(x_observed, y_observed, "o", label="observation")
>>> plt.plot(x, y, label="pchip interpolation")
>>> plt.legend()
>>> plt.show()

r.   r   )r
   r   
derivative)xiyir#   derr%   Pnus          r(   r   r   8  sb    t 	"t,A
axt	3||C ##.12cR #c222s    A'c                      ^  \ rS rSrSrSSSS.S\S   S\S-  4U 4S	 jjjjrSS
 jr\	SS j5       r
\	SS j5       rSrU =r$ )r   i|  a  
Akima interpolator

Fit piecewise cubic polynomials, given vectors x and y. The interpolation
method by Akima uses a continuously differentiable sub-spline built from
piecewise cubic polynomials. The resultant curve passes through the given
data points and will appear smooth and natural.

Parameters
----------
x : ndarray, shape (npoints, )
    1-D array of monotonically increasing real values.
y : ndarray, shape (..., npoints, ...)
    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 the interpolation axis.
axis : int, optional
    Axis in the ``y`` array corresponding to the x-coordinate values. Defaults
    to ``axis=0``.
method : {'akima', 'makima'}, optional
    If ``"makima"``, use the modified Akima interpolation [2]_.
    Defaults to ``"akima"``, use the Akima interpolation [1]_.

    .. versionadded:: 1.13.0

extrapolate : {bool, None}, optional
    If bool, determines whether to extrapolate to out-of-bounds points 
    based on first and last intervals, or to return NaNs. If None, 
    ``extrapolate`` is set to False.
    
Methods
-------
__call__
derivative
antiderivative
roots

See Also
--------
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.
CubicSpline : Cubic spline data interpolator.
PPoly : Piecewise polynomial in terms of coefficients and breakpoints

Notes
-----
.. versionadded:: 0.14

Use only for precise data, as the fitted curve passes through the given
points exactly. This routine is useful for plotting a pleasingly smooth
curve through a few given points for purposes of plotting.

Let :math:`\delta_i = (y_{i+1} - y_i) / (x_{i+1} - x_i)` be the slopes of
the interval :math:`\left[x_i, x_{i+1}\right)`. Akima's derivative at
:math:`x_i` is defined as:

.. math::

    d_i = \frac{w_1}{w_1 + w_2}\delta_{i-1} + \frac{w_2}{w_1 + w_2}\delta_i

In the Akima interpolation [1]_ (``method="akima"``), the weights are:

.. math::

    \begin{aligned}
    w_1 &= |\delta_{i+1} - \delta_i| \\
    w_2 &= |\delta_{i-1} - \delta_{i-2}|
    \end{aligned}

In the modified Akima interpolation [2]_ (``method="makima"``),
to eliminate overshoot and avoid edge cases of both numerator and
denominator being equal to 0, the weights are modified as follows:

.. math::

    \begin{align*}
    w_1 &= |\delta_{i+1} - \delta_i| + |\delta_{i+1} + \delta_i| / 2 \\
    w_2 &= |\delta_{i-1} - \delta_{i-2}| + |\delta_{i-1} + \delta_{i-2}| / 2
    \end{align*}

Examples
--------
Comparison of ``method="akima"`` and ``method="makima"``:

>>> import numpy as np
>>> from scipy.interpolate import Akima1DInterpolator
>>> import matplotlib.pyplot as plt
>>> x = np.linspace(1, 7, 7)
>>> y = np.array([-1, -1, -1, 0, 1, 1, 1])
>>> xs = np.linspace(min(x), max(x), num=100)
>>> y_akima = Akima1DInterpolator(x, y, method="akima")(xs)
>>> y_makima = Akima1DInterpolator(x, y, method="makima")(xs)

>>> fig, ax = plt.subplots()
>>> ax.plot(x, y, "o", label="data")
>>> ax.plot(xs, y_akima, label="akima")
>>> ax.plot(xs, y_makima, label="makima")
>>> ax.legend()
>>> fig.show()

The overshoot that occurred in ``"akima"`` has been avoided in ``"makima"``.

References
----------
.. [1] A new method of interpolation and smooth curve fitting based
       on local procedures. Hiroshi Akima, J. ACM, October 1970, 17(4),
       589-602. :doi:`10.1145/321607.321609`
.. [2] Makima Piecewise Cubic Interpolation. Cleve Moler and Cosmin Ionita, 2019.
       https://blogs.mathworks.com/cleve/2019/04/29/makima-piecewise-cubic-interpolation/

akimaN)methodr3   r}   )r|   makimar3   c          	      >  > US;  a  [        SU S35      e[        XU5      u  pp#n[        R                  " U5      (       a  Sn[	        U5      eUc  SOUn[        R
                  " UR                  S-   4UR                  SS  -   5      n	U[        S 5      4SUR                  S-
  -  -      n[        R                  " US	S
9U-  U	SS& SU	S   -  U	S   -
  U	S'   SU	S   -  U	S   -
  U	S	'   SU	S   -  U	S   -
  U	S'   SU	S   -  U	S   -
  U	S'   SU	SS  U	S S -   -  n
[        R                  " [        R                  " U	S	S
95      nUS:X  a<  [        R                  " U	SS  U	S S -   5      nUSS  SUSS  -  -   nUS S SUS S -  -   nO
USS  nUS S nX-   n[        R                  " US[        R                  " U[        R                  * S9-  :  5      nUS	   USS  nnUU   U	US-   4U-      -  UU   U	US-   4U-      -  -   UU   -  U
U'   [        TU ]A  XU
S	US9  X0l        g )N>   r|   r~   z	`method`=z is unsupported.z`Akima1DInterpolator` only works with real values for `y`. If you are trying to use the real components of the passed array, use `np.real` on the array before passing to `Akima1DInterpolator`.Fr2   r   Nr   r.   r   rg   g       @r/         ?r~   g&.>)initialrL   )NotImplementedErrorr)   r   rM   r   r5   sizer   slicer   r    rW   nonzeromaxinfr7   r8   r%   )r9   r#   r$   r%   r}   r3   r'   rO   rP   mr<   dmpmf1f2f12indx_indy_indr>   s                      r(   r8   Akima1DInterpolator.__init__  s   ,,%	&9I&JKK *!5q??1,C S/!  +2e HHaffqj^aggabk12t(affqj"99:''!!$r)!B AaDy1Q4!AaDy1Q4!QrU
QrU""QrU
QrU"" !AB%!CR&.!VVBGGAA&'X!"#2'BAB#12,&BCR3CR=(BABBCRBgjjtbffS266'&BBBC1vs12wuS'AuqylU233S'AuqylU23347:3x@# 	qqkB	r*   c                     [        S5      e)Nz9Extending a 1-D Akima interpolator is not yet implementedr   )r9   r=   r#   rights       r(   extendAkima1DInterpolator.extend!  s    ! #4 5 	5r*   c                     [        S5      eNz:This method does not make sense for an Akima interpolator.r   )clstckr3   s      r(   from_splineAkima1DInterpolator.from_spline'      ! #; < 	<r*   c                     [        S5      er   r   )r   bpr3   s      r(   from_bernstein_basis(Akima1DInterpolator.from_bernstein_basis,  r   r*   r.   )r   )Tr   )rA   rB   rC   rD   rE   r   boolr8   r   classmethodr   r   rF   rG   rH   s   @r(   r   r   |  se    m^37+/38I0J 3!D[3 3j5 < < < <r*   r   c                   @   ^  \ rS rSrSrSU 4S jjr\S 5       rSrU =r	$ )r   i2  a]  Cubic spline data interpolator.

Interpolate data with a piecewise cubic polynomial which is twice
continuously differentiable [1]_. The result is represented as a `PPoly`
instance with breakpoints matching the given data.

Parameters
----------
x : array_like, shape (n,)
    1-D array containing values of the independent variable.
    Values must be real, finite and in strictly increasing order.
y : array_like
    Array containing values of the dependent variable. It can have
    arbitrary number of dimensions, but the length along ``axis``
    (see below) must match the length of ``x``. Values must be finite.
axis : int, optional
    Axis along which `y` is assumed to be varying. Meaning that for
    ``x[i]`` the corresponding values are ``np.take(y, i, axis=axis)``.
    Default is 0.
bc_type : string or 2-tuple, optional
    Boundary condition type. Two additional equations, given by the
    boundary conditions, are required to determine all coefficients of
    polynomials on each segment [2]_.

    If `bc_type` is a string, then the specified condition will be applied
    at both ends of a spline. Available conditions are:

    * 'not-a-knot' (default): The first and second segment at a curve end
      are the same polynomial. It is a good default when there is no
      information on boundary conditions.
    * 'periodic': The interpolated functions is assumed to be periodic
      of period ``x[-1] - x[0]``. The first and last value of `y` must be
      identical: ``y[0] == y[-1]``. This boundary condition will result in
      ``y'[0] == y'[-1]`` and ``y''[0] == y''[-1]``.
    * 'clamped': The first derivative at curves ends are zero. Assuming
      a 1D `y`, ``bc_type=((1, 0.0), (1, 0.0))`` is the same condition.
    * 'natural': The second derivative at curve ends are zero. Assuming
      a 1D `y`, ``bc_type=((2, 0.0), (2, 0.0))`` is the same condition.

    If `bc_type` is a 2-tuple, the first and the second value will be
    applied at the curve start and end respectively. The tuple values can
    be one of the previously mentioned strings (except 'periodic') or a
    tuple ``(order, deriv_values)`` allowing to specify arbitrary
    derivatives at curve ends:

    * `order`: the derivative order, 1 or 2.
    * `deriv_value`: array_like containing derivative values, shape must
      be the same as `y`, excluding ``axis`` dimension. For example, if
      `y` is 1-D, then `deriv_value` must be a scalar. If `y` is 3-D with
      the shape (n0, n1, n2) and axis=2, then `deriv_value` must be 2-D
      and have the shape (n0, n1).
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), ``extrapolate`` is
    set to 'periodic' for ``bc_type='periodic'`` and to True otherwise.

Attributes
----------
x : ndarray, shape (n,)
    Breakpoints. The same ``x`` which was passed to the constructor.
c : ndarray, shape (4, n-1, ...)
    Coefficients of the polynomials on each segment. The trailing
    dimensions match the dimensions of `y`, excluding ``axis``.
    For example, if `y` is 1-d, then ``c[k, i]`` is a coefficient for
    ``(x-x[i])**(3-k)`` on the segment between ``x[i]`` and ``x[i+1]``.
axis : int
    Interpolation axis. The same axis which was passed to the
    constructor.

Methods
-------
__call__
derivative
antiderivative
integrate
roots

See Also
--------
Akima1DInterpolator : Akima 1D interpolator.
PchipInterpolator : PCHIP 1-D monotonic cubic interpolator.
PPoly : Piecewise polynomial in terms of coefficients and breakpoints.

Notes
-----
Parameters `bc_type` and ``extrapolate`` work independently, i.e. the
former controls only construction of a spline, and the latter only
evaluation.

When a boundary condition is 'not-a-knot' and n = 2, it is replaced by
a condition that the first derivative is equal to the linear interpolant
slope. When both boundary conditions are 'not-a-knot' and n = 3, the
solution is sought as a parabola passing through given points.

When 'not-a-knot' boundary conditions is applied to both ends, the
resulting spline will be the same as returned by `splrep` (with ``s=0``)
and `InterpolatedUnivariateSpline`, but these two methods use a
representation in B-spline basis.

.. versionadded:: 0.18.0

Examples
--------
In this example the cubic spline is used to interpolate a sampled sinusoid.
You can see that the spline continuity property holds for the first and
second derivatives and violates only for the third derivative.

>>> import numpy as np
>>> from scipy.interpolate import CubicSpline
>>> import matplotlib.pyplot as plt
>>> x = np.arange(10)
>>> y = np.sin(x)
>>> cs = CubicSpline(x, y)
>>> xs = np.arange(-0.5, 9.6, 0.1)
>>> fig, ax = plt.subplots(figsize=(6.5, 4))
>>> ax.plot(x, y, 'o', label='data')
>>> ax.plot(xs, np.sin(xs), label='true')
>>> ax.plot(xs, cs(xs), label="S")
>>> ax.plot(xs, cs(xs, 1), label="S'")
>>> ax.plot(xs, cs(xs, 2), label="S''")
>>> ax.plot(xs, cs(xs, 3), label="S'''")
>>> ax.set_xlim(-0.5, 9.5)
>>> ax.legend(loc='lower left', ncol=2)
>>> plt.show()

In the second example, the unit circle is interpolated with a spline. A
periodic boundary condition is used. You can see that the first derivative
values, ds/dx=0, ds/dy=1 at the periodic point (1, 0) are correctly
computed. Note that a circle cannot be exactly represented by a cubic
spline. To increase precision, more breakpoints would be required.

>>> theta = 2 * np.pi * np.linspace(0, 1, 5)
>>> y = np.c_[np.cos(theta), np.sin(theta)]
>>> cs = CubicSpline(theta, y, bc_type='periodic')
>>> print("ds/dx={:.1f} ds/dy={:.1f}".format(cs(0, 1)[0], cs(0, 1)[1]))
ds/dx=0.0 ds/dy=1.0
>>> xs = 2 * np.pi * np.linspace(0, 1, 100)
>>> fig, ax = plt.subplots(figsize=(6.5, 4))
>>> ax.plot(y[:, 0], y[:, 1], 'o', label='data')
>>> ax.plot(np.cos(xs), np.sin(xs), label='true')
>>> ax.plot(cs(xs)[:, 0], cs(xs)[:, 1], label='spline')
>>> ax.axes.set_aspect('equal')
>>> ax.legend(loc='center')
>>> plt.show()

The third example is the interpolation of a polynomial y = x**3 on the
interval 0 <= x<= 1. A cubic spline can represent this function exactly.
To achieve that we need to specify values and first derivatives at
endpoints of the interval. Note that y' = 3 * x**2 and thus y'(0) = 0 and
y'(1) = 3.

>>> cs = CubicSpline([0, 1], [0, 1], bc_type=((1, 0), (1, 3)))
>>> x = np.linspace(0, 1)
>>> np.allclose(x**3, cs(x))
True

References
----------
.. [1] `Cubic Spline Interpolation
        <https://en.wikiversity.org/wiki/Cubic_Spline_Interpolation>`_
        on Wikiversity.
.. [2] Carl de Boor, "A Practical Guide to Splines", Springer-Verlag, 1978.
c           	        > [        XU5      u  pp#n[        U5      nU R                  XBUR                  SS  U5      u  pUc  U	S   S:X  a  SnOSnUR                  S:X  a  [
        R                  " U5      n
GOUR                  UR                  S   /S/UR                  S-
  -  -   5      n[
        R                  " USS9U-  nUS:X  a&  U	S   S;   a
  SUS   4U	S'   U	S   S;   a
  SUS   4U	S'   US:X  a  U	S   S	:X  a  U	S   S	:X  a  [
        R                  " S
5      n[
        R                  " SUR                  SS  -   UR                  S9nSUS'   SUS'   US   US'   SUS   US   -   -  US'   US   US'   SUS'   SUS'   SUS   -  US'   SUS   US   -  US   US   -  -   -  US'   SUS   -  US'   [        XSSSS9n
GOUS:X  aZ  U	S   S:X  aQ  X-  R                  S5      SU-  R                  S5      -  n[
        R                  " X4UR                  SS  -   5      n
GOR[
        R                  " SU45      n[
        R                  " U4UR                  SS  -   UR                  S9nSUS S USS  -   -  USSS24'   US S USSS 24'   USS  USS S24'   SUSS  US S -  US S USS  -  -   -  USS& U	u  nnUS:X  GaI  US S 2SS24   nSUS   US   -   -  US'   US   US'   US S nUS   nUS   nSUS   US   -   -  nUS   nUS   nSUS   US   -  US   US   -  -   -  US'   SUS   US   -  US   US   -  -   -  US'   US S 2S S24   nUS S n[
        R                  " U5      nU* US'   U* US'   [!        SUUSSSS9n[!        SUUSSSS9nUS   UUS   -  -
  UUS   -  -
  UUUS   -  -   UUS   -  -   -  n[
        R                  " U4UR                  SS  -   UR                  S9n
UUU-  -   U
S S& UU
S'   U
S   U
S'   GOkUS	:X  aN  US   US'   US   US   -
  US'   US   US   -
  nUS   SU-  -   US   -  US   -  US   S-  US   -  -   U-  US'   O[US   S:X  a  SUS'   SUS'   US   US'   O?US   S:X  a6  SUS   -  US'   US   US'   SUS   -  US   S-  -  SUS   US   -
  -  -   US'   US	:X  aN  US   US'   US   US   -
  US'   US   US   -
  nUS   S-  US   -  SU-  US   -   US   -  US   -  -   U-  US'   O[US   S:X  a  SUS'   SUS'   US   US'   O?US   S:X  a6  SUS   -  US'   US   US'   SUS   -  US   S-  -  SUS   US   -
  -  -   US'   [!        SXSSSS9n
["        TU ]I  XU
SUS9  X0l        g ) Nr   r   periodicTr.   r   
not-a-knotr   r2   r   )r2   r2   )r2   r1   r   r   )r   r   )r   r   )r   r   r   r   )r   r   )r   r   F)overwrite_aoverwrite_bcheck_finiterf   r/   rg   r   )overwrite_abr   r   g      )r   r/   )r/   rg   r   rL   )r)   r6   _validate_bcr   r   r   rh   r4   r   r    zerosr5   r   r   sumbroadcast_tor   r7   r8   r%   )r9   r#   r$   r%   bc_typer3   r'   rO   nbcsr:   r;   Abr<   bc_startbc_enda_m1_0a_m1_m2a_m1_m1a_m2_m1a_0_m1Acb1b2s1s2s_m1r\   r>   s                                 r(   r8   CubicSpline.__init__  sg   )!5qF!!'aggabk4@!u
"("66Q;a A**bhhqk]aSAFFQJ-??@CGGAA&,E Ava566aMBqEa566aMBqE Av"Q%</BqE\4IHHV$HHTAGGABK/qww?$$Q%$r!ur!u}-$Q%$$$58|!CFU1X-Aq0AAB!58|!!Dd',.aBqEZ/ [%%a(BH>>!+<<OOAtaggabk'9: HHaV$HHaTAGGABK/qww? "Sb'BqrF"23!QrT'
cr7!QR%V"crc'
s12ws3c#2hqr6JJK!B#% &z) !QrT'
A2b6BqE>2AdG fAdG#2A  VF fG2b6BrF?3G fGUFAr 2SWuQx5G GHAaDR59!4s2wr7J!JKAbE1crc6B3BBr*B#GBqE%XBrF &fb"527eMB &fb"527eMB rUVbe^3g26FF$v1~5"R&8HHJD !!3177CA$)^AcrF AbEaDAbE</"$Q%$"#A$1+$aD1Q4K!$Q!A#Q 7%( B #A	E!H 4!589 :!!!)"#$"#$'{!!!)"#be)$"$Q%$#hqk1BqE1H<qAaD1Q4K?PP!-#%b6%$%bEAbEM&	bEAbEM"%b'1*U2Y"6"#A#B-R!8r!B#CFG"H"a#$%$%&	 &q	"a#$r"v:%$&rF&	 #fQi"R&!) ;a1R51R5=>Q Q"$VQ15EKA 	qqkB	r*   c                    [        U [        5      (       a;  U S:X  a1  [        R                  " US   US   SSS9(       d  [	        SU S35      eX 4n O+[        U 5      S:w  a  [	        S	5      eSU ;   a  [	        S
5      e/ nU  GHQ  n[        U[        5      (       a  US:X  a)  UR                  S[        R                  " U5      45        MH  US:X  a)  UR                  S[        R                  " U5      45        Mw  US;   a  UR                  U5        M  [	        SU S35      e Uu  pgUS;  a  [	        S5      e[        R                  " U5      nUR                  U:w  a  [	        SUR                   SU S35      e[        R                  " UR                  [        R                  5      (       a  UR                  [        SS9nUR                  Xg45        GMT     XA4$ ! [         a  n[	        S5      UeSnAff = f)zValidate and prepare boundary conditions.

Returns
-------
validated_bc : 2-tuple
    Boundary conditions for a curve start and end.
y : ndarray
    y casted to complex dtype if one of the boundary conditions has
    complex dtype.
r   r   r/   gV瞯<)rtolatolz(The first and last `y` point along axis zF must be identical (within machine precision) when bc_type='periodic'.r   zF`bc_type` must contain 2 elements to specify start and end conditions.zf'periodic' `bc_type` is defined for both curve ends and cannot be used with other boundary conditions.clampedr   naturalr   zbc_type=z is not allowed.zFA specified derivative value must be given in the form (order, value).Nr   z.The specified derivative order must be 1 or 2.z`deriv_value` shape z is not the expected one .Fr   )
isinstancestrr   allcloser   r6   appendr   	Exceptionr   r   r   r   r   r   r   )	r   r$   expected_deriv_shaper%   validated_bcr   deriv_orderderiv_valuees	            r(   r   CubicSpline._validate_bcz  s    gs##*${{1Q42UG$B4& I. ./ /
 (G 7|q   "E F F W$  "8 9 9 B"c""? ''BHH5I,J(KL9_ ''BHH5I,J(KL55 ''+$xt3C%DEE/1,K f,$ &2 3 3 !jj5$$(<<$.{/@/@.A B,,@+AD 
 ==!2!2B4F4FGGu5A##[$>?C F - ! $< s    G
G4#G//G4r.   )r   r   N)
rA   rB   rC   rD   rE   r8   rs   r   rF   rG   rH   s   @r(   r   r   2  s'    cJ`D C Cr*   r   r   r   )rE   typingr   numpyr   scipy.linalgr   r    r   _polyintr   __all__r)   r	   r
   r   r   r    r*   r(   <module>r      si    A   ,  15 pT TnV#* V#rA3Hs<, s<lL$ Lr*   