o
    m9:j                     @   s   U d dl 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)_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 r2   r2   Z/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/torch/utils/_device.py_device_constructors   s   	
 !"#$&'(r4   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)selfr7   r2   r2   r3   __init__E   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 r2   )r   ).0_r2   r2   r3   
<listcomp>Q   s    z+DeviceContext.__enter__.<locals>.<listcomp>)
r   
old_devicer7   r$   r   r   reversed
isinstancer5   r8   )r9   	cur_stackmoder2   r2   r3   	__enter__I   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   r@   r5   AssertionErrorappendr8   r   r?   )r9   exc_typeexc_valexc_tbrA   r<   rB   r2   r2   r3   __exit__[   s(   





zDeviceContext.__exit__r2   c                 C   s8   |pi }|t  v r|dd u r| j|d< ||i |S )Nr7   )r4   getr7   )r9   functypesargskwargsr2   r2   r3   __torch_function__v   s   
z DeviceContext.__torch_function__)r6   N)r2   N)__name__
__module____qualname__r:   rC   rI   rO   r2   r2   r2   r3   r5   D   s
    
r5   c                    s   t  fdd|S )Nc                      s    S r
   r2   r2   r7   r2   r3   <lambda>   s    z"device_decorator.<locals>.<lambda>r   )r7   rK   r2   rS   r3   device_decorator~   s   rU   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
   )rU   r   r7   )rK   rS   r2   r3   rT      s    zset_device.<locals>.<lambda>r2   rS   r2   rS   r3   
set_device   s   rV   )	functoolsr   torch._Cr   torch.overridesr   r   r   torch.utils._contextlibr   r   r7   __annotations__	lru_cacher4   r5   rU   rV   r2   r2   r2   r3   <module>   s   

6: