o
    i3                     @  s  d dl mZ d dlmZmZmZmZmZ er*d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lm
Z d d	lmZ d
d ZdddddTddZ		dUddddVdd ZddddWd#d$ZddddXd&d'Z	dYd ddd(dZd.d/Zd[d1d2Zdddd\d4d5Zdddd]d6d7Z ddd8d9d^d=d>Z!d?d@d_dEdFZ"ddddWdGdHZ#ddddXdIdJZ$d dKd`dLdMZ%d dKd`dNdOZ&ddddWdPdQZ'ddddXdRdSZ(dS )a    )annotations)TYPE_CHECKINGListOptionalTupleUnion   )ArrayDeviceDtypeNestedSequenceSupportsBufferProtocol)Sequence)_all_dtypesN)r
   )runtimec                 C  s$   dt  D ]	}| |u r d S qtd)NNz)dtype must be one of the supported dtypes)r   
ValueError)dtyped r   _/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/cupy/array_api/_creation_functions.py_check_valid_dtype   s
   r   )r   devicecopyobjZUnion[Array, bool, int, float, NestedSequence[bool | int | float], SupportsBufferProtocol]r   Optional[Dtype]r   Optional[Device]r   Optional[bool]returnr	   c            	   C  s:  ddl m} t| |durt|tstd||du r!t }|du r)tdt| |rd|dur9| j|kr9d}|du rbt	 }zt
|j |tj| jd|d} W t
| | S t
| w | S |du ryt| try| d	ksu| d
k rytdt	 }zt
|j tj| |d}W t
| nt
| w ||S )z~
    Array API compatible wrapper for :py:func:`np.asarray <numpy.asarray>`.

    See its docstring for more information.
    r   r	   NUnsupported device Fz!copy=False is not yet implementedT)r   r   l            l         z&Integer out of bounds for array dtypesr   )_array_objectr	   r   
isinstance_Devicer   NotImplementedErrorr   r   	getDevice	setDeviceid_newnparray_arrayintOverflowErrorasarray)r   r   r   r   r	   prev_deviceresr   r   r   r0   !   s8   

"
r0   )r   r   stopOptional[Union[int, float]]stepUnion[int, float]startc            	   C     ddl m} t| |durt|tstd||du r!t }t }zt|j	 |
tj| |||dW t| S t| w )z|
    Array API compatible wrapper for :py:func:`np.arange <numpy.arange>`.

    See its docstring for more information.
    r   r    Nr!   )r3   r5   r   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   arange)r7   r3   r5   r   r   r	   r1   r   r   r   r9   Y      r9   shapeUnion[int, Tuple[int, ...]]c             	   C     ddl m} t| |durt|tstd||du r!t }t }zt|j	 |
tj| |dW t| S t| w )zz
    Array API compatible wrapper for :py:func:`np.empty <numpy.empty>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   emptyr;   r   r   r	   r1   r   r   r   r>   v      r>   xc            	   C     ddl m} t| |durt|tstd||du r!t }t }zt|j	 |
tj| j|dW t| S t| w )z
    Array API compatible wrapper for :py:func:`np.empty_like <numpy.empty_like>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   
empty_liker-   rA   r   r   r	   r1   r   r   r   rC         rC   )kr   r   n_rowsr.   n_colsOptional[int]rF   c            	   C  r8   )zv
    Array API compatible wrapper for :py:func:`np.eye <numpy.eye>`.

    See its docstring for more information.
    r   r    Nr!   )MrF   r   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   eye)rG   rH   rF   r   r   r	   r1   r   r   r   rK      r:   rK   objectc                C  s   ddl m} |t| S )z
    Array API compatible wrapper for :py:func:`np.from_dlpack <numpy.from_dlpack>`.

    See its docstring for more information.
    r   r    )r#   r	   r*   r+   from_dlpack)rA   r	   r   r   r   rM      s   rM   
fill_valuec             	   C  s   ddl m} t| |durt|tstd||du r!t }t||r.|jdkr.|j}t	 }zt
|j tj| ||d}W t
| nt
| w |jtvrWtd||S )zx
    Array API compatible wrapper for :py:func:`np.full <numpy.full>`.

    See its docstring for more information.
    r   r    Nr!   r   r"   zInvalid input to full)r#   r	   r   r$   r%   r   ndimr-   r   r'   r(   r)   r+   fullr   r   	TypeErrorr*   )r;   rN   r   r   r	   r1   r2   r   r   r   rP      s    

