o
    0 i/                     @   s4  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
dZ	d+ddddZ				d,dee dede
dddee d	ee fddZdd edfdedee dededed	ee fddZefdeded	ee fddZedfdededed	ee fddZ				d,dee dede
dddee d	ee fd d!Zedfdededed	ee fd"d#Z				d,dee dede
dddee d	ee fd$d%Z		d-ded&ededed	ee f
d'd(Z				d,dee d&edede
dddee d	ee fd)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                 C   s   t j| ||d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    r   `/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/cupy/_creation/basic.pyempty   s   r   T)
get_memptrc                C   s   |  }|dvrtd|t|r|f}|dkr(|dur(t|| jkr(dS tt| j	j
| j	jt|}|dkrbt| t||}d}|durNt|n| j}|r[tj||d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numpyZisscalarlenndimchrr   flagsc_contiguousf_contiguousordr   r   mathprodsizer   r   data)ar   r   r   r   stridesr(   memptrr   r   r   _new_like_order_and_strides#   s"   


r-   r   	prototypesubokc                 C   sR   |durt d|du r| j}t| |||\}}}|r|n| j}t|||||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   r-   r   r   r   )r.   r   r   r/   r   r+   r,   r   r   r   
empty_likeC   s   
r2   NMkc                 C   sH   |du r| }t | |f||d}||  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      )zerosZdiagonalfill)r3   r4   r5   r   r   retr   r   r   eyem   s   r:   nc                 C   s   t | |d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   )r:   )r;   r   r   r   r   identity   s   r<   c                 C   s   t j| ||d}|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   r6   )r   r   r8   r   r   r   r*   r   r   r   ones   s   
r>   r*   c                 C   s`   |durt d|du r| j}t| |||\}}}|r|n| j}t|||||} | 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`

    Nr0   r6   )r1   r   r-   r   r   r   r8   r*   r   r   r/   r   r+   r,   r   r   r   	ones_like   s   

r@   c                 C   s$   t j| ||d}|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nbytesr=   r   r   r   r7      s   r7   c                 C   sf   |durt d|du r| j}t| |||\}}}|r|n| j}t|||||} | 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`

    Nr0   r   )	r1   r   r-   r   r   r   r)   rA   rB   r?   r   r   r   
zeros_like   s   
rC   
fill_valuec                 C   sL   |du rt |tjr|j}nt|j}tj| ||d}tj||d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Zcasting)
isinstancer   r   r   r   arraycopyto)r   rD   r   r   r*   r   r   r   full*  s   rJ   c                 C   sf   |durt d|du r| j}t| |||\}}}|r|n| j}t|||||} tj| |d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`

    Nr0   rE   rF   )r1   r   r-   r   r   r   rI   )r*   rD   r   r   r/   r   r+   r,   r   r   r   	full_likeK  s    
rK   )N)Nr   NN)Nr   )r&   typingr   r   r   r   Zcupy._core.internalr   r   Zcupy.typing._typesr   r   r   r	   r
   floatr   r-   r2   intr:   r<   r>   r@   r7   rC   rJ   rK   r   r   r   r   <module>   s    
"
,
#

-

.
$