
    `i/                        d dl Z d dlmZmZ d dlZd dlZd dlmZmZ d dl	m
Z
mZmZmZmZ edfdededed	ee         fd
Z	 d dddZ	 	 	 	 d!dee         dede
dddee         d	ee         fdZdd edfdedee         dededed	ee         fdZefdeded	ee         fdZedfdededed	ee         fdZ	 	 	 	 d!dee         dede
dddee         d	ee         fdZedfdededed	ee         fdZ	 	 	 	 d!dee         dede
dddee         d	ee         fdZ	 	 d"dedededed	ee         f
dZ	 	 	 	 d!dee         dedede
dddee         d	ee         fdZdS )#    N)AnyOptional)_get_strides_for_order_K_update_order_char)
_OrderKACF_OrderCF
_ShapeLike	DTypeLikeNDArrayCshapedtypeorderreturnc                 0    t          j        | ||          S )a  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`

    r   )cupyndarray)r   r   r   s      h/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_creation/basic.pyemptyr      s    & <uE2222    T)
get_memptrc          	      H   |                                 }|dvr"t          d                    |                    t          j        |          r|f}|dk    r|t          |          | j        k    rdS t          t          | j	        j
        | j	        j        t          |                              }|dk    rft          | t          j        |          |          }d}|t          j        |          n| j        }|rt%          j        ||          j        nd}|||fS |ddfS )zw
    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_stridesr1   #   s2    KKMME(((3::5AABBB~e  ||)c%jjAF.B.B"	ag2CJJ@ @ A AE ||*1ek%.@.@%HH#(#4ty!&7AKD...33tgv%%dD  r   r   	prototypesubokc                     |t          d          || j        }t          | |||          \  }}}|r|n| j        }t	          j        |||||          S )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`

    Nsubok is not supported yet)	TypeErrorr   r1   r   r   r   )r2   r   r   r3   r   r/   r0   s          r   
empty_liker7   C   sl    > 4555}85%( (E7F/EE	E<ufgu===r   NMkc                     || }t          | |f||          }||  k    s||k    r|S |                    |                              d           |S )a  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`

    N)r   r      )zerosdiagonalfill)r8   r9   r:   r   r   rets         r   eyerA   m   sa    4 	y
Ae5
1
1
1CQBww!q&&
LLOOJr   nc                 $    t          | |          S )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   )rA   )rB   r   s     r   identityrD      s     qr   c                 ^    t          j        | ||          }|                    d           |S )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   r<   )r   r   r?   r   r   r   r.   s       r   onesrG      s.    * 	UE///AFF1IIIHr   r.   c                     |t          d          || j        }t          | |||          \  }}}|r|n| j        }t	          j        |||||          } |                     d           | S )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`

    Nr5   r<   )r6   r   r1   r   r   r   r?   r.   r   r   r3   r   r/   r0   s          r   	ones_likerJ      s    < 4555}8E59>@ @E7F'EEEUE67E::AFF1IIIHr   c                 t    t          j        | ||          }|j                            d|j                   |S )a  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nbytesrF   s       r   r=   r=      s9    & 	UE///AF18$$$Hr   c                     |t          d          || j        }t          | |||          \  }}}|r|n| j        }t	          j        |||||          } | j                            d| j                   | S )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`

    Nr5   r   )	r6   r   r1   r   r   r   r-   rL   rM   rI   s          r   
zeros_likerO      s    < 4555}8E59>@ @E7F'EEEUE67E::AF18$$$Hr   
fill_valuec                     |;t          |t          j                  r|j        }nt	          j        |          j        }t          j        | ||          }t          j        ||d           |S )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`

    Nr   unsafecasting)
isinstancer   r   r   r!   arraycopyto)r   rP   r   r   r.   s        r   fullrX   *  sk    . }j$,// 	2$EEK
++1EUE///AK:x0000Hr   c                     |t          d          || j        }t          | |||          \  }}}|r|n| j        }t	          j        |||||          } t	          j        | |d           | S )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`

    Nr5   rR   rS   )r6   r   r1   r   r   r   rW   )r.   rP   r   r   r3   r   r/   r0   s           r   	full_likerZ   K  s    @ 4555}8E59>@ @E7F'EEEUE67E::AK:x0000Hr   )N)Nr   NN)Nr   )r*   typingr   r   r!   r   cupy._core.internalr   r   cupy.typing._typesr   r   r	   r
   r   floatr   r1   r7   intrA   rD   rG   rJ   r=   rO   rX   rZ    r   r   <module>ra      sR                      L L L L L L L L              !3 333 3 S\	3 3 3 3.  $!37! ! ! ! !D  &*'> '>3<'>'> '> 	'>
 
#'> S\'> '> '> '>X       C=    	 
   S\       F ).   I '#,    ( !   S\	   8  &*( (3<(( ( 	(
 
#( S\( ( ( (Z !   S\	   4  &*( (3<(( ( 	(
 
#( S\( ( ( (\  	   	
 S\   H  &** *3<** * 	*
 * 
#* S\* * * * * *r   