
    |Yh                    F   d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	 d dl
mZ erd dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ  ed          Z e	d	          Zej        dd            Zej        dd            Z G d dej        j                  ZdS )    )annotationsN)nullcontext)AnyCallableTYPE_CHECKINGTypeVar)	ParamSpec)Sequence)torch_function_passthrough_P_Rreturndict[Any, Any]c            	     	   t           t           j        ft           j        t           j        j        ft           j        j        t           j        j        j        ft           j        t           j        j        ft           j        t           j        j        ft           j        t           j        j        fg} i t           j        j        t           j        j	        t           j        j
        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j        t           j        j         t           j        j         t           j        j!        t           j        j!        t           j        j"        t           j        j"        t           j        j#        t           j        j#        t           j        j$        t           j        j$        t           j        j%        t           j        j%        t           j        j&        t           j'        j(        t           j        j)        t           j'        j)        i}| D ]D\  }}|j*        D ]7}|j+        ,                    |          ||j+        ,                    |          <   8Et[          t           j                  D ]T}|t           j        j*        v r?t           j        j+        ,                    |          |t]          t           j        |          <   Ut           j        j/        j*        D ]^}t]          t           j        |d          pt]          t           |          }t           j        j/        j+        ,                    |          ||<   _|S )z}
    Mapping of torch API functions to torch._refs functions.
    E.g. torch_to_refs_map()[torch.add] == torch._refs.add
    N)0torch_refsnn
functionalspecialfftlinalgTensor
__invert__bitwise_not__xor__bitwise_xor__and__bitwise_and__or__
bitwise_or__eq__eq__rsub__rsub__rtruediv__rtruediv__floordiv__floor_divide__rfloordiv__	rfloordiv__pow__pow__rpow__rpow	new_emptynew_full	new_zerosnew_onesfill_zero_tosum_to_sizecopy__primscopy_toresize__all____dict__getdirgetattr_conversions)modulesr	mod_torchmod_refsstensor_attrs         f/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/_prims/context.pytorch_to_refs_maprH      s;    
	5;>"		ekn78	+,	EKO$	u{)*G!8ek5 	ek5 	U[3	
 	U[^ 	u{/ 	!5;#7 	!5;#; 	"EK$9 	eko 	u{/ 	 5 	u{3 	 5 	u{3  	EK-!" 	EK-#$ 	 %+"9EL0U\0- A0  ' D D	8! 	D 	DA+3+<+@+@+C+CAi $$Q''((	D  F F###*/+*>*B*B1*E*EAgelA&&' [%- B BelAt44Iq8I8I1:>>qAA+H    set[Any]c                 8    d t           j        j        D             S )zJ
    Set of all prim functions, e.g., torch._prims.add in all_prims()
    c                V    h | ]&}t           j        j                            |          'S  )r   r8   r<   r=   ).0rE   s     rG   	<setcomp>zall_prims.<locals>.<setcomp>W   s+    GGGQEL!%%a((GGGrI   )r   r8   r;   rM   rI   rG   	all_primsrP   R   s    
 HG%,2FGGGGrI   c                  2    e Zd ZdZdd efddZ	 	 dddZdS )TorchRefsModeaB  
    Switches the interpretation of torch.* functions and Tensor methods to
    use PrimTorch refs in torch._refs.  (Direct calls to _refs are unaffected.)

    >>> # xdoctest: +SKIP
    >>> with TorchRefsMode():
    ...     torch.add(x, y)  # calls torch._refs.add(x, y)

    By default, this context manager will fall back on the torch.* if the
    ref does not exist; set strict=True to error if this occurs.
    If the ref exists we still would like to fall back on the torch.* sometimes,
    this behavior can be customized by passing a function to should_fallback_fn.
    Fc                     dS )NFrM   )_s    rG   <lambda>zTorchRefsMode.<lambda>l   s    U rI   strictboolshould_fallback_fnCallable[..., bool]prims_mode_clstyper   Nonec                0    || _         || _        || _        d S )N)rV   rX   rZ   )selfrV   rX   rZ   s       rG   __init__zTorchRefsMode.__init__i   s!     "4,rI   rM   N	orig_funcCallable[_P, _R]typesSequence[type]argsSequence[Any]kwargsdict[str, Any] | Noner   c                |   |i }|t           v s|t                      v r4|                                 5   ||i |cd d d            S # 1 swxY w Y   t                      }|                    |d           }|Et          |t          j        j                  r&t          j	        j
                            |d           }n~||t          |t          j        j                  r]t          |dd           }|#|j        rt          ||j        d         d           }|%t          j	        j
                            |d           }|C|                     | ||||          r ||i |S | 5   ||i |cd d d            S # 1 swxY w Y   | j        r/t!          dt          j                            |                      ||i |S )Ndefaultr   zno _refs support for )r   rP   rZ   rH   r=   
isinstancer   _ops
OpOverload_decompdecomposition_tableOpOverloadPacketr?   _dirrX   rV   RuntimeError	overridesresolve_name)r^   r`   rb   rd   rf   mappingfuncri   s           rG   __torch_function__z TorchRefsMode.__torch_function__s   sa    >F 222i9;;6N6N$$&& 2 2 y$1&112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2#%%{{9d++ <Jy%*2GHH<=488DIIDD\jEJ4OPP\iD99G9>!)Y^A->EE"}8<<WdKK&&tYdFKK 2 y$1&111 - -tT,V,,- - - - - - - - - - - - - - - -; 	Q(D(DY(O(OQQ   y$)&)))s#   AAA E55E9<E9)rV   rW   rX   rY   rZ   r[   r   r\   )rM   N)
r`   ra   rb   rc   rd   re   rf   rg   r   r   )__name__
__module____qualname____doc__r   r_   rv   rM   rI   rG   rR   rR   Z   sf           2B2B*	- - - - - !(,+* +* +* +* +* +* +*rI   rR   )r   r   )r   rJ   ) 
__future__r   	functools
contextlibr   typingr   r   r   r   typing_extensionsr	   collections.abcr
   r   torch._decomptorch._primstorch._refstorch._refs.nntorch._refs.nn.functionaltorch._refs.specialtorch.overridestorch._prims_commonr   r   r   cacherH   rP   rr   TorchFunctionModerR   rM   rI   rG   <module>r      s   " " " " " "     " " " " " " 8 8 8 8 8 8 8 8 8 8 8 8 ' ' ' ' ' '  )((((((                                  : : : : : : Yt__WT]] 3 3 3 3l H H H HD* D* D* D* D*EO5 D* D* D* D* D*rI   