o
    i                     @   sh   d dl Z d dlmZ d dlmZ d dlmZ dd Zedfdd	Z	dddZ
edfddZdddZdS )    N)cuda)_new_like_order_and_strides)internalc                 C   s:   |d u r| d ur| j }|S t|tr|f}|S t|}|S )N)shape
isinstanceinttuple)ar    r
   P/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/cupyx/_pinned_array.py_update_shape   s   
r   Cc                 C   s@   t d| } t| t|j }t|}tj| |||d}|S )a"  Returns a new, uninitialized NumPy array with the given shape
    and dtype.

    This is a convenience function which is just :func:`numpy.empty`,
    except that the underlying memory is pinned/pagelocked.

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

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

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

    N)dtypebufferorder)	r   r   prodnumpyr   itemsizer   alloc_pinned_memoryndarray)r   r   r   nbytesmemoutr
   r
   r   empty_pinned   s
   

r   Kc           
      C   sx   |durt d|du r| j}t| |}t| |||dd\}}}t|t|j }t	|}tj
|||||d}	|	S )a  Returns a new, uninitialized NumPy array with the same shape and dtype
    as those of the given array.

    This is a convenience function which is just :func:`numpy.empty_like`,
    except that the underlying memory is pinned/pagelocked.

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

    Args:
        a (numpy.ndarray or cupy.ndarray): Base array.
        dtype: 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:
        numpy.ndarray: A new array with same shape and dtype of ``a`` with
        elements not initialized.

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

    Nzsubok is not supported yetF)
get_memptr)r   r   stridesr   )	TypeErrorr   r   r   r   r   r   r   r   r   r   )
r	   r   r   subokr   r   _r   r   r   r
   r
   r   empty_like_pinned,   s   



r    c                 C   s    t | ||}tj|ddd |S )a  Returns a new, zero-initialized NumPy array with the given shape
    and dtype.

    This is a convenience function which is just :func:`numpy.zeros`,
    except that the underlying memory is pinned/pagelocked.

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

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

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

    r   unsafecasting)r   r   copyto)r   r   r   r   r
   r
   r   zeros_pinnedX   s   r%   c                 C   s$   t | ||||}tj|ddd |S )aj  Returns a new, zero-initialized NumPy array with the same shape and dtype
    as those of the given array.

    This is a convenience function which is just :func:`numpy.zeros_like`,
    except that the underlying memory is pinned/pagelocked.

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

    Args:
        a (numpy.ndarray or cupy.ndarray): Base array.
        dtype: 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:
        numpy.ndarray: An array filled with zeros.

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

    r   r!   r"   )r    r   r$   )r	   r   r   r   r   r   r
   r
   r   zeros_like_pinnedp   s   r&   )Nr   NN)r   cupyr   cupy._creation.basicr   
cupy._corer   r   floatr   r    r%   r&   r
   r
   r
   r   <module>   s    

,