o
    ki                     @   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jdB 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   ]/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/utils/_device.py_device_constructors   s   	
 !"#$&'(r5   c                   @   s0   e Zd ZdddZdd Zdd Zdd
dZdS )DeviceContextreturnNc                 C   s   t || _d | _d S r   )r   device	prev_mode)selfr8   r3   r3   r4   __init__>   s   
zDeviceContext.__init__c                 C   sT   t | _| ja dd tt D }t|  t|D ]}t|tr#|| _	qt| qd S )Nc                 S   s   g | ]}t  qS r3   )r   ).0_r3   r3   r4   
<listcomp>K   s    z+DeviceContext.__enter__.<locals>.<listcomp>)
r	   
old_devicer8   r%   r   r   reversed
isinstancer6   r9   )r:   	cur_stackmoder3   r3   r4   	__enter__C   s   

zDeviceContext.__enter__c                 C   s   | j ag }tt d D ]}t }t|trtd|| qt dkr1t }t|ts1td| j	d ur;t
| j	 t|D ]}t
| q?d S )Nr
   z@Found nested DeviceContext on the mode stack where none expectedr   z8Expected a DeviceContext at the bottom of the mode stack)r?   r	   r%   r   r   rA   r6   AssertionErrorappendr9   r   r@   )r:   exc_typeexc_valexc_tbrB   r=   rC   r3   r3   r4   __exit__U   s(   





zDeviceContext.__exit__r3   c                 C   s8   |pi }|t  v r|dd u r| j|d< ||i |S )Nr8   )r5   getr8   )r:   functypesargskwargsr3   r3   r4   __torch_function__p   s   
z DeviceContext.__torch_function__)r7   N)r3   N)__name__
__module____qualname__r;   rD   rJ   rP   r3   r3   r3   r4   r6   =   s
    
r6   c                    s   t  fdd|S )Nc                      s    S r   r3   r3   r8   r3   r4   <lambda>y   s    z"device_decorator.<locals>.<lambda>r   )r8   rL   r3   rT   r4   device_decoratorx   s   rV   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   )rV   r   r8   )rL   rT   r3   r4   rU      s    zset_device.<locals>.<lambda>r3   rT   r3   rT   r4   
set_device|   s   rW   )	functoolstypingr   r   torch._Cr   torch.overridesr   r   r   torch.utils._contextlibr   r	   r8   __annotations__	lru_cacher5   r6   rV   rW   r3   r3   r3   r4   <module>   s   

.;