
    `i6?                        d dl Z d dlZd dl mZ d dlmZ d dlmZ d dlm	Z	 d dl
Z
 ej        dddd	d
dd          Zd Zd ZdkdZd Zd ZdldZej        xZZ ej        dddd          Z ej        dddd          Zej        Z ej        dddd          Zd Zd!Z ej        d"d#d$efd%d&efd'd(efd)d*efd+d,efd-d.d/d0efd1effd2d3          Z ej        d4d5d6d7          Zd8Zd9Z ej        d:d;d<d=d>d?d@dAdBdCdDdEdFefdGefdHefdIefdJeffdKedLdMdNO          Z dPZ! ej        dQd;d<d=d>d?d@dAdBdCdDdEdFe!fdGe!fdHe!fdIe!fdJe!ffdRedSdTdUO          Z" ej        dVdWdKdX          Z# ej        dYdZdRd[          Z$d\Z% ej        d]d^d_e%d`a          Z&dldbZ'dmdeZ(dndgZ)e j*        +                    dch          di             Z,dodjZ-dS )p    N)_core)_routines_math)fusion)stride_tricksz
T x1, T x2zT yzx1 * x2za + bzy = a0dot_productc                     | j         dk    s|j         dk    rt          d          | j        j        dv s|j        j        dv rdS t	          | ||          rdS dS )N   z&Only 1d inputs are supported currentlybuidirectfft)ndimNotImplementedErrordtypekind_fftconv_faster)in1in2modes      c/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_math/misc.py_choose_conv_methodr      sf    
x1}}A!"JKKK
y~#).E"9"9xsC&& u8    c                     dS )zJ
    .. seealso:: :func: `scipy.signal._signaltools._fftconv_faster`

    T )xhr   s      r   r   r   $   s	     4r   fullc                    | j         dk    rt          d          |j         dk    rt          d          |j        dk    rt          d          |j         | j         k    r|| }} |                                 } |                                }t	          | ||          }|dk    rt          | ||          }n'|dk    rt          | ||          }nt          d          |S )	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     	v{{,---v{{,---vzz=>>>v!1			A			A At,,FAq$''	5Aq$''-...Jr   c                 @   d}| j         d         |j         d         k     r|| }} d|j         d         dz  z
  }| j        j        dk    s|j        j        dk    r#t          j        j        t          j        j        }}n"t          j        j        t          j        j        }}t          j        | |          }| j         d         |j         d         }}t          j
        j                            ||z   dz
            }	 || |	          }
 |||	          } ||
|z  |	          }|dk    rd||z   dz
  }}n4|dk    r|dz
  dz  |z   }||z   }n|dk    r|dz
  |}}nt          d	          |d
||f         }|j        dv rt          j        |          }|                    |d          S )Nr   r
      cr   samevalidz5acceptable mode flags are `valid`, `same`, or `full`..iuFcopy)shaper   r   cupyr   ifftrfftirfftresult_typecupyxscipynext_fast_lenr    aroundastype)a1a2r   offsetr   r4   r   n1n2out_sizefa1fa2r'   startends                  r   r#   r#   P   s   F	x|bhrl""RBRXb\A%% 
x}rx}33HL$(-THM48>TR$$EXb\28B<B{,,R"Wq[99H
#b(

C
#b(

C
$sSy(
#
#Cv~~R!s	aA&bj	!VRsCE E 	E c59n
CzTk#::e%:(((r   c                 >   d}| j         |j         k     r|| }} d|j         dz  z
  }t          j        | |          }| j         |j         }}|                     |d          } |                    |d          }|dk    r!||z   dz
  }t          j        | |dz
            } n?|dk    r+|}|dz
  dz  |z   }t          j        | |dz
  |z
  |f          } n|dk    r||z
  dz   }| j        d         }	t          j        | ||f|	|	f          } t          | |d d d	         d
          }
|
S )Nr   r
   r+   Fr0   r   r-   r.   r*   )axis)	r   r3   r7   r<   padstridesr   
as_strided_dot_kernel)r=   r>   r   r?   r   r@   rA   rB   pad_sizestrideoutputs              r   r"   r"   w   sF   F	wRBRWq[R$$EWbgB	5u	%	%B	5u	%	%Bv~~7Q;Xb"q&!!	Fq=6)Xb26H,h788	7Q;Z]F		!"xnvv6F	G	GBR"XA...FMr   c                     t          j                    r#t          j        t          j        | |||          S |                     |||          S )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   rU   rU      sV    0  <!%*"#UEs< < < 	< 66%C6(((r   	cupy_cbrt)e->ef->fd->dzout0 = cbrt(in0)zJElementwise cube root function.

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

    )doccupy_square)b->bB->Bh->hH->Hi->iI->Il->lL->Lq->qQ->QrY   rZ   r[   F->F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
if (in0.real() == 0) {
  out0 = (in0.imag() > 0) - (in0.imag() < 0);
} else {
  out0 = (in0.real() > 0) - (in0.real() < 0);
}
	cupy_signr^   r_   r`   ra   rb   rc   rd   re   rf   rg   rY   rZ   r[   rh   ri   z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`

    cupy_heaviside)ee->e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_maximum??->?bb->bBB->Bhh->hHH->Hii->iII->Ill->lLL->Lqq->qQQ->Qrm   rn   ro   FF->F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)rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   )rm   out0 = fmax(in0, in1))rn   r   )ro   r   r|   r}   zTakes the maximum of two arrays elementwise.

    If NaN appears, it returns the other operand.

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

    	cupy_fmin)rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   )rm   out0 = fmin(in0, in1))rn   r   )ro   r   r|   r}   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))zffff->fr   )zdddd->dr   )zFfff->Fr   )zDddd->Dr   z
