
    
9jxB                       S SK Jr  S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKr\R                  " SS	S
SSSS5      rS rS rSS jrS rS rSS jr\R*                  =rr\R.                  " SS/\" 5       QSPSP7SSS9r\R.                  " SSSSS S!S"S#S$S%S&S/\" 5       QSPSPS'PS(P7S)S*S9r\R4                  r\R.                  " S+S/\" 5       QSPSP7S,S-S9rS.rS/r\R.                  " S0SS\4SS \4S!S"\4S#S$\4S%S&\4S/\" 5       QSPSPS'\4PS(\4P7S1S2S9rS3r\R.                  " S0SS\4SS \4S!S"\4S#S$\4S%S&\4S/\" 5       QSPSPS'\4PS(\4P7S15      r \R.                  " S4S5/\" S65      QS7PS8P7S9S:S9r!S;r"S<r#\R.                  " S=S>S?S@SASBSCSDSESFSGSHS5\#4/\" S6\#SI9QS7\#4PS8\#4PSJ\#4PSK\#4P7SL\"SMSNSOSP9r$SQr%\R.                  " SRS>S?S@SASBSCSDSESFSGSHS5\%4/\" S6\%SI9QS7\%4PS8\%4PSJ\%4PSK\%4P7SS\"STSUSVSP9r&\R.                  " SWS>S?S@SASBSCSDSESFSGSHSX/\" S6SYSI9QSZPS[PSJPSKP7SLS\S9r'\R.                  " S]S>S?S@SASBSCSDSESFSGSHS^/\" S6S_SI9QS`PSaPSJPSKP7SSSbS9r(Scr)\R.                  " SdSeSfSgShSiSjSkSlSmSnSoSp/\" SqSrSsSI9QStPSuPSvPSwP7Sx\)SySz9r*SS{ jr+SS} jr,SS~ jr-\R\                  R_                  S|S9S 5       r0SS jr1g)    )annotationsN)_core)_routines_math)fusion)stride_tricks)	bf16_loopz
T x1, T x2zT yzx1 * x2za + bzy = a0dot_productc                    U R                   S:w  d  UR                   S:w  a  [        S5      eU R                  R                  S;   d  UR                  R                  S;   a  g[	        XU5      (       a  gg)N   z&Only 1d inputs are supported currentlybuidirectfft)ndimNotImplementedErrordtypekind_fftconv_faster)in1in2modes      I/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_math/misc.py_choose_conv_methodr      sX    
xx1}A!"JKK
yy~~#))..E"9s&&    c                    g)zB
.. seealso:: :func: `scipy.signal._signaltools._fftconv_faster`

