
    
9j9                    V   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S%S jr  S&S jr	  S'S	 jr
  S(S
 jrS r " S S5      r\" SS9r\" SS9r\R                   " SSSSSSSSSSSS/\" S5      QSPSPSPSP7S 5      r\R                   " S!S"S 5      r\R                   " S!S#S$5      rg))    )annotationsN)_core)	bf16_loopc                   Uc&  [        S XU4 5       5      (       a  [        nO[        nUc  U nSn Uc  Sn[        [        R                  " X-
  U-  5      5      nUS::  a  [
        R                  " SUS9$ [        R                  " U5      R                  [        R                  :X  ab  US:  a  [        S5      eUS:X  a'  [
        R                  " X U-
  /[        R                  S9$ [
        R                  " U /[        R                  S9$ [
        R                  " U4US9n[        R                  " U5      R                  n[        U" U 5      U" U5      XSS9  U$ )a1  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`

c              3  z   #    U  H1  n[         R                  " [        U5      5      R                  S :H  v   M3     g7f)fN)numpydtypetypekind).0vals     O/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_creation/ranges.py	<genexpr>arange.<locals>.<genexpr>!   s/      /-3 {{49%**c1-s   9;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%      s,   ( } / -/ / /EE||uzz4<4/01Dqyzz$e,,{{5%++-!88  19::udl35;;GG::ugU[[99
**dWE
*C
++e

!
!C#e*c$i:J    TFc                *   [         R                  " X[        U5      5      nUc  Un[         R                  " U4US9nU(       a  US-
  OUnUS::  a#  US:  a  UR	                  U 5        [        S5      n	OH[        X-
  5      U-  n	[        U5      nU	S:X  a  [        XU -
  X5        O[        X	U5        U(       a  XS'   [         R                  " U[         R                  5      (       a  [         R                  " XwS9  UR                  USS	9nU(       a  Xy4$ U$ )
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.

r   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<   C   s    , 
		%uSz	2B}
**cV2
&C37SC
ax7HHUOU|T\"S(T{3;%eE\3DE-Gudll++

3 
**U*
'Cy
r&   c                   US:  a  [        S5      eU(       a  US-
  OUn[        R                  " U 5      n[        R                  " U5      n	U(       a  U	(       a  [        XX#XE5      $ U(       dR  [	        U [        R
                  5      (       a  U R                  R                  S:X  d  [        R                  " U 5      S-  n U	(       dR  [	        U[        R
                  5      (       a  UR                  R                  S:X  d  [        R                  " U5      S-  n[        R                  " X[        U5      5      n
Uc  U
nX-
  n[        R                  " U4U
S9n[        SSXS9  UR                  SS	UR                  -  -   5      nUS:  a0  X-  n[        R                  " US:H  5      (       a	  X-  nX-  nOX-  nO[        S
5      nX-  nX-  nU(       a
  US:  a  XS'   US:w  a  [        R                   " USU5      n[        R"                  " U[        R$                  5      (       a  [        R&                  " XS9  UR)                  USS9nU(       a  X4$ U$ )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         ?r   r)   )r*   )r   r(   r*   r+   Fr-   )
ValueErrorr   isscalarr<   
isinstancendarrayr
   r   asarrayr/   r   r   r   reshapendimr   moveaxisr3   r4   r5   r6   )r   r    r7   r8   r9   r
   axisr;   scalar_startscalar_stopr:   deltar#   r!   s                 r   linspacerK   }   s   @ Qw?@@37SC=='L--%KSGKK5$,,//EKK4D4D4KLL'#-E4..4::??c3I<<%+D			%uSz	2B}LE **cV2
&C#sC*
++edUZZ//
0C Qw{88DAIJC+C*C U|kLCC!GBqymmCD)udll++

3 
**U*
'Cy
r&   c                   [        XX#US9nUc  [        R                  " XG5      $ [        R                  " U5      R
                  S;   a  UR                  [        R                  5      n[        R                  " XG5      R                  U5      $ )a  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`

)r7   r8   rG   iu)rK   r   powerr   r
   r   r6   float64)r   r    r7   r8   baser
   rG   ys           r   logspacerR      sk    6 	#tDA}{{4## zz%%HHT\\";;t&&u--r&   c                    UR                  SS5      n[        UR                  SS5      5      n[        UR                  SS5      5      nU(       a&  [        SR                  [	        U5      S   5      5      eUS	;  a  [        S
5      eU  HH  nUR                  S:w  a  [        S5      e[        U[        R                  5      (       a  M?  [        S5      e   [        U 5      S::  a  [        U 5      $ / n[        U 5       H_  u  puUS:X  a	  US:X  a  SnOUS:X  a	  US:X  a  SnOUnSU-  [        S5      4-   S[        U 5      US-   -
  -  -   n	UR                  XY   5        Ma     U(       a  Un
O[	        [        R                  " U6 5      n
U(       a/  [!        [        U
5      5       H  nX   R#                  5       X'   M     [        U
5      $ )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:
    tuple of cupy.ndarray

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

indexingxyr.   TsparseFz2meshgrid() got an unexpected keyword argument '{}'r   )rU   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?   rE   rA   r   rB   lentuple	enumeratesliceappendbroadcast_arraysranger.   )xikwargsrT   r.   rV   xmeshesi	left_noneexpand_slices	meshes_brs              r   meshgridrl     s   : zz*d+H

64()D&**Xu-.FBIIVQ!" 	" |#MNN66Q;122!T\\**;<<	 
 2w!|RyF"tQI!q&II 9,+( CGy1}$=>? 	a&'  	..78	s9~&A$<,,.IL 'r&   c                  .    \ rS rSrSrSS jrS rS rSrg)	nd_gridiL  a^  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`

c                    Xl         g rX   rV   )selfrV   s     r   __init__nd_grid.__init__e  s    r&   c           
        [        U[        5      (       a  UR                  nUR                  nUR                  nUc  Sn[        U[
        5      (       al  [        U5      n[        U5      nUS:w  a  UR                  U-
  [        US-
  5      -  nUR                  U-   n[        R                  " SUS[        5      U-  U-   $ [        R                  " XCU5      $ / n[        n[        [        U5      5       H  nX   R                  nX   R                  nUc  SnUc  Sn[        U[
        5      (       a*  UR                  [        [        U5      5      5        [        nOCUR                  [        [        R                  " X   R                  U-
  US-  -  5      5      5        [        U[        5      (       d8  [        U[        5      (       d#  [        X   R                  [        5      (       d  M  [        nGM     U R                   (       a?  [#        Xg4[        U5      -  5       V	V
s/ s H  u  p[        R                  " XS9PM     nn	n
O[        R$                  " Xg5      n[        [        U5      5       H  nX   R                  nX   R                  nUc  SnUc  Sn[        U[
        5      (       a:  [        [        U5      5      nUS:w  a   X   R                  U-
  [        US-
  5      -  nX   U-  U-   X'   M     U R                   (       aj  [        R&                  /[        U5      -  n[        [        U5      5       H5  n[        S S 5      X'   X   [)        U5         X'   [        R&                  X'   M7     U$ s  sn
n	f )Nr   r   r>   r   )rA   r`   r!   r    r   complexabsr   r   r   r%   rc   r]   ra   mathr   rV   zipindicesnewaxisr^   )rq   keyr!   r    r   lengthr"   r$   k_x_tnnslobjs                r   __getitem__nd_grid.__getitem__h  s   c5!!88D88DIIE}$((4yT19HHu,dQh?Dxx${{1fa7$>FF{{555s3xA6;;DFLLE}|$((CD	N+		36;;#64#:"FGHJ4''ue,,sv{{E22! !" ;; #D&3t9*< =? =fb ++b+ =  ?B d(Bs4y!A6;;DFLLE}|$((3t9~19FKK%/5?BDUT\E)BE " ;;\\NSY.E3t9% t,eEl+<< & 	-?s   " M5c                    g)Nr    )rq   s    r   __len__nd_grid.__len__  s    r&   rp   N)F)	__name__
__module____qualname____firstlineno____doc__rr   r   r   __static_attributes__r   r&   r   rn   rn   L  s    0;zr&   rn   rp   cupy_arangezbb->bzBB->Bzhh->hzHH->Hzii->izII->Izll->lzLL->Lzqq->qzQQ->Qzee->er   z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)2   TFN)r   TFNr   )r   Tg      $@Nr   )
__future__r   rw   r	   r   r   
cupy._utilr   r%   r<   rK   rR   rl   rn   mgridogridcreate_ufuncr   r2   r1   r   r&   r   <module>r      s   "      4n BG7t GK^B CG#.LEPZ Zz 	ut ""gw'7Ggw0!*10/608?0-0 /0  $$
 ".. " r&   