
    Gj                         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z  ed<    e j        d          d             Z G d d	e          Zd
 Zd ZdS )    N)_len_torch_function_stack)	_pop_mode
_push_modeTorchFunctionModecontext_decoratorCURRENT_DEVICE   c                     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     V/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/torch/utils/_device.py_device_constructorsr7      s   11 	1 		1
 	1 	
1 	1 	1 	1 		1 		1 		1 	
1 	1 	1  	!1" 	#1$ 	%1& 	"'1, 	
-1. 	/10 	112 	314 	516 	718 	&91: 	;1< 	=1> 	?1@ 	A1B 	C1D 	E1F 	G1H 	I1L 	M1N 	O1P 	Q1 1r5   c                   *    e Zd ZddZd Zd Zd	dZdS )
DeviceContextreturnNc                 F    t          j        |          | _        d | _        d S r   )r   device	prev_mode)selfr<   s     r6   __init__zDeviceContext.__init__E   s    l6**/3r5   c                    t           | _        | j        a d t          t	                                D             }t          |            t          |          D ].}t          |t                    r|| _	        t          |           /d S )Nc                 *    g | ]}t                      S r4   )r   ).0_s     r6   
<listcomp>z+DeviceContext.__enter__.<locals>.<listcomp>Q   s    MMMQY[[MMMr5   )
r	   
old_devicer<   r&   r   r   reversed
isinstancer9   r=   )r>   	cur_stackmodes      r6   	__enter__zDeviceContext.__enter__I   s    (
 NM%0I0K0K*L*LMMM	4Y'' 	! 	!D$.. !!%4    		! 	!r5   c                    | j         ag }t          t                      dz
            D ]I}t	                      }t          |t                    rt          d          |                    |           Jt                      dk    r2t	                      }t          |t                    st          d          | j	        t          | j	                   t          |          D ]}t          |           d S )Nr
   z@Found nested DeviceContext on the mode stack where none expectedr   z8Expected a DeviceContext at the bottom of the mode stack)rE   r	   r&   r   r   rG   r9   AssertionErrorappendr=   r   rF   )r>   exc_typeexc_valexc_tbrH   rC   rI   s          r6   __exit__zDeviceContext.__exit__[   s	   	 022Q677 	# 	#A;;D$.. $V   T""""$&&**;;DdM22 $N   >%t~&&&Y'' 	 	Dt	 	r5   r4   c                 x    |pi }|t                      v r|                    d          
| j        |d<    ||i |S )Nr<   )r7   getr<   )r>   functypesargskwargss        r6   __torch_function__z DeviceContext.__torch_function__v   sO    2'))))fjj.B.B.J#{F8tT$V$$$r5   )r:   N)r4   N)__name__
__module____qualname__r?   rJ   rQ   rX   r4   r5   r6   r9   r9   D   sZ        4 4 4 4! ! !$  6% % % % % %r5   r9   c                 *     t           fd|          S )Nc                       S r   r4   r<   s   r6   <lambda>z"device_decorator.<locals>.<lambda>   s    V r5   r   )r<   rT   s   ` r6   device_decoratorr`   ~   s    ^^^^T222r5   c                       f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                 H    t          t          j                  |           S r   )r`   r   r<   )rT   r<   s    r6   r_   zset_device.<locals>.<lambda>   s    (f)=)=tDD r5   r4   r^   s   `r6   
set_devicerc      s     EDDDDr5   )	functoolsr   torch._Cr   torch.overridesr   r   r   torch.utils._contextlibr   r	   r<   __annotations__	lru_cacher7   r9   r`   rc   r4   r5   r6   <module>rj      s          . . . . . . D D D D D D D D D D 5 5 5 5 5 5 '+t# * * * Q2 2 2l6% 6% 6% 6% 6%% 6% 6% 6%t3 3 3E E E E Er5   