T )xhr   s      r   r   r   &   s     r   c                   U R                   S:X  a  [        S5      eUR                   S:X  a  [        S5      eUR                  S:  a  [        S5      eUR                   U R                   :  a  XpU R                  5       n UR                  5       n[	        XU5      nUS:X  a  [        XU5      nU$ US:X  a  [        XU5      nU$ [        S5      e)	aR  Returns the discrete, linear convolution of two one-dimensional sequences.

Args:
    a (cupy.ndarray): first 1-dimensional input.
    v (cupy.ndarray): second 1-dimensional input.
    mode (str, optional): `valid`, `same`, `full`

Returns:
    cupy.ndarray: Discrete, linear convolution of a and v.

.. seealso:: :func:`numpy.convolve`

r   za cannot be emptyzv cannot be emptyr   z"v cannot be multidimensional arrayr   r   zUnsupported method)size
ValueErrorr   ravelr   _dot_convolve_fft_convolve)avr   methodouts        r   convolver)   /   s     	vv{,--vv{,--vvz=>>vv1		A		A t,FA$'
 J	 
5A$' J -..r   c                   SnU R                   S   UR                   S   :  a  XpSUR                   S   S-  -
  nU R                  R                  S:X  d  UR                  R                  S:X  a4  [        R                  R                  [        R                  R
                  pTO3[        R                  R                  [        R                  R                  pT[        R                  " X5      nU R                   S   UR                   S   pSS K	n	U	R                  R                  R                  Xx-   S-
  5      n
U" X
5      nU" X5      nU" X-  U
5      nUS:X  a	  SXx-   S-
  pO.US:X  a  US-
  S-  U-   nX-   nOUS:X  a  US-
  UpO[        S	5      eUS
X24   nUR                  S;   a  [        R                  " U5      nUR                  USS9$ )Nr   r      cfullsamevalidz5acceptable mode flags are `valid`, `same`, or `full`..iuFcopy)shaper   r   cupyr   ifftrfftirfftresult_typecupyx.scipy.fftscipynext_fast_lenr!   aroundastype)a1a2r   offsetr   r6   r   n1n2cupyxout_sizefa1fa2r(   startends                   r   r$   r$   R   s   F	xx|bhhrl"BRXXb\A%% 
xx}}rxx}}3HHLL$((--THHMM488>>TR$EXXb\288B<{{,,RWq[9H
b
C
b
C
sy(
#Cv~!s	aA&j	!VRsCE 	E c59n
CzzTkk#::e%:((r   c                @   SnU R                   UR                   :  a  XpSUR                   S-  -
  n[        R                  " X5      nU R                   UR                   peU R                  USS9n UR                  USS9nUS:X  a!  XV-   S-
  n[        R                  " XS-
  5      n O?US:X  a,  UnUS-
  S-  U-   n[        R                  " XS-
  U-
  U45      n OUS:X  a  XV-
  S-   nU R
                  S   n	[        R                  " U WU4X45      n [        XS S S	2   SS
9n
U
$ )Nr   r   r,   Fr2   r.   r/   r0   r+   )axis)	r    r5   r9   r>   padstridesr   
as_strided_dot_kernel)r?   r@   r   rA   r   rB   rC   rE   pad_sizestrideoutputs              r   r#   r#   y   s!   F	wwBRWWq[R$EWWbgg	5u	%B	5u	%Bv~7Q;XXbq&!	Fq=6)XXb6H,h78	7Q;ZZ]F		!	!"xnv6F	GB"XA.FMr   c                    [         R                  " 5       (       a$  [         R                  " [        R                  XX#S9$ U R	                  XUS9$ )a  Clips the values of an array to a given interval.

This is equivalent to ``maximum(minimum(a, a_max), a_min)``, while this
function is more efficient.

Args:
    a (cupy.ndarray): The source array.
    a_min (scalar, cupy.ndarray or None): The left side of the interval.
        When it is ``None``, it is ignored.
    a_max (scalar, cupy.ndarray or None): The right side of the interval.
        When it is ``None``, it is ignored.
    out (cupy.ndarray): Output array.

Returns:
    cupy.ndarray: Clipped array.

.. seealso:: :func:`numpy.clip`

Notes
-----
When `a_min` is greater than `a_max`, `clip` returns an
array in which all values are equal to `a_max`.
r(   )r   
_is_fusing_call_ufunc_mathclip)r%   a_mina_maxr(   s       r   rX   rX      sF    0 !!%**"#E< 	< 66%C6((r   	cupy_cbrtze->ezf->fzd->dzout0 = cbrt(in0)zJElementwise cube root function.

    .. seealso:: :data:`numpy.cbrt`

    )doccupy_squarezb->bzB->Bzh->hzH->Hzi->izI->Izl->lzL->Lzq->qzQ->QzF->FzD->Dzout0 = in0 * in0zIElementwise square function.

    .. seealso:: :data:`numpy.square`

    	cupy_fabszout0 = abs(in0)zuCalculates absolute values element-wise.
    Only real values are handled.

    .. seealso:: :data:`numpy.fabs`

    zout0 = in0 > 0z
out0 = in0 / abs(in0)
	cupy_signzout0 = (in0 > 0) - (in0 < 0)zElementwise sign function.

    It returns -1, 0, or 1 depending on the sign of the input.

    .. seealso:: :data:`numpy.sign`

    z
if (in0.real() == 0) {
  out0 = (in0.imag() > 0) - (in0.imag() < 0);
} else {
  out0 = (in0.real() > 0) - (in0.real() < 0);
}
cupy_heavisideee->er,   ff->fdd->dz
    if (isnan(in0)) {
        out0 = in0;
    } else if (in0 == 0) {
        out0 = in1;
    } else {
        out0 = (in0 > 0);
    }
    zTCompute the Heaviside step function.

    .. seealso:: :data:`numpy.heaviside`

    z;
#ifndef NAN
#define NAN __int_as_float(0x7fffffff)
#endif
zLout0 = (isnan(in0) | isnan(in1)) ? out0_type(NAN) : out0_type(max(in0, in1))cupy_maximumz??->?zbb->bzBB->Bzhh->hzHH->Hzii->izII->Izll->lzLL->Lzqq->qzQQ->Q)codezFF->FzDD->Dzout0 = max(in0, in1)zTakes the maximum of two arrays elementwise.

    If NaN appears, it returns the NaN.

    .. seealso:: :data:`numpy.maximum`

    )OP_MAXr   r   max)preambler\   cutensor_op
scatter_opzLout0 = (isnan(in0) | isnan(in1)) ? out0_type(NAN) : out0_type(min(in0, in1))cupy_minimumzout0 = min(in0, in1)zTakes the minimum of two arrays elementwise.

    If NaN appears, it returns the NaN.

    .. seealso:: :data:`numpy.minimum`

    )OP_MINr   r   min	cupy_fmax)ra   out0 = fmax(in0, in1)ro   )rb   ro   )rc   ro   zTakes the maximum of two arrays elementwise.

    If NaN appears, it returns the other operand.

    .. seealso:: :data:`numpy.fmax`

    	cupy_fmin)ra   out0 = fmin(in0, in1)rq   )rb   rq   )rc   rq   zTakes the minimum of two arrays elementwise.

    If NaN appears, it returns the other operand.

    .. seealso:: :data:`numpy.fmin`

    a  
template <class T>
__device__ T nan_to_num(T x, T nan, T posinf, T neginf) {
    if (isnan(x))
        return nan;
    if (isinf(x))
        return x > 0 ? posinf : neginf;
    return x;
}

template <class T>
__device__ complex<T> nan_to_num(complex<T> x, T nan, T posinf, T neginf) {
    T re = nan_to_num(x.real(), nan, posinf, neginf);
    T im = nan_to_num(x.imag(), nan, posinf, neginf);
    return complex<T>(re, im);
}
cupy_nan_to_num_z????->?zbbbb->bzBBBB->Bzhhhh->hzHHHH->Hziiii->izIIII->Izllll->lzLLLL->Lzqqqq->qzQQQQ->Q)zeeee->e%out0 = nan_to_num(in0, in1, in2, in3)   r   rs   )zffff->frs   )zdddd->drs   )zFfff->Frs   )zDddd->Drs   z
out0 = in0zQElementwise nan_to_num function.

    .. seealso:: :func:`numpy.nan_to_num`

    )rh   r\   c                j   UR                   S;   a.  [        R                  " UR                   R                  5       5      nUR                   S;  a  Sn OMU cJ  UbG  U(       a   [        R                  " U5      R
                  O[        R                  " U5      R                  n [        R                  " X5      $ )NFDefdr   )charr5   r   lowerfinform   rg   
