
    `i9                        d dl Z d dlZd dlZd dlmZ ddZ	 	 ddZ	 	 dd	Z	 	 ddZd Z G d de	          Z
 e
d          Z e
d          Z ej        ddd          Z ej        ddd          Z ej        ddd          ZdS )    N)_core   c                    |+t          d | ||fD                       rt          }nt          }|| }d} |d}t          t          j        || z
  |z                      }|dk    rt          j        d|          S t          j        |          j        t          j	        k    ra|dk    rt          d          |dk    r%t          j        | | |z
  gt          j	                  S t          j        | gt          j	                  S t          j        |f|          }t          j        |          j        }t           ||            ||          ||           |S )	ae  Returns an array with evenly spaced values within a given interval.

    Values are generated within the half-open interval [start, stop). The first
    three arguments are mapped like the ``range`` built-in function, i.e. start
    and step are optional.

    Args:
        start: Start of the interval.
        stop: End of the interval.
        step: Step width between each pair of consecutive values.
        dtype: Data type specifier. It is inferred from other arguments by
            default.

    Returns:
        cupy.ndarray: The 1-D array of range values.

    .. seealso:: :func:`numpy.arange`

    Nc              3   j   K   | ].}t          j        t          |                    j        d k    V  /dS )fN)numpydtypetypekind).0vals     i/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_creation/ranges.py	<genexpr>zarange.<locals>.<genexpr>   sN       / / {499%%*c1 / / / / / /    r   r   )r   r	      zMarange() is only supported for booleans when the result has at most length 2.)anyfloatintr   ceilcupyemptyr	   r
   bool_	TypeErrorarray_arange_ufunc)startstopstepr	   sizerettyps          r   aranger#   	   ss   ( } / / $-/ / / / / 	EEE||uz4%<4/0011Dqyyz$e,,,,{5%+--!888   199:uedl35;GGGG:ugU[9999
*dWE
*
*
*C
+e


!C##e**cc$iiE::::Jr   2   TFc                 J   t          j        | |t          |                    }||}t          j        |f|          }|r|dz
  n|}|dk    r+|dk    r|                    |            t          d          }	nXt          || z
            |z  }	t          |          }|	dk    rt          | || z
  ||           nt          | |	|           |r||d<   t          j        |t           j                  rt          j	        ||           |
                    |d	
          }|r||	fS |S )a  Returns an array with evenly-spaced values within a given interval.

    Instead of specifying the step width like :func:`cupy.arange`, this
    function requires the total number of elements specified.

    Args:
        start: Start of the interval.
        stop: End of the interval.
        num: Number of elements.
        endpoint (bool): If ``True``, the stop value is included as the last
            element. Otherwise, the stop value is omitted.
        retstep (bool): If ``True``, this function returns (array, step).
            Otherwise, it returns only the array.
        dtype: Data type specifier. It is inferred from the start and stop
            arguments by default.

    Returns:
        cupy.ndarray: The 1-D array of ranged values.

    Nr   r   r   nan        outFcopy)r   result_typer   r   fill_linspace_ufunc_underflow_linspace_ufunc
issubdtypeintegerfloorastype)
r   r   numendpointretstepr	   dtr!   divr   s
             r   _linspace_scalarr:   @   s=   , 
	%uSzz	2	2B}
*cV2
&
&
&C
(377SC
axx77HHUOOOU||TE\""S(T{{3;;%eTE\3DDDDE4--- 	CGudl++ !
3C    
**U*
'
'C Dy
r   c                 J   |dk     rt          d          |r|dz
  n|}t          j        |           }t          j        |          }	|r|	rt          | |||||          S |sAt	          | t          j                  r| j        j        dk    st          j        |           dz  } |	sAt	          |t          j                  r|j        j        dk    st          j        |          dz  }t          j	        | |t          |                    }
||
}|| z
  }t          j        |f|
          }t          dd||
           |                    d	d
|j        z  z             }|dk    r.||z  }t          j        |dk              r||z  }||z  }n||z  }nt          d          }||z  }|| z  }|r|dk    r||d<   |dk    rt          j        |d|          }t          j        |t          j                  rt          j        ||           |                    |d          }|r||fS |S )a  Returns an array with evenly-spaced values within a given interval.

    Instead of specifying the step width like :func:`cupy.arange`, this
    function requires the total number of elements specified.

    Args:
        start (scalar or array_like): Starting value(s) of the sequence.
        stop (scalar or array_like): Ending value(s) of the sequence, unless
            ``endpoint`` is set to ``False``. In that case, the sequence
            consists of all but the last of ``num + 1`` evenly spaced samples,
            so that ``stop`` is excluded.  Note that the step size changes when
            ``endpoint`` is ``False``.
        num: Number of elements.
        endpoint (bool): If ``True``, the stop value is included as the last
            element. Otherwise, the stop value is omitted.
        retstep (bool): If ``True``, this function returns (array, step).
            Otherwise, it returns only the array.
        dtype: Data type specifier. It is inferred from the start and stop
            arguments by default.
        axis (int):  The axis in the result to store the samples.  Relevant
            only if start or stop are array-like.  By default ``0``, the
            samples will be along a new axis inserted at the beginning.
            Use ``-1`` to get an axis at the end.

    Returns:
        cupy.ndarray: The 1-D array of ranged values.

    .. seealso:: :func:`numpy.linspace`

    r   z$linspace with num<0 is not supportedr   r         ?Nr   r'   )r(   )r   r&   r(   r)   Fr+   )
ValueErrorr   isscalarr:   
isinstancendarrayr	   r   asarrayr-   r   r   r   reshapendimr   moveaxisr1   r2   r3   r4   )r   r   r5   r6   r7   r	   axisr9   scalar_startscalar_stopr8   deltar!   r   s                 r   linspacerI   z   s`   @ Qww?@@@
(377SC=''L-%%K L LtS(GUKKK .5$,// 	.EK4D4K4KL''#-E ,4.. 	,4:?c3I3I<%%+D		%uSzz	2	2B}5LE *cV2
&
&
&C#sCr****
++edUZ//
0
0C Qwws{8DAI 	3JC+CC*CC U||Ek5LC C!GGBqyymCD))udl++ !
3C    
**U*
'
'C Dy
r         $@c                    t          | ||||          }|t          j        ||          S t          j        |          j        dv r|                    t          j                  }t          j        ||                              |          S )a2  Returns an array with evenly-spaced values on a log-scale.

    Instead of specifying the step width like :func:`cupy.arange`, this
    function requires the total number of elements specified.

    Args:
        start: Start of the interval.
        stop: End of the interval.
        num: Number of elements.
        endpoint (bool): If ``True``, the stop value is included as the last
            element. Otherwise, the stop value is omitted.
        base (float): Base of the log space. The step sizes between the
            elements on a log-scale are the same as ``base``.
        dtype: Data type specifier. It is inferred from the start and stop
            arguments by default.
        axis (int):  The axis in the result to store the samples.  Relevant
            only if start or stop are array-like.  By default ``0``, the
            samples will be along a new axis inserted at the beginning.
            Use ``-1`` to get an axis at the end.
    Returns:
        cupy.ndarray: The 1-D array of ranged values.

    .. seealso:: :func:`numpy.logspace`

    )r5   r6   rE   Niu)rI   r   powerr   r	   r   r4   float64)r   r   r5   r6   baser	   rE   ys           r   logspacerQ      s    6 	#tDDDA}{4### z%%%HHT\"";tQ&&u---r   c                     |                     dd          }t          |                     dd                    }t          |                     dd                    }|r5t          d                    t	          |          d                             |d	vrt          d
          | D ]E}|j        dk    rt          d          t          |t          j	                  st          d          Ft          |           dk    rt	          |           S g }t          |           D ]o\  }}|dk    r	|dk    rd}n|dk    r	|dk    rd}n|}d|z  t          d          fz   dt          |           |dz   z
  z  z   }	|                    ||	                    p|r|}
