o
    W۷iT                     @  sP   d dl mZ d dlZd dlmZ dddZejfddZddd	Zdd
dZdS )    )annotationsN)_corec                 C  s*   t j| ||d} t |  std| S )a  Converts the given input to an array,
    and raises an error if the input contains NaNs or Infs.

    Args:
        a: array like.
        dtype: data type, optional
        order: {'C', 'F', 'A', 'K'}, optional

    Returns:
        cupy.ndarray: An array on the current device.

    .. note::
        This function performs device synchronization.

    .. seealso:: :func:`numpy.asarray_chkfinite`

    )dtypeorderz#array must not contain Infs or NaNs)cupyasarrayisfiniteall
ValueError)ar   r    r   M/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupy/_manipulation/kind.pyasarray_chkfinite   s   r   c                 C  s"   t |t js
t j}t j| |dS )a  Converts array elements to float type.

    Args:
        a (cupy.ndarray): Source array.
        dtype: str or dtype object, optional

    Returns:
        cupy.ndarray: The input array ``a`` as a float ndarray.

    .. seealso:: :func:`numpy.asfarray`

    r   )r   
issubdtypeinexactfloat64r   r   r   r   r   r   asfarray    s   r   c                 C  s   t | |S )am  Return an array laid out in Fortran order in memory.

    Args:
        a (~cupy.ndarray): The input array.
        dtype (str or dtype object, optional): By default, the data-type is
            inferred from the input data.

    Returns:
        ~cupy.ndarray: The input `a` in Fortran, or column-major, order.

    .. seealso:: :func:`numpy.asfortranarray`

    )r   asfortranarrayr   r   r   r   r   2   s   r   c              
     s  ddddddddd |s$zt j| |dW S  ty#   td|w z fdd|D }W n tyG   td	t|t    w d
}|ddhkrTtdd|v r`d}|	d nd|v rkd}|	d d|v rqdnd}zt j
| |||dd}W |S  ty   td|w )a  Return an array which satisfies the requirements.

    Args:
        a (~cupy.ndarray): The input array.
        dtype (str or dtype object, optional): The required data-type.
            If None preserve the current dtype.
        requirements (str or list of str): The requirements can be any
            of the following

            * 'F_CONTIGUOUS' ('F', 'FORTRAN') - ensure a Fortran-contiguous                 array. 
            * 'C_CONTIGUOUS' ('C', 'CONTIGUOUS') - ensure a C-contiguous array.

            * 'OWNDATA' ('O')      - ensure an array that owns its own data.

    Returns:
        ~cupy.ndarray: The input array ``a`` with specified requirements and
        type if provided.

    .. seealso:: :func:`numpy.require`

    CFOWNDATA)r   C_CONTIGUOUS
CONTIGUOUSr   F_CONTIGUOUSFORTRANOr   r   zIncorrect dtype "{}" providedc                   s   h | ]} |   qS r   )upper).0xpossible_flagsr   r   	<setcomp>g   s    zrequire.<locals>.<setcomp>z#Incorrect flag "{}" in requirementsAz%Cannot specify both "C" and "F" orderr   r   TNF)r   r   copysubok)r   
asanyarray	TypeErrorr
   formatKeyErrorsetkeyspopremovearray)r   r   requirementsr   r%   arrr   r!   r   requireC   sH   

r2   )NN)N)	
__future__r   r   r   r   r   r   r   r2   r   r   r   r   <module>   s    