asanyarray)r   r   negs      r   _check_nan_infr}     sy    zzT

5::++-.zz	
s%(DJJu!!djj.?.C.C??1$$r   Tc                "   [        U [        R                  5      (       d  [        R                  " SU 5      nOU(       a  [        R                  " U 5      OU nUR
                  n[        X&5      n[        X6S5      n[        XFS5      n[        XX4US9$ )zReplace NaN with zero and infinity with large finite numbers (default
behaviour) or with the numbers defined by the user using the `nan`,
`posinf` and/or `neginf` keywords.

.. seealso:: :func:`numpy.nan_to_num`

r   FTrT   )
isinstancer5   ndarrayr.   
empty_liker   r}   _nan_to_num)r   r3   nanposinfneginfr(   r   s          r   
nan_to_numr     sq     a&&iiA$(dooa aIIE

$CF51FF40Fqv377r   c                ~   [        U R                  R                  [        R                  5      (       d  U $ US:  a9  [
        R                  " U R                  R                  5      nUR                  U-  n[        R                  " [        R                  " U R                  5      U:  5      (       a  U R                  n U $ )a  If input is complex with all imaginary parts close to zero, return real
parts.
"Close to zero" is defined as `tol` * (machine epsilon of the type for
`a`).

.. warning::

        This function may synchronize the device.

.. seealso:: :func:`numpy.real_if_close`
r   )
issubclassr   typer5   complexfloatingnumpyrz   epsallabsoluteimagreal)r%   tolfs      r   real_if_closer     s}     aggllD$8$899
QwKK%eeckxxaff%+,,FFHr   )for_each_devicec                    SnUS-  nSnU (       a  SnOSnUS-  nU[         R                  R                  R                  -  nSn[         R                  " XUSUS	9$ )
Nzraw V x, raw U idx, z2raw W fx, raw Y fy, U len, raw Y left, raw Y rightzZ yztypedef double real_t;
ztypedef Z real_t;
ztypedef Z value_t;
a  
        U x_idx = idx[i] - 1;

        if ( _isnan<V>(x[i]) ) { y = x[i]; }
        else if (x_idx < 0) { y = left[0]; }
        else if (x[i] == fx[len - 1]) {
            // searchsorted cannot handle both of the boundary points,
            // so we must detect and correct ourselves...
            y = fy[len - 1];
        }
        else if (x_idx >= len - 1) { y = right[0]; }
        else if (x[i] == fx[x_idx]) { y = fy[x_idx]; }
        else {
            const Z slope = (value_t)(fy[x_idx+1] - fy[x_idx]) / \
                            ((real_t)fx[x_idx+1] - (real_t)fx[x_idx]);
            Z out = slope * ((real_t)x[i] - (real_t)fx[x_idx]) \
                    + (value_t)fy[x_idx];
            if (_isnan<Z>(out)) {
                out = slope * ((real_t)x[i] - (real_t)fx[x_idx+1]) \
                      + (value_t)fy[x_idx+1];
                if (_isnan<Z>(out) && (fy[x_idx] == fy[x_idx+1])) {
                    out = fy[x_idx];
                }
            }
            y = out;
        }
    cupy_interp)rh   )r5   _sortingsearch	_preambleElementwiseKernel)
is_complex	in_params
out_paramsrh   re   s        r   _get_interp_kernelr     sp    &IEEIJ-(&&H$$...HD6 !!t]XG Gr   c           
        UR                   S:w  d  UR                   S:w  a  [        S5      eUR                  UR                  :w  a  [        S5      eUR                  S:X  a  [        S5      eU R                  R                  (       d  [        S5      e[        R                  " X5      n[        R                  " U[        R                  5      (       d)  [        SR                  U[        R                  5      5      eUGb   US:X  a  [        S	5      e[        U5      nSnSnU R                  [        R                  5      n UR                  [        R                  5      nX-  n X-  n[        R                  " U5      nX   nX'   n[        R                  " US
S U-
  XSS U-   45      n[        R                  " US
S X"SS 45      nUR                  R                  (       d   eUR                  R                  (       d   eUR                   R"                  S:X  a  SOSn[        R$                  " U R&                  US9n	[        R(                  " XSS9n
Uc  US   O[        R*                  " X2R                   5      nUc  US
   O[        R*                  " XBR                   5      n[-        US:H  5      nU" X
XUR                  X4U	5        U	$ )a  One-dimensional linear interpolation.

Args:
    x (cupy.ndarray): a 1D array of points on which the interpolation
        is performed.
    xp (cupy.ndarray): a 1D array of points on which the function values
        (``fp``) are known.
    fp (cupy.ndarray): a 1D array containing the function values at the
        the points ``xp``.
    left (float or complex): value to return if ``x < xp[0]``. Default is
        ``fp[0]``.
    right (float or complex): value to return if ``x > xp[-1]``. Default is
        ``fp[-1]``.
    period (None or float): a period for the x-coordinates. Parameters
        ``left`` and ``right`` are ignored if ``period`` is specified.
        Default is ``None``.

Returns:
    cupy.ndarray: The interpolated values, same shape as ``x``.

.. note::
    This function may synchronize if ``left`` or ``right`` is not already
    on the device.

.. seealso:: :func:`numpy.interp`

r   zxp and fp must be 1D arraysz$fp and xp are not of the same lengthr   zarray of sample points is emptyz-Non-C-contiguous x is currently not supportedzACannot cast array data from {} to {} according to the rule 'safe'Nzperiod must be a non-zero valuer+   r-   Dd)r   right)side)r   r!   r    flagsc_contiguousr   r5   common_typecan_castfloat64	TypeErrorformatabsr>   argsortconcatenater   r   emptyr4   searchsortedarrayr   )r   xpfpleftr   periodx_dtypeasort_xp	out_dtyperR   idxkerns               r   interpr     sM   : 
ww!|rww!|677	ww"''?@@	ww!|:;;77! #. / 	/q%G==$,,// C68 	8  Q;>??VHHT\\"YYt||$ 	

<<#\\r"#wv~ra76>BCr"#wqG45xx$$$$xx$$$$ xx}}+IZZy1F


B
0CL2a5djjxx&@DmBrFE88)DEi3./D$v6Mr   )r.   )N)Tg        NN)d   )NNN)2
__future__r   r5   r   
cupy._corer   rW   r   cupy.libr   
cupy._utilr   r   ReductionKernelrO   r   r   r)   r$   r#   rX   sqrt
sqrt_fixedcreate_ufunccbrtsquarer   fabs_unsigned_sign_complex_signsign_legacy_complex_sign_legacy_sign	heaviside_float_preamble_float_maximummaximum_float_minimumminimumfmaxfmin_nan_to_num_preambler   r}   r   r   _utilmemoizer   r   r   r   r   <module>r      s   "   .  "    ##	
 F$)N8)D JJ z *ik*6*6*			 
		VVVVVVVVVCkC#)C+1C39C;AC		
	 >> *ik*6*6*				 " fn%v/Gfn%v/Gfn%7 k7 "7 $*7 m	7  &}5	7
 #		"  !!fn%v/Gfn%v/Gfn%E kE "E $*E "#	E '-.B%C	E
 # .y|.W.g.		(
-


gw'7Ggw~  '  ~	 
 ~  ~  ~  	 !U'4,-


gw'7Ggw~  '  ~	 
 ~  ~  ~  	 !U'4, gw'7Ggw' /0 (	
 (   		& gw'7Ggw' /0 (	
 (   		& &   	9i	9iI/0 1BC	0
/0/0/0/0 !	#	0%8&, D)(G *(GVLr   