nt	          t          j        |           }
|r<t          t          |
                    D ]}|
|                                         |
|<    |
S )a  Return coordinate matrices from coordinate vectors.

    Given one-dimensional coordinate arrays ``x1, x2, ... , xn`` this
    function makes N-D grids.

    For one-dimensional arrays ``x1, x2, ... , xn`` with lengths
    ``Ni = len(xi)``, this function returns ``(N1, N2, N3, ..., Nn)`` shaped
    arrays if indexing='ij' or ``(N2, N1, N3, ..., Nn)`` shaped arrays
    if indexing='xy'.

    Unlike NumPy, CuPy currently only supports 1-D arrays as inputs.

    Args:
        xi (tuple of ndarrays): 1-D arrays representing the coordinates
            of a grid.
        indexing ({'xy', 'ij'}, optional): Cartesian ('xy', default) or
            matrix ('ij') indexing of output.
        sparse (bool, optional): If ``True``, a sparse grid is returned in
            order to conserve memory. Default is ``False``.
        copy (bool, optional): If ``False``, a view
            into the original arrays are returned. Default is ``True``.

    Returns:
        list of cupy.ndarray

    .. seealso:: :func:`numpy.meshgrid`

    indexingxyr,   TsparseFz2meshgrid() got an unexpected keyword argument '{}'r   )rT   ijz.Valid values for `indexing` are 'xy' and 'ij'.r   zinput has to be 1dzinput has to be cupy.ndarrayNN)popboolr   formatlistr=   rC   r?   r   r@   len	enumeratesliceappendbroadcast_arraysranger,   )xikwargsrS   r,   rU   xmeshesi	left_noneexpand_slices	meshes_brs              r   meshgridrj     s!   : zz*d++H

