o
    U)i                     @   s   U d dl mZ d dlZd dlmZmZmZ d dlmZ d dl	m
Z
 d dl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 )    )OptionalN)TorchFunctionMode	_pop_mode
_push_modecontext_decorator)_len_torch_function_stack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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&t j't j(t j%S N))torchemptyZempty_permutedZempty_stridedZempty_quantizedZonesZarangeZbartlett_windowZblackman_windoweyeZfftZfftfreqZrfftfreqfullfillZhamming_windowZhann_windowZkaiser_windowZlinspaceZlogspacenestedZnested_tensorZrandZrandnrandintZrandpermrangeZsparse_coo_tensorZsparse_compressed_tensorZsparse_csr_tensorZsparse_csc_tensorZsparse_bsr_tensorZsparse_bsc_tensorZtril_indicesZtriu_indicesZvanderZzerosZasarrayZtensorZ	as_tensorZscalar_tensor r   r   _/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/torch/utils/_device.py_device_constructors   s   	
 !"#$%&')*+,r   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)selfr   r   r   r   __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 r   )r   ).0_r   r   r   
<listcomp>I   s    z+DeviceContext.__enter__.<locals>.<listcomp>)r	   
old_devicer   r   r   r   reversed)r   	cur_stackmoder   r   r   	__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   
isinstancer   appendr   r   )r   exc_typeexc_valexc_tbr    r   r!   r   r   r   __exit__Q   s   

zDeviceContext.__exit__r   Nc                 C   s8   |pi }|t  v r|dd u r| j|d< ||i |S )Nr   )r   getr   )r   functypesargskwargsr   r   r   __torch_function__d   s   
z DeviceContext.__torch_function__)r   N)__name__
__module____qualname__r   r"   r(   r.   r   r   r   r   r   =   s
    r   c                    s   t  fdd|S )Nc                      s    S r   r   r   r   r   r   <lambda>l   s    z"device_decorator.<locals>.<lambda>r   )r   r*   r   r2   r   device_decoratork   s   r4   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   )r4   r   r   )r*   r2   r   r   r3   u   s    zset_device.<locals>.<lambda>r   r2   r   r2   r   
set_devicen   s   r5   )typingr   r   Ztorch.overridesr   r   r   Ztorch.utils._contextlibr   Ztorch._Cr   	functoolsr	   r   __annotations__	lru_cacher   r   r4   r5   r   r   r   r   <module>   s   
1.