
    `ik;                         d dl Z d dlmZ d ZddZ G d de          Z G d de          Zdd	Z G d
 de          ZdS )    N)PPolyc                 `    t          j        |           pt          | d          o
| j        dk    S )z-Check whether x is if a scalar type, or 0-dimshape )cupyisscalarhasattrr   )xs    r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/interpolate/_cubic.py	_isscalarr      s,    =Dwq'22Dqw"}D    c                    t          t          j        | |f          \  } }t          j        | j        t          j                  rt          d          |                     t                    } t          j        |j        t          j                  rt          }nt          }|ut          j        |          }|j
        |j
        k    rt          d          t          j        |j        t          j                  rt          }|                    |d          }|                    |d          }||j        z  }| j        dk    rt          d          | j
        d         d	k     rt          d
          | j
        d         |j
        |         k    r"t          d                    |                    t          j        t          j        |                     st          d          t          j        t          j        |                    st          d          |5t          j        t          j        |                    st          d          t          j        |           }t          j        |dk              rt          d          t          j        ||d          }|t          j        ||d          }| ||||fS )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.Nz/The shapes of `y` and `dydx` must be identical.F)copy   z`x` must be 1-dimensional.r      z%`x` must contain at least 2 elements.zBThe length of `y` along `axis`={0} 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.)mapr   asarray
issubdtypedtypecomplexfloating
ValueErrorastypefloatcomplexr   ndimformatallisfinitediffanymoveaxis)r
   yaxisdydxr   dxs         r   prepare_inputr&      sk    t|aV$$DAqqw 455 :8999	Aqw 455 |D!!7dj  NOOO?4:t';<< 	E{{5u{--	U##A!&=Dv{{5666wqzA~~@AAAwqzQWT]"" 3396$<<A A 	A 8DM!$$%% A?@@@8DM!$$%% A?@@@t)<)< = =BCCC	1Bxa FDEEEaq!!A}T4++b!T4r   c                   $     e Zd ZdZd fd	Z xZS )CubicHermiteSplinea2	  Piecewise-cubic interpolator matching values and first derivatives.

    The result is represented as a `PPoly` instance. [1]_

    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 ``cupy.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.

    See Also
    --------
    Akima1DInterpolator : Akima 1D interpolator.
    PchipInterpolator : PCHIP 1-D monotonic cubic 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.
    r   Nc                 N   |d}t          ||||          \  }}}}}|                    |j        d         gdg|j        dz
  z  z             }t	          j        |d          |z  }|d d         |dd          z   d|z  z
  |z  }	t	          j        dt          |          dz
  f|j        dd          z   |	j                  }
|	|z  |
d<   ||d d         z
  |z  |	z
  |
d<   |d d         |
d<   |d d         |
d	<   t                      
                    |
||
           || _        d S )NTr   r   r#   r      )r      )extrapolate)r&   reshaper   r   r   r   emptylenr   super__init__r#   )selfr
   r"   r$   r#   r.   r%   dxrslopetc	__class__s              r   r3   zCubicHermiteSpline.__init__|   sD   K,Q4>>2q$jj"(1+!
);;<<	!!$$$s*#2#Yabb!AI-4J3q66A:4AGDDD3w!SbS	!S(1,!CRCy!"v!A;777			r   r   N)__name__
__module____qualname____doc__r3   __classcell__r9   s   @r   r(   r(   B   sH        7 7r         r   r(   c                   P     e Zd ZdZd fd	Zed             Zed             Z xZS )PchipInterpolatora	  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
        A 1-D array of monotonically increasing real values. ``x`` cannot
        include duplicate values (otherwise f is overspecified)
    y : ndarray
        A 1-D array of real values. ``y``'s length along the interpolation
        axis must be equal to the length of ``x``. If N-D array, use ``axis``
        parameter to select correct axis.
    axis : int, optional
        Axis in the y array corresponding to the x-coordinate values.
    extrapolate : bool, optional
        Whether to extrapolate to out-of-bounds points based on first
        and last intervals, or to return NaNs.

    See Also
    --------
    CubicHermiteSpline : Piecewise-cubic interpolator.
    Akima1DInterpolator : Akima 1D 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).
           `10.1137/0905021 <https://doi.org/10.1137/0905021>`_.
    .. [2] see, e.g., C. Moler, Numerical Computing with Matlab, 2004.
           `10.1137/1.9780898717952 <https://doi.org/10.1137/1.9780898717952>`_
    r   Nc                    t          |||          \  }}}}}|                    |j        d         fd|j        dz
  z  z             }|                     ||          }t                                          |||d|           || _        d S )Nr   )r   r   r#   r.   )r&   r/   r   r   _find_derivativesr2   r3   r#   )	r4   r
   r"   r#   r.   _xpdkr9   s	           r   r3   zPchipInterpolator.__init__   s    (At441aqYY
}tQVAX677##B**Ar{CCC			r   c                 j   d| z  |z   |z  | |z  z
  | |z   z  }t          j        |          t          j        |          k    }t          j        |          t          j        |          k    t          j        |          dt          j        |          z  k    z  }| |z  }d||<   d||         z  ||<   |S )Nr   g      @        )r   signabs)h0h1m0m1dmaskmask2mmms           r   
_edge_casezPchipInterpolator._edge_case   s     "frkR"r')b2g6 y||ty}},2$)B--/HQKK"TXb\\/)+uo$BsG#r   c                    |j         }|j        dk    r| d d d f         } |d d d f         }| dd          | d d         z
  }|dd          |d d         z
  |z  }|j         d         dk    r3t          j        |          }||d<   ||d<   |                    |          S t          j        |          }|dd          |d d         k    |dd          dk    z  |d d         dk    z  }d|dd          z  |d d         z   }|dd          d|d d         z  z   }	||d d         z  |	|dd          z  z   ||	z   z  }
t          j        |          }t          j        |dd|
z            |dd<   t                              |d         |d         |d         |d                   |d<   t                              |d         |d         |d         |d                   |d<   |                    |          S )Nr   r+   r   r   rJ   g      ?)	r   r   r   
zeros_liker/   rK   whererB   rU   )r
   r"   y_shapehkmkrH   smk	conditionw1w2whmeans              r   rE   z#PchipInterpolator._find_derivatives   s    '6Q;;!!!T'
A!!!T'
AqrrUQssV^eafn"71:??##BBqEBqE::g&&&immWCRC(RVq[9RW\J	r!""vX3B3Va3B3i r#2#w,bf,b9_Q:icFl;;1R4 ",,RUBqE2a5"Q%HH1"--bfbfbfbfMM2zz'"""r   r:   )	r;   r<   r=   r>   r3   staticmethodrU   rE   r?   r@   s   @r   rB   rB      s~        ? ?B        \ ,# ,# \,# ,# ,# ,# ,#r   rB   c                     t          | ||          |dk    r           S t          |          r                     |                    S fd|D             S )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.
    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.

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

    Returns
    -------
    y : scalar or array_like
        The result, of length R or length M or M by R.
    r*   r   c                 L    g | ] }                      |                    !S r   )
derivative).0nuPr
   s     r   
<listcomp>z%pchip_interpolate.<locals>.<listcomp>B  s0    222 R  ##222r   )rB   r   re   )xiyir
   derr#   rh   s     `  @r   pchip_interpolaterm     sx    D 	"bt,,,A
axxqtt	3 3 q||C  ###22222c2222r   c                   \     e Zd ZdZd	 fd	Zd
dZedd            Zedd            Z xZ	S )Akima1DInterpolatoral  
    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 [1]_.

    Parameters
    ----------
    x : ndarray, shape (m, )
        1-D array of monotonically increasing real values.
    y : ndarray, shape (m, ...)
        N-D array of real values. The length of ``y`` along the first axis
        must be equal to the length of ``x``.
    axis : int, optional
        Specifies the axis of ``y`` along which to interpolate. Interpolation
        defaults to the first axis of ``y``.

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

    Notes
    -----
    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.

    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.
    r   c                    t          |||          \  }}}}}t          j        |j        dz   f|j        dd          z             }|t          d           fd|j        dz
  z  z            }t          j        |d          |z  |dd<   d|d         z  |d         z
  |d<   d|d         z  |d         z
  |d<   d|d	         z  |d
         z
  |d<   d|d         z  |d	         z
  |d<   d|dd          |d d	         z   z  }t          j        t          j        |d                    }|dd          }	|d d         }
|	|
z   }|j        dk    rt          j	         nt          j
        |          }t          j        |d|z  k              }|d         |dd          }}|	|         ||dz   f|z            z  |
|         ||dz   f|z            z  z   ||         z  ||<   t                                          |||dd           || _        d S )Nr-   r   Nr   r*   r   rW   g       @r+   g      ?g&.>FrD   )r&   r   r0   sizer   slicer   r   rL   infmaxnonzeror2   r3   r#   )r4   r
   r"   r#   r%   rF   mr7   dmf1f2f12	max_valueindx_indy_indr9   s                   r   r3   zAkima1DInterpolator.__init__l  s$    *!Q552q$ J
~344t(afqj"99:)AA&&&+!B$ AaDy1Q4!AaDy1Q4!QrU
QrU""QrU
QrU"" !ABB%!CRC&.!Xdi***++VW2g!"1TXII$(3--	l3	!11221vs122wuS'AuqylU233S'AuqylU23347:3x@# 	Aqqe<<<			r   Tc                      t          d          )Nz9Extending a 1-D Akima interpolator is not yet implementedNotImplementedError)r4   r8   r
   rights       r   extendzAkima1DInterpolator.extend  s    ! #4 5 5 	5r   Nc                      t          d          Nz:This method does not make sense for an Akima interpolator.r   )clstckr.   s      r   from_splinezAkima1DInterpolator.from_spline      ! #; < < 	<r   c                      t          d          r   r   )r   bpr.   s      r   from_bernstein_basisz(Akima1DInterpolator.from_bernstein_basis  r   r   )r   )Trq   )
r;   r<   r=   r>   r3   r   classmethodr   r   r?   r@   s   @r   ro   ro   E  s        $ $L" " " " " "H5 5 5 5 < < < [< < < < [< < < < <r   ro   rq   )r   r   )	r   $cupyx.scipy.interpolate._interpolater   r   r&   r(   rB   rm   ro   r   r   r   <module>r      s    6 6 6 6 6 6E E E
4  4  4  4 nK K K K K K K K\F# F# F# F# F#* F# F# F#R)3 )3 )3 )3XY< Y< Y< Y< Y<, Y< Y< Y< Y< Y<r   