64(())D&**Xu--..F "BIIVQ! !" " 	" |##MNNN = =6Q;;1222!T\** 	=;<<<	=
2ww!||BxxF" ( (1tQII!q&&III 9,++( CGGy1}$=>? 	a&'''' 9		.788	 /s9~~&& 	/ 	/A$Q<,,..IaLLr   c                   &    e Zd ZdZddZd Zd ZdS )nd_grida  Construct a multi-dimensional "meshgrid".

    ``grid = nd_grid()`` creates an instance which will return a mesh-grid
    when indexed.  The dimension and number of the output arrays are equal
    to the number of indexing dimensions.  If the step length is not a
    complex number, then the stop is not inclusive.

    However, if the step length is a **complex number** (e.g. 5j), then the
    integer part of its magnitude is interpreted as specifying the
    number of points to create between the start and stop values, where
    the stop value **is inclusive**.

    If instantiated with an argument of ``sparse=True``, the mesh-grid is
    open (or not fleshed out) so that only one-dimension of each returned
    argument is greater than 1.

    Args:
        sparse (bool, optional): Whether the grid is sparse or not.
            Default is False.

    .. seealso:: :data:`numpy.mgrid` and :data:`numpy.ogrid`

    Fc                     || _         d S rW   rU   )selfrU   s     r   __init__znd_grid.__init__b  s    r   c           
         t          |t                    r|j        }|j        }|j        }|d}t          |t
                    rmt          |          }t          |          }|dk    r|j        |z
  t          |dz
            z  }|j        |z   }t          j
        d|dt                    |z  |z   S t          j
        |||          S g }t          }t          t          |                    D ]
}||         j        }||         j        }|d}|d}t          |t
                    r7|                    t          t          |                               t          }nH|                    t          t          j        ||         j        |z
  |dz  z                                 t          |t                    s5t          |t                    s t          ||         j        t                    rt          }| j        r,d t#          ||ft          |          z            D             }	nt          j        ||          }	t          t          |                    D ]}||         j        }||         j        }|d}|d}t          |t
                    rEt          t          |                    }|dk    r#||         j        |z
  t          |dz
            z  }|	|         |z  |z   |	|<   | j        r|t          j        gt          |          z  }
t          t          |                    D ]B}t          d d           |
|<   |	|         t)          |
                   |	|<   t          j        |
|<   C|	S )Nr   r   r<   c                 @    g | ]\  }}t          j        ||           S )r   )r   r#   )r   _x_ts      r   
<listcomp>z'nd_grid.__getitem__.<locals>.<listcomp>  s;     ? ? ?b" +b+++ ? ? ?r   )r?   r^   r   r   r   complexabsr   r   r   r#   ra   r\   r_   mathr   rU   zipindicesnewaxistuple)ro   keyr   r   r   lengthr    r"   knnslobjs              r   __getitem__znd_grid.__getitem__e  sB   c5!! 	68D8DIE}$(( 64yyT199Hu,dQh?Dx${1fa77$>FF{5$555s3xx 	 	Aq6;DFLE}|$(( JCD		NN+++	3q6;#64#:"FGGHHJ J J4'' ue,,s1v{E22 ; 	)? ? #D3&3t99*< = =? ? ?BB dC((Bs4yy!! 	+ 	+Aq6;DFLE}|$(( C3t99~~199FK%/5??BDUT\E)BqEE; 	(\NSYY.E3t99%% ( ( t,,a1eEll+1<a	r   c                     dS )Nr    )ro   s    r   __len__znd_grid.__len__  s    qr   N)F)__name__
__module____qualname____doc__rp   r   r   r   r   r   rl   rl   I  sQ         0   ; ; ;z    r   rl   rn   cupy_arange)zbb->bzBB->Bzhh->hzHH->Hzii->izII->Izll->lzLL->Lzqq->qzQQ->Qzee->ezff->fdd->d)zFF->Fzout0 = in0 + float(i) * in1)zDD->Dzout0 = in0 + double(i) * in1zout0 = in0 + i * in1cupy_linspace)r   )zddd->dzout0 = in0 + i * in1 / in2)Nr   N)r$   TFN)r$   TFNr   )r$   TrJ   Nr   )rx   r   r   r   r#   r:   rI   rQ   rj   objectrl   mgridogridcreate_ufuncr   r0   r/   r   r   r   <module>r      s|           4 4 4 4n BG7 7 7 7t GK^ ^ ^ ^B CG#. #. #. #.LE E EPZ Z Z Z Zf Z Z Zz 	ut #"0   %%$ 
 /E. " "   r   