
    
9j3                       S SK Jr  S SKrS SKJr  S SKrS SKrS SKJrJ	r	  S SK
JrJrJrJrJr  \S4       SS jjr SSS	.S
 jjr    S           SS jjrSS \S4           SS jjr\4SS jjr\S4       SS jjr    S           SS jjr\S4       SS jjr    S           SS jjr  S         SS jjr    S             SS jjrSS.S jrg)     )annotationsN)Any)_get_strides_for_order_K_update_order_char)
_OrderKACF_OrderCF
_ShapeLike	DTypeLikeNDArrayCc                ,    [         R                  " XUS9$ )aw  Returns an array without initializing the elements.

Args:
    shape (int or tuple of ints): Dimensionalities of the array.
    dtype (data-type, optional): Data type specifier.
    order ({'C', 'F'}): Row-major (C-style) or column-major
        (Fortran-style) order.

Returns:
    cupy.ndarray: A new array with elements not initialized.

.. seealso:: :func:`numpy.empty`

order)cupyndarray)shapedtyper   s      N/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_creation/basic.pyemptyr      s    & <<E22    T)
get_memptrc          	     n   UR                  5       nUS;  a  [        SR                  U5      5      e[        R                  " U5      (       a  U4nUS:X  a  Ub  [        U5      U R                  :w  a  g[        [        U R                  R                  U R                  R                  [        U5      5      5      nUS:X  as  [        U [        R                  " U5      U5      nSnUb  [        R                   " U5      OU R"                  nU(       a  [$        R&                  " XaS9R(                  OSnX%U4$ USS4$ )zk
Determine order and strides as in NumPy's PyArray_NewLikeArray.

(see: numpy/core/src/multiarray/ctors.c)
)r   FKAzorder not understood: {}r   N)r   NNr   r   )upper
ValueErrorformatnumpyisscalarlenndimchrr   flagsc_contiguousf_contiguousordr   r   mathprodsizer   r   data)ar   r   r   r   stridesr+   memptrs           r   _new_like_order_and_stridesr0   %   s    KKME((3::5ABB~~e |)c%jAFF.B"	agg22CJ@ AE |*1ekk%.@%H#(#4tyy!&&7AD.33tv%%dD  r   c                    Ub  [        S5      eUc  U R                  n[        XX$5      u  p%nU(       a  UOU R                  n[        R
                  " XAXeU5      $ )a  Returns a new array with same shape and dtype of a given array.

This function currently does not support ``subok`` option.

Args:
    a (cupy.ndarray): Base array.
    dtype (data-type, optional): Data type specifier.
        The data type of ``a`` is used by default.
    order ({'C', 'F', 'A', or 'K'}): Overrides the memory layout of the
        result. ``'C'`` means C-order, ``'F'`` means F-order, ``'A'`` means
        ``'F'`` if ``a`` is Fortran contiguous, ``'C'`` otherwise.
        ``'K'`` means match the layout of ``a`` as closely as possible.
    subok: Not supported yet, must be None.
    shape (int or tuple of ints): Overrides the shape of the result. If
        ``order='K'`` and the number of dimensions is unchanged, will try
        to keep order, otherwise, ``order='C'`` is implied.

Returns:
    cupy.ndarray: A new array with same shape and dtype of ``a`` with
    elements not initialized.

.. seealso:: :func:`numpy.empty_like`

subok is not supported yet)	TypeErrorr   r0   r   r   r   )	prototyper   r   subokr   r.   r/   s          r   
empty_liker6   E   sX    > 455}8%(EFE	E<<fu==r   c                    Uc  U n[        X4X4S9nX * ::  d  X!:  a  U$ UR                  U5      R                  S5        U$ )aY  Returns a 2-D array with ones on the diagonals and zeros elsewhere.

Args:
    N (int): Number of rows.
    M (int): Number of columns. ``M == N`` by default.
    k (int): Index of the diagonal. Zero indicates the main diagonal,
        a positive index an upper diagonal, and a negative index a lower
        diagonal.
    dtype (data-type, optional): Data type specifier.
    order ({'C', 'F'}): Row-major (C-style) or column-major
        (Fortran-style) order.

Returns:
    cupy.ndarray: A 2-D array with given diagonals filled with ones and
    zeros elsewhere.

.. seealso:: :func:`numpy.eye`

)r   r      )zerosdiagonalfill)NMkr   r   rets         r   eyer@   o   sG    4 	y
e
1CBw!&
LLOJr   c                    [        XS9$ )a  Returns a 2-D identity array.

