U
    •Ê¹j†  ã                	   @   sì  d dl Z d dlZd dlmZmZmZ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
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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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 )é    N)	ÚAnyÚCallableÚDictÚIteratorÚListÚOptionalÚTupleÚTypeVarÚUnion)ÚBackendIndexÚDispatchKeyÚNativeFunctionÚNativeFunctionsGroupÚNativeFunctionsViewGroup)ÚcontextÚSÚTÚFÚF2ÚF3)ÚgÚreturnc              
   #   sl   t | tƒr| j‰ nt | tƒr$| j‰ n| ‰ t‡ fdd„ƒ�* tjˆ 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   úO/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torchgen/context.pyÚ<lambda>6   ó    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   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   ÚwrapperD   s    
z%with_native_function.<locals>.wrapper)Ú	functoolsÚwrapsr   r   ©r   r)   r   r(   r   Úwith_native_functionC   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)   M   s    
z)with_native_function_and.<locals>.wrapper)r*   r+   r   r   r   r,   r   r(   r   Úwith_native_function_andL   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'   ©r1   r   r(   r   r   r)   W   s    
z,method_with_native_function.<locals>.wrapper)r*   r+   r   r   r   r,   r   r(   r   Úmethod_with_native_functionV   s    r3   c                    s$   t  ˆ ¡tttdœ‡ fdd„ƒ}|S )Nr0   c              
      s.   t |d ƒ� ˆ | |ƒW  5 Q R £ S Q R X d S )Nr   r'   r2   r(   r   r   r)   b   s    z3method_with_nested_native_function.<locals>.wrapper)r*   r+   r   r   r   r,   r   r(   r   Ú"method_with_nested_native_function_   s    r4   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   r5   r(   r   r   r)   o   s    
z/with_native_function_and_index.<locals>.wrapper)r*   r+   r   r   r   r,   r   r(   r   Úwith_native_function_and_indexl   s    r6   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   r7   r(   r   r   r)   {   s    
z1with_native_function_and_indices.<locals>.wrapper)r*   r+   r   r   r   r   r   r,   r   r(   r   Ú with_native_function_and_indicesx   s     r8   )%Ú
contextlibr*   Útypingr   r   r   r   r   r   r   r	   r
   Ztorchgen.localr$   Ztorchgen.modelr   r   r   r   r   Ztorchgen.utilsr   r   r   r   ÚboolÚstrr   r   Úcontextmanagerr%   r-   r/   r3   r4   r6   r8   r   r   r   r   Ú<module>   sL   ,

ú	ú	þ$	(
(
þþþ