out0 = in0zQElementwise nan_to_num function.

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

    )r   r\   c                    |j         dv r+t          j        |j                                                   }|j         dvrd} n| 7|5|rt          j        |          j        nt          j        |          j        } nKt          j        |           rt          j        } n*t          j	        |           rt          j
        d| dk     z  z  } t          j        | |          S )NFDefdr   r*   )charr3   r   lowerfinfor   r   isnannanisinfinf
asanyarray)r   r   negs      r   _check_nan_infr     s    zT
5:++--..z	
s%(CDJu!!dj.?.?.C	A %H	A %Ha!e}$?1e$$$r   T        c                 ,   t          | t          j                  st          j        d|           }n|rt          j        |           n| }|j        }t          ||          }t          ||d          }t          ||d          }t          | ||||          S )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   FTrQ   )
isinstancer3   ndarrayr   
empty_liker   r   _nan_to_num)r   r1   r   posinfneginfr'   r   s          r   
nan_to_numr     s     a&& 0iA$(/doa   aIE
e
$
$CFE511FFE400Fq#vv37777r   d   c                    t          | j        j        t          j                  s| S |dk    r(t          j        | j        j                  }|j        |z  }t          j        t          j	        | j
                  |k               r| j        } | S )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   typer3   complexfloatingnumpyr   epsallabsoluteimagreal)r$   tolfs      r   real_if_closer     sx     aglD$899 
QwwK%%eckxaf%%+,, FHr   )for_each_devicec                     d}|dz  }d}| rd}nd}|dz  }|t           j        j        j        z  }d}t          j        |||d|	          S )
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 {
            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)r   )r3   _sortingsearch	_preambleElementwiseKernel)
is_complex	in_params
out_paramsr   codes        r   _get_interp_kernelr     sz    &IEEIJ )-(&&H$..HD4 !:t]XG G G Gr   c           
      8   |j         dk    s|j         dk    rt          d          |j        |j        k    rt          d          |j        dk    rt          d          | j        j        st          d          t          j        | |          }t          j        |t          j	                  s-t          d                    |t          j	                            ||dk    rt          d	          t          |          }d}d}|                     t          j	                  } |                    t          j	                  }| |z  } ||z  }t          j        |          }||         }||         }t          j        |d
d         |z
  ||dd         |z   f          }t          j        |d
d         ||dd         f          }|j        j        sJ |j        j        sJ |j        j        dk    rdnd}t          j        | j        |          }	t          j        || d          }
||d         nt          j        ||j                  }||d
         nt          j        ||j                  }t-          |dk              } || |
|||j        |||	           |	S )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   r3   common_typecan_castfloat64	TypeErrorformatabsr<   argsortconcatenater   r   emptyr2   searchsortedarrayr   )r   xpfpleftr   periodx_dtypeasort_xp	out_dtyperO   idxkerns               r   interpr     s   : 
w!||rw!||6777	w"'?@@@	w!||:;;;7 /! #. / / 	/q"%%G=$,// 8 C668 8 	8  Q;;>???VHHT\""YYt|$$ 	
V
f<##\\r"##wv~r2ac76>BCCr"##wBqsG455x$$$$x$$$$ x}++IZy111F

B
0
0
0CL2a55djrx&@&@DmBrFFE28)D)DEi3.//DDCR$v666Mr   )r   )N)Tr   NN)r   )NNN).r3   cupyx.scipy.fftr8   r   
cupy._corer   rT   r   cupy.libr   r   ReductionKernelrL   r   r   r(   r#   r"   rU   sqrt
sqrt_fixedcreate_ufunccbrtsquarer   fabs_unsigned_sign_complex_sign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`              . . . . . .       " " " " " "  $e#	 
 
 
         F$) $) $)N  8) ) ) )D J z u			 	 	 
	5		
	 	
	 	
	 > u				 		 		 " ufn%v/Gfn%v/Gfn%vvvmv}57 #		 	 	  E	  	(
-
%
gw'7Ggw~~~~~  	 !U%4 4 4*-
%
gw'7Ggw~~~~~  	 !U%4 4 4* u 		 	 	$ u 		 	 	$ & !e 0 !	!	 	 	.% % % %8 8 8 8&   , D))'G 'G *)'GTL L L L L Lr   