o
    *n0j                     @  s  d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZmZmZmZmZ d dlmZmZmZ er@d dlmZmZ edeeeeeB eeB ZedeeedB eeZed	eeef ee Zejd#ddZd$ddZ d%ddZ!d&ddZ"d'ddZ#d(ddZ$d)d!d"Z%dS )*    )annotationsN)AnyTYPE_CHECKINGTypeVar)BackendIndexDispatchKeyNativeFunctionNativeFunctionsGroupNativeFunctionsViewGroup)contextST)CallableIteratorFF2F3g@NativeFunctionsGroup | NativeFunctionsViewGroup | NativeFunctionreturnIterator[None]c              	   #  s    t | tr
| j nt | tr| j n|  t fdd- tj j j	d d V  W d    n1 s5w   Y  W d    d S W d    d S 1 sMw   Y  d S )Nc                     s   d j  d j S )Nzin native_functions.yaml line z:
  )locfunc fr   W/home/wildlama/miniconda3/envs/lam_a2e/lib/python3.10/site-packages/torchgen/context.py<lambda><   s    z)native_function_manager.<locals>.<lambda>)!use_const_ref_for_mutable_tensorsZuse_ilistref_for_tensor_lists)

isinstancer	   outr
   viewr   localZparametrizer   Zpart_of_structured_group)r   r   r   r   native_function_manager-   s    

"r#   r   Callable[[F], T]c                   s   t  d fdd}|S )Nr   r   r   r   c                   s4   t |   | W  d    S 1 sw   Y  d S Nr#   r   r   r   r   wrapperJ   s   
$z%with_native_function.<locals>.wrapper)r   r   r   r   	functoolswrapsr   r(   r   r'   r   with_native_functionI      r-   Callable[[F, F2], T]c                      t  d	 fdd}|S )
Nr   r   f2r   r   r   c                   6   t |   | |W  d    S 1 sw   Y  d S r%   r&   )r   r1   r'   r   r   r(   S   s   
$z)with_native_function_and.<locals>.wrapper)r   r   r1   r   r   r   r)   r,   r   r'   r   with_native_function_andR   s   r3   Callable[[S, F], T]c                   r0   )
Nslfr   r   r   r   r   c                   s6   t |  | |W  d    S 1 sw   Y  d S r%   r&   r5   r   r'   r   r   r(   ]      
$z,method_with_native_function.<locals>.wrapper)r5   r   r   r   r   r   r)   r,   r   r'   r   method_with_native_function\   r.   r8   Callable[[S, F3], T]c                   r0   )
Nr5   r   r   r   r   r   c                   s:   t |d   | |W  d    S 1 sw   Y  d S )Nr   r&   r6   r'   r   r   r(   h   s   $z3method_with_nested_native_function.<locals>.wrapper)r5   r   r   r   r   r   r)   r,   r   r'   r   "method_with_nested_native_functione      r:   Callable[[F, BackendIndex], T]c                   r0   )
Nr   r   backend_indexr   r   r   c                   r2   r%   r&   )r   r=   r'   r   r   r(   u   r7   z/with_native_function_and_index.<locals>.wrapper)r   r   r=   r   r   r   r)   r,   r   r'   r   with_native_function_and_indexr   r;   r>   1Callable[[F, dict[DispatchKey, BackendIndex]], T]c                   r0   )
Nr   r   backend_indicesdict[DispatchKey, BackendIndex]r   r   c                   r2   r%   r&   )r   r@   r'   r   r   r(      r7   z1with_native_function_and_indices.<locals>.wrapper)r   r   r@   rA   r   r   r)   r,   r   r'   r    with_native_function_and_indices~   r;   rB   )r   r   r   r   )r   r$   r   r$   )r   r/   r   r/   )r   r4   r   r4   )r   r9   r   r9   )r   r<   r   r<   )r   r?   r   r?   )&
__future__r   
contextlibr*   typingr   r   r   Ztorchgen.localr"   Ztorchgen.modelr   r   r   r	   r
   Ztorchgen.utilsr   r   r   collections.abcr   r   r   boolstrr   tuplelistr   contextmanagerr#   r-   r3   r8   r:   r>   rB   r   r   r   r   <module>   sD    		

	


	