It is equivalent to ``eye(n, n, dtype)``.

Args:
    n (int): Number of rows and columns.
    dtype (data-type, optional): Data type specifier.

Returns:
    cupy.ndarray: A 2-D identity array.

.. seealso:: :func:`numpy.identity`

r   )r@   )nr   s     r   identityrC      s     qr   c                R    [         R                  " XUS9nUR                  S5        U$ )a  Returns a new array of given shape and dtype, filled with ones.

This function currently does not support ``order`` option.

Args:
    shape (int or tuple of ints): Dimensionalities of the array.
    dtype (data-type, optional): Data type specifier.
    order ({'C', 'F'}): Row-major (C-style) or column-major
        (Fortran-style) order.

Returns:
    cupy.ndarray: An array filled with ones.

.. seealso:: :func:`numpy.ones`

r   r8   )r   r   r;   r   r   r   r-   s       r   onesrF      s$    * 	U/AFF1IHr   c                    Ub  [        S5      eUc  U R                  n[        XUU5      u  p%nU(       a  UOU R                  n[        R
                  " XAXeU5      n U R                  S5        U $ )a  Returns an array of ones with same shape and dtype as a given array.

This function currently does not support ``subok`` option.

Args:
    a (cupy.ndarray): Base array.
    dtype (data-type, optional): Data type specifier.
        The dtype of ``a`` is used by default.
    order ({'C', 'F', 'A', or 'K'}): Overrides the memory layout of the
        result. ``'C'`` means C-order, ``'F'`` means F-order, ``'A'`` means
        ``'F'`` if ``a`` is Fortran contiguous, ``'C'`` otherwise.
        ``'K'`` means match the layout of ``a`` as closely as possible.
    subok: Not supported yet, must be None.
    shape (int or tuple of ints): Overrides the shape of the result. If
        ``order='K'`` and the number of dimensions is unchanged, will try
        to keep order, otherwise, ``order='C'`` is implied.

Returns:
    cupy.ndarray: An array filled with ones.

.. seealso:: :func:`numpy.ones_like`

r2   r8   )r3   r   r0   r   r   r   r;   r-   r   r   r5   r   r.   r/   s          r   	ones_likerI      sj    < 455}859>@EFEEU6E:AFF1IHr   c                |    [         R                  " XUS9nUR                  R                  SUR                  5        U$ )au  Returns a new array of given shape and dtype, filled with zeros.

Args:
    shape (int or tuple of ints): Dimensionalities of the array.
    dtype (data-type, optional): Data type specifier.
    order ({'C', 'F'}): Row-major (C-style) or column-major
        (Fortran-style) order.

Returns:
    cupy.ndarray: An array filled with zeros.

.. seealso:: :func:`numpy.zeros`

r   r   )r   r   r,   memset_asyncnbytesrE   s       r   r9   r9      s1    & 	U/AFF188$Hr   c                   Ub  [        S5      eUc  U R                  n[        XUU5      u  p%nU(       a  UOU R                  n[        R
                  " XAXeU5      n U R                  R                  SU R                  5        U $ )a  Returns an array of zeros with same shape and dtype as a given array.

This function currently does not support ``subok`` option.

Args:
    a (cupy.ndarray): Base array.
    dtype (data-type, optional): Data type specifier.
        The dtype of ``a`` is used by default.
    order ({'C', 'F', 'A', or 'K'}): Overrides the memory layout of the
        result. ``'C'`` means C-order, ``'F'`` means F-order, ``'A'`` means
        ``'F'`` if ``a`` is Fortran contiguous, ``'C'`` otherwise.
        ``'K'`` means match the layout of ``a`` as closely as possible.
    subok: Not supported yet, must be None.
    shape (int or tuple of ints): Overrides the shape of the result. If
        ``order='K'`` and the number of dimensions is unchanged, will try
        to keep order, otherwise, ``order='C'`` is implied.

Returns:
    cupy.ndarray: An array filled with zeros.

.. seealso:: :func:`numpy.zeros_like`

r2   r   )	r3   r   r0   r   r   r   r,   rK   rL   rH   s          r   
zeros_likerN     sw    < 455}859>@EFEEU6E:AFF188$Hr   c                    UcL  [        U[        R                  5      (       a  UR                  nO [        R
                  " U5      R                  n[        R                  " XUS9n[        R                  " XASS9  U$ )a  Returns a new array of given shape and dtype, filled with a given value.

This function currently does not support ``order`` option.

Args:
    shape (int or tuple of ints): Dimensionalities of the array.
    fill_value: A scalar value to fill a new array.
    dtype (data-type, optional): Data type specifier.
    order ({'C', 'F'}): Row-major (C-style) or column-major
        (Fortran-style) order.

Returns:
    cupy.ndarray: An array filled with ``fill_value``.

.. seealso:: :func:`numpy.full`

r   unsafecasting)
isinstancer   r   r   r    arraycopyto)r   
fill_valuer   r   r-   s        r   fullrW   ,  s\    . }j$,,//$$EKK
+11EU/AKKx0Hr   c                    Ub  [        S5      eUc  U R                  n[        XUU5      u  p6nU(       a  UOU R                  n[        R
                  " XRXvU5      n [        R                  " XSS9  U $ )a  Returns a full array with same shape and dtype as a given array.

This function currently does not support ``subok`` option.

Args:
    a (cupy.ndarray): Base array.
    fill_value: A scalar value to fill a new array.
    dtype (data-type, optional): Data type specifier.
        The dtype of ``a`` is used by default.
    order ({'C', 'F', 'A', or 'K'}): Overrides the memory layout of the
        result. ``'C'`` means C-order, ``'F'`` means F-order, ``'A'`` means
        ``'F'`` if ``a`` is Fortran contiguous, ``'C'`` otherwise.
        ``'K'`` means match the layout of ``a`` as closely as possible.
    subok: Not supported yet, must be None.
    shape (int or tuple of ints): Overrides the shape of the result. If
        ``order='K'`` and the number of dimensions is unchanged, will try
        to keep order, otherwise, ``order='C'`` is implied.

Returns:
    cupy.ndarray: An array filled with ``fill_value``.

.. seealso:: :func:`numpy.full_like`

r2   rP   rQ   )r3   r   r0   r   r   r   rU   )r-   rV   r   r   r5   r   r.   r/   s           r   	full_likerY   M  sn    @ 455}859>@EFEEU6E:AKKx0Hr   copyc                  [        U [        R                  5      (       d  [        S[	        U 5       S35      eU R                  XS9$ )a  
Copies an array to a specified data type.

This function is an Array API compatible alternative to
`cupy.ndarray.astype`.

Parameters
----------
x : ndarray
    Input CuPy array to cast.
dtype : dtype
    Data type of the result.
copy : bool, optional
    Specifies whether to copy an array when the specified dtype matches
    the data type of the input array ``x``. If ``True``, a newly allocated
    array must always be returned. If ``False`` and the specified dtype
    matches the data type of the input array, the input array must be
    returned; otherwise, a newly allocated array must be returned.
    Defaults to ``True``.

Returns
-------
out : ndarray
    An array having the specified data type.

See Also
--------
ndarray.astype
numpy.astype

z&Input should be a CuPy array. It is a z	 instead.rZ   )rS   r   r   r3   typeastype)xr   r[   s      r   r^   r^   |  sF    @ a&&4T!WIYG
 	
 88E8%%r   )r   r	   r   r
   r   r   returnNDArray[Any])N)Nr   NN)r4   ra   r   DTypeLike | Noner   r   r5   Noner   _ShapeLike | Noner`   ra   )r<   intr=   z
int | Noner>   re   r   r
   r   r   r`   ra   )rB   re   r   r
   r`   ra   )r-   ra   r   rb   r   r   r5   rc   r   rd   r`   ra   )Nr   )
r   r	   rV   r   r   rb   r   r   r`   ra   )r-   ra   rV   r   r   rb   r   r   r5   rc   r   rd   r`   ra   )
__future__r   r)   typingr   r    r   cupy._core.internalr   r   cupy.typing._typesr   r   r	   r
   r   floatr   r0   r6   r@   rC   rF   rI   r9   rN   rW   rY   r^    r   r   <module>rl      s   "     L  !333 3 	3.  $!37!D #'#''>'>'> '> 	'>
 !'> '>X        	 
    F ). ( !  	8 #'#'((( ( 	(
 !( (Z !  	4 #'#'((( ( 	(
 !( (\ #'	   	
 H #'#'***  * 	*
 * !* *^ !% $&r   