U
    d                  	   @   s  d dl mZmZmZ d dlmZmZmZmZm	Z	 d dl
mZ d dlZd dlmZmZmZmZmZmZ d dlZedeeeeeef eeef Zedeeee eZejeeeef ed ddd	Zeegef eegef d
ddZeeegef eeegef d
ddZeeegef eeegef d
ddZeeegef eeegef d
ddZeeee	ef gef eeee	ef gef d
ddZdS )    )STcontext)NativeFunctionNativeFunctionsGroupNativeFunctionsViewGroupBackendIndexDispatchKeyN)TypeVarUnionIteratorCallableDictOptionalFF2)greturnc              
   #   sh   t | tr| j nt | tr$| j n|  t fdd& tj jd d V  W 5 Q R X W 5 Q R X d S )Nc                      s   d j  d j S )Nzin native_functions.yaml line z:
  )locfunc fr   4/tmp/pip-unpacked-wheel-ua33x9lu/torchgen/context.py<lambda>2       z)native_function_manager.<locals>.<lambda>)!use_const_ref_for_mutable_tensors)	
isinstancer   outr   viewr   localZparametrizer   )r   r   r   r   native_function_manager#   s    

r!   )r   r   c                    s"   t  ttd fdd}|S )N)r   r   c              
      s(   t |   | W  5 Q R  S Q R X d S Nr!   r   r   r   r   wrapper?   s    
z%with_native_function.<locals>.wrapper)	functoolswrapsr   r   r   r%   r   r$   r   with_native_function>   s    r)   c                    s$   t  tttd fdd}|S )N)r   f2r   c              
      s*   t |   | |W  5 Q R  S Q R X d S r"   r#   )r   r*   r$   r   r   r%   H   s    
z)with_native_function_and.<locals>.wrapper)r&   r'   r   r   r   r(   r   r$   r   with_native_function_andG   s    r+   c                    s$   t  tttd fdd}|S )N)slfr   r   c              
      s*   t |  | |W  5 Q R  S Q R X d S r"   r#   )r,   r   r$   r   r   r%   R   s    
z,method_with_native_function.<locals>.wrapper)r&   r'   r   r   r   r(   r   r$   r   method_with_native_functionQ   s    r-   c                    s$   t  tttd fdd}|S )N)r   backend_indexr   c              
      s*   t |   | |W  5 Q R  S Q R X d S r"   r#   )r   r.   r$   r   r   r%   _   s    
z/with_native_function_and_index.<locals>.wrapper)r&   r'   r   r   r   r(   r   r$   r   with_native_function_and_index\   s    r/   c                    s,   t  ttttf td fdd}|S )N)r   backend_indicesr   c              
      s*   t |   | |W  5 Q R  S Q R X d S r"   r#   )r   r0   r$   r   r   r%   k   s    
z1with_native_function_and_indices.<locals>.wrapper)r&   r'   r   r   r	   r   r   r(   r   r$   r    with_native_function_and_indicesh   s     r1   )Ztorchgen.utilsr   r   r   Ztorchgen.modelr   r   r   r   r	   Ztorchgen.localr    r&   typingr
   r   r   r   r   r   
contextlibr   boolr   contextmanagerr!   r)   r+   r-   r/   r1   r   r   r   r   <module>   sB    

		$	(
(