rP   c            	   C  s   ddl m} t| |durt|tstd||du r!t }t||r.|jdkr.|j}t	 }zt
|j tj| j||d}W t
| nt
| w |jtvrXtd||S )z
    Array API compatible wrapper for :py:func:`np.full_like <numpy.full_like>`.

    See its docstring for more information.
    r   r    Nr!   r   r"   zInvalid input to full_like)r#   r	   r   r$   r%   r   rO   r-   r   r'   r(   r)   r+   	full_liker   r   rQ   r*   )rA   rN   r   r   r	   r1   r2   r   r   r   rR      s    

rR   T)r   r   endpointnumrS   boolc            	   C  s   ddl m} t| |du rt }nt|tstd|t }zt|j	 |
tj| ||||dW t| S t| w )z
    Array API compatible wrapper for :py:func:`np.linspace <numpy.linspace>`.

    See its docstring for more information.
    r   r    Nr!   )r   rS   )r#   r	   r   r%   r$   r   r   r'   r(   r)   r*   r+   linspace)r7   r3   rT   r   r   rS   r	   r1   r   r   r   rV     s   
rV   xy)indexingarraysrX   strList[Array]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><      zmeshgrid.<locals>.<setcomp>z,meshgrid inputs must all have the same dtypec                   s   g | ]}  |qS r   )r*   )r]   r,   r    r   r   
<listcomp>?  s    zmeshgrid.<locals>.<listcomp>c                 S  s   g | ]}|j qS r   )r-   r\   r   r   r   ra   A  r`   rX   )r#   r	   lenr   r+   meshgrid)rX   rY   r   r    r   rc   1  s   
rc   c             	   C  r=   )zx
    Array API compatible wrapper for :py:func:`np.ones <numpy.ones>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   onesr?   r   r   r   rd   E  r@   rd   c            	   C  rB   )z
    Array API compatible wrapper for :py:func:`np.ones_like <numpy.ones_like>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   	ones_liker-   rD   r   r   r   re   _  rE   re   rF   c               C  4   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 trilrf   )r#   r	   rO   r   r*   r+   trilr-   rA   rF   r	   r   r   r   ri   v     
ri   c               C  rg   )zx
    Array API compatible wrapper for :py:func:`np.triu <numpy.triu>`.

    See its docstring for more information.
    r   r    rh   z)x must be at least 2-dimensional for triurf   )r#   r	   rO   r   r*   r+   triur-   rj   r   r   r   rl     rk   rl   c             	   C  r=   )zz
    Array API compatible wrapper for :py:func:`np.zeros <numpy.zeros>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   zerosr?   r   r   r   rm     r@   rm   c            	   C  rB   )z
    Array API compatible wrapper for :py:func:`np.zeros_like <numpy.zeros_like>`.

    See its docstring for more information.
    r   r    Nr!   r"   )r#   r	   r   r$   r%   r   r   r'   r(   r)   r*   r+   
zeros_liker-   rD   r   r   r   rn     rE   rn   )
r   r   r   r   r   r   r   r   r   r	   )Nr   )r3   r4   r5   r6   r7   r6   r   r   r   r   r   r	   )r;   r<   r   r   r   r   r   r	   )rA   r	   r   r   r   r   r   r	   r   )rG   r.   rH   rI   rF   r.   r   r   r   r   r   r	   )rA   rL   r   r	   )
r;   r<   rN   r6   r   r   r   r   r   r	   )
rN   r6   rA   r	   r   r   r   r   r   r	   )rT   r.   r7   r6   r3   r6   r   r   r   r   rS   rU   r   r	   )rY   r	   rX   rZ   r   r[   )rA   r	   rF   r.   r   r	   ))
__future__r   typingr   r   r   r   r   _typingr	   r
   r   r   r   collections.abcr   _dtypesr   cupyr+   	cupy.cudar%   cupy_backends.cuda.apir   r   r0   r9   r>   rC   rK   rM   rP   rR   rV   rc   rd   re   ri   rl   rm   rn   r   r   r   r   <module>   sn    ; 
')