a
    h                  	   @  sR  d dl mZ d dlZd dlZd dlmZmZmZ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rd dlmZ e	deeee
eef e
eef Ze	deeee eeZe	d	eeef ee Zej d
ddddZ!dddddZ"dddddZ#dddddZ$dddddZ%dddddZ&dddd d!Z'dS )"    )annotationsN)AnyCallableOptionalTYPE_CHECKINGTypeVarUnion)BackendIndexDispatchKeyNativeFunctionNativeFunctionsGroupNativeFunctionsViewGroup)contextST)IteratorFF2F3z@NativeFunctionsGroup | NativeFunctionsViewGroup | NativeFunctionzIterator[None])greturnc              	   #  s   t | tr| j nt | tr$| j n|  t fddH tj j j	d d V  W d    n1 sh0    Y  W d    n1 s0    Y  d S )Nc                     s   d j  d j S )Nzin native_functions.yaml line z:
  )locfunc fr   >/var/www/auris/lib/python3.9/site-packages/torchgen/context.py<lambda><       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$   zCallable[[F], T])r   r   c                   s"   t  ddd fdd}|S )Nr   r   )r   r   c                   s4   t |   | W  d    S 1 s&0    Y  d S Nr$   r   r   r   r   wrapperJ   s    
z%with_native_function.<locals>.wrapper	functoolswrapsr   r(   r   r'   r   with_native_functionI   s    r-   zCallable[[F, F2], T]c                   s$   t  dddd fdd}|S )Nr   r   r   )r   f2r   c                   s6   t |   | |W  d    S 1 s(0    Y  d S r%   r&   )r   r.   r'   r   r   r(   S   s    
z)with_native_function_and.<locals>.wrapperr)   r,   r   r'   r   with_native_function_andR   s    r/   zCallable[[S, F], T]c                   s$   t  dddd fdd}|S )Nr   r   r   slfr   r   c                   s6   t |  | |W  d    S 1 s(0    Y  d S r%   r&   r1   r   r'   r   r   r(   ]   s    
z,method_with_native_function.<locals>.wrapperr)   r,   r   r'   r   method_with_native_function\   s    r3   zCallable[[S, F3], T]c                   s$   t  dddd fdd}|S )Nr   r   r   r0   c                   s:   t |d   | |W  d    S 1 s,0    Y  d S )Nr   r&   r2   r'   r   r   r(   h   s    z3method_with_nested_native_function.<locals>.wrapperr)   r,   r   r'   r   "method_with_nested_native_functione   s    r4   zCallable[[F, BackendIndex], T]c                   s$   t  dddd fdd}|S )Nr   r	   r   )r   backend_indexr   c                   s6   t |   | |W  d    S 1 s(0    Y  d S r%   r&   )r   r5   r'   r   r   r(   u   s    
z/with_native_function_and_index.<locals>.wrapperr)   r,   r   r'   r   with_native_function_and_indexr   s    r6   z1Callable[[F, dict[DispatchKey, BackendIndex]], T]c                   s$   t  dddd fdd}|S )Nr   zdict[DispatchKey, BackendIndex]r   )r   backend_indicesr   c                   s6   t |   | |W  d    S 1 s(0    Y  d S r%   r&   )r   r7   r'   r   r   r(      s    
z1with_native_function_and_indices.<locals>.wrapperr)   r,   r   r'   r    with_native_function_and_indices~   s    r8   )(
__future__r   
contextlibr*   typingr   r   r   r   r   r   Ztorchgen.localr#   Ztorchgen.modelr	   r
   r   r   r   Ztorchgen.utilsr   r   r   collections.abcr   r   boolstrr   tuplelistr   contextmanagerr$   r-   r/   r3   r4   r6   r8   r   r   r   r   <module>   sB    

			
	