o
    i}                     @   s   U d dl Z d dlmZ d dlZd dlmZ d dlmZmZm	Z	 d dl
mZ daeej ed< e ddd	 ZG d
d de	Zdd Zdd ZdS )    N)Optional)_len_torch_function_stack)	_pop_mode
_push_modeTorchFunctionModecontext_decoratorCURRENT_DEVICE   c                   C   s   h t jt jt jt jt jt jt jt jt j	t j
jt j
jt jt jt jt jt jt jt jjt jt jt jt jt jt jt jt jt jt jt jt j t j!t j"t j#t j$t j%t j&S N)'torchemptyempty_permutedempty_stridedempty_quantizedonesarangebartlett_windowblackman_windoweyefftfftfreqrfftfreqfullhamming_windowhann_windowkaiser_windowlinspacelogspacenestednested_tensorrandrandnrandintrandpermrangesparse_coo_tensorsparse_compressed_tensorsparse_csr_tensorsparse_csc_tensorsparse_bsr_tensorsparse_bsc_tensortril_indicestriu_indiceszerosasarraytensor	as_tensorscalar_tensor r3   r3   P/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/torch/utils/_device.py_device_constructors   s   	
 !"#$&'(r5   c                   @   s.   e Zd Zdd Zdd Zdd Zdd	d
ZdS )DeviceContextc                 C   s   t || _d S r   )r   device)selfr7   r3   r3   r4   __init__>   s   zDeviceContext.__init__c                 C   sB   t | _| ja dd tt D }t|  t|D ]}t| qd S )Nc                 S   s   g | ]}t  qS r3   )r   ).0_r3   r3   r4   
<listcomp>I   s    z+DeviceContext.__enter__.<locals>.<listcomp>)r	   
old_devicer7   r%   r   r   reversed)r8   	cur_stackmoder3   r3   r4   	__enter__A   s   
zDeviceContext.__enter__c                 C   st   | j ag }tt d D ]}t }t|trJ || qt dkr-t }t|ts-J t|D ]}t	| q1d S )Nr
   r   )
r=   r	   r%   r   r   
isinstancer6   appendr>   r   )r8   exc_typeexc_valexc_tbr?   r;   r@   r3   r3   r4   __exit__P   s   

zDeviceContext.__exit__r3   Nc                 C   s8   |pi }|t  v r|dd u r| j|d< ||i |S )Nr7   )r5   getr7   )r8   functypesargskwargsr3   r3   r4   __torch_function__c   s   
z DeviceContext.__torch_function__)r3   N)__name__
__module____qualname__r9   rA   rG   rM   r3   r3   r3   r4   r6   =   s
    r6   c                    s   t  fdd|S )Nc                      s    S r   r3   r3   r7   r3   r4   <lambda>l   s    z"device_decorator.<locals>.<lambda>r   )r7   rI   r3   rQ   r4   device_decoratork   s   rS   c                    s    fddS )z
    Set the default device inside of the wrapped function by decorating it with this function.

    If you would like to use this as a context manager, use device as a
    context manager directly, e.g., ``with torch.device(device)``.
    c                    s   t t | S r   )rS   r   r7   )rI   rQ   r3   r4   rR   v   s    zset_device.<locals>.<lambda>r3   rQ   r3   rQ   r4   
set_deviceo   s   rT   )	functoolstypingr   r   torch._Cr   torch.overridesr   r   r   torch.utils._contextlibr   r	   r7   __annotations__	lru_cacher5   r6   rS   rT   r3   r3   r3   r4   <module>   s   

..