U
    bB'                  	   @  s:  d dl mZ d dlmZmZmZmZmZ erTddlm	Z	m
Z
mZmZmZ d dlmZ ddlmZ d dlZdd	 Zdddd
ddddddddZdKddddddddddddZddddddddddZddddddddddZdLd ddd d!d"d!dddd#d$d%Zd&dd'd(d)Zddddddddd*d+d,Zddddddddd-d.d/Zddd0d1d!ddddd2dd3d4d5Zd6d7dd8d9d:d;d<Zddddddddd=d>Zddddddddd?d@Z d dAdd!ddBdCdDZ!d dAdd!ddBdEdFZ"dddddddddGdHZ#dddddddddIdJZ$dS )M    )annotations)TYPE_CHECKINGListOptionalTupleUnion   )ArrayDeviceDtypeNestedSequenceSupportsBufferProtocol)Sequence)_all_dtypesNc                 C  s(   dt  D ]}| |kr d S qtdd S )N)Nz)dtype must be one of the supported dtypes)r   
ValueError)dtyped r   G/tmp/pip-unpacked-wheel-cxuynqjx/numpy/array_api/_creation_functions.py_check_valid_dtype   s    r   )r   devicecopyzZUnion[Array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]zOptional[Dtype]zOptional[Device]z#Optional[Union[bool, np._CopyMode]]r	   )objr   r   r   returnc               C  s   ddl m} t| |dkr*td||dtjjfkrBtdt| |r|dk	rb| j	|krbd}|dtjj
fkr|tj| jd|d	S | S |dkrt| tr| d
ks| dk rtdtj| |d}||S )z~
    Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`.

    See its docstring for more information.
    r   r	   cpuNUnsupported device Fz!copy=False is not yet implementedNT)r   r   l            l         z&Integer out of bounds for array dtypesr   )_array_objectr	   r   r   npZ	_CopyModeZ	IF_NEEDEDNotImplementedError
isinstancer   ZALWAYS_newarray_arrayintOverflowErrorasarray)r   r   r   r   r	   resr   r   r   r(      s     
"r(   )r   r   zOptional[Union[int, float]]zUnion[int, float])stopstepstartr   r   r   c               C  sB   ddl m} t| |dkr*td||tj| |||dS )z|
    Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.

    See its docstring for more information.
    r   r   r   r   )r*   r+   r   )r   r	   r   r   r#   r    arange)r,   r*   r+   r   r   r	   r   r   r   r-   K   s
    r-   zUnion[int, Tuple[int, ...]])shaper   r   r   c                C  s>   ddl m} t| |dkr*td||tj| |dS )zz
    Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    emptyr.   r   r   r	   r   r   r   r/   a   s
    r/   )xr   r   r   c               C  s@   ddl m} t| |dkr*td||tj| j|dS )z
    Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    
empty_liker%   r1   r   r   r	   r   r   r   r2   t   s
    r2   )kr   r   r&   zOptional[int])n_rowsn_colsr4   r   r   r   c               C  sB   ddl m} t| |dkr*td||tj| |||dS )zv
    Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.

    See its docstring for more information.
    r   r   r   r   )Mr4   r   )r   r	   r   r   r#   r    eye)r5   r6   r4   r   r   r	   r   r   r   r8      s
    r8   object)r1   r   c                C  s   ddl m} |t| S )Nr   r   )r   r	   r#   r    from_dlpack)r1   r	   r   r   r   r:      s    r:   )r.   
fill_valuer   r   r   c                C  sp   ddl m} t| |dkr*td|t||rD|jdkrD|j}tj| ||d}|j	t
krftd||S )zx
    Array API compatible wrapper for :py:func:`np.full <numpy.full>`.

    See its docstring for more information.
    r   r   r   r   r   r   zInvalid input to full)r   r	   r   r   r"   ndimr%   r    fullr   r   	TypeErrorr#   )r.   r;   r   r   r	   r)   r   r   r   r=      s    
r=   )r;   r1   r   r   r   c               C  sX   ddl m} t| |dkr*td|tj| j||d}|jtkrNt	d|
|S )z
    Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.

    See its docstring for more information.
    r   r   r   r   r   zInvalid input to full_like)r   r	   r   r   r    	full_liker%   r   r   r>   r#   )r1   r;   r   r   r	   r)   r   r   r   r?      s    
r?   T)r   r   endpointbool)numr,   r*   r   r   r@   r   c            	   C  sD   ddl m} t| |dkr*td||tj| ||||dS )z
    Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.

    See its docstring for more information.
    r   r   r   r   )r   r@   )r   r	   r   r   r#   r    linspace)r,   r*   rB   r   r   r@   r	   r   r   r   rC      s
    rC   Zxy)indexingstrzList[Array])arraysrD   r   c                   sR   ddl m  tdd |D dkr*td fddtjdd |D d	| iD S )
z
    Array API compatible wrapper for :py:func:`np.meshgrid <numpy.meshgrid>`.

    See its docstring for more information.
    r   r   c                 S  s   h | ]
}|j qS r   r   .0ar   r   r   	<setcomp>   s     zmeshgrid.<locals>.<setcomp>z,meshgrid inputs must all have the same dtypec                   s   g | ]}  |qS r   )r#   )rH   r$   r   r   r   
<listcomp>   s   zmeshgrid.<locals>.<listcomp>c                 S  s   g | ]
}|j qS r   )r%   rG   r   r   r   rK      s     rD   )r   r	   lenr   r    meshgrid)rD   rF   r   r   r   rM      s    
rM   c                C  s>   ddl m} t| |dkr*td||tj| |dS )zx
    Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    onesr0   r   r   r   rN      s
    rN   c               C  s@   ddl m} t| |dkr*td||tj| j|dS )z
    Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    	ones_liker%   r3   r   r   r   rO     s
    rO   r4   )r1   r4   r   c               C  s4   ddl m} | jdk rtd|tj| j|dS )zx
    Array API compatible wrapper for :py:func:`np.tril <numpy.tril>`.

    See its docstring for more information.
    r   r      z)x must be at least 2-dimensional for trilrP   )r   r	   r<   r   r#   r    trilr%   r1   r4   r	   r   r   r   rR   #  s    
rR   c               C  s4   ddl m} | jdk rtd|tj| j|dS )zx
    Array API compatible wrapper for :py:func:`np.triu <numpy.triu>`.

    See its docstring for more information.
    r   r   rQ   z)x must be at least 2-dimensional for triurP   )r   r	   r<   r   r#   r    triur%   rS   r   r   r   rT   1  s    
rT   c                C  s>   ddl m} t| |dkr*td||tj| |dS )zz
    Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    zerosr0   r   r   r   rU   ?  s
    rU   c               C  s@   ddl m} t| |dkr*td||tj| j|dS )z
    Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.

    See its docstring for more information.
    r   r   r   r   r   )r   r	   r   r   r#   r    
zeros_liker%   r3   r   r   r   rV   R  s
    rV   )Nr   )N)%
__future__r   typingr   r   r   r   r   _typingr	   r
   r   r   r   collections.abcr   Z_dtypesr   Znumpyr    r   r(   r-   r/   r2   r8   r:   r=   r?   rC   rM   rN   rO   rR   rT   rU   rV   r   r   r   r   <module>   sn   /    
    