
    קgL                     X    d dl mZ d dlmZ d dlmZmZ d Zd Zd Z	d Z
d Zd	 Zd
 ZdS )    )Refine)
TensorType)Varunifyc                     t          |           }|                                 t          |j                  }t	          | j        |           dS )z-
    Calls our symbolic inferencer once.
    N)r   refineunify_eqconstraintssubstitute_all_typesgraphtracedrmgus      c/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/fx/experimental/unify_refinements.py infer_symbolic_types_single_passr      sC     	vAHHJJJ
1=
!
!Cs+++++    c                 ^   t          |           }|                                 t          |j                  }t	          | j        |           t          |           }|                                 t          |j                  }t	          | j        |           |                                 dS )z
    Calls our symbolic inferencer twice.
    This is useful when one pass is not enough
    to infer all the information such as the case
    for braodcasting.
    N)r   r   r	   r
   r   r   symbolic_relationsr   s      r   infer_symbolic_typesr      s     	vAHHJJJ
1=
!
!Cs+++vAHHJJJ
1=
!
!Cs+++r   c                     g }g }| D ]6}|                     |j                   |                     |j                   7t          |          t          |          fS )za
    Convert equality constraints in the right format
    to be used by unification library.
    )appendlhsrhstuple)
list_of_eqr   r   eqs       r   
convert_eqr   #   s_    
 C
C  

26

26::uSzz!!r   c                 F    t          |           \  }}t          ||          S )z@
    Apply unification to a set of
    equality constraints
    )r   r   )r   r   r   s      r   r	   r	   0   s#    
 *%%HCc??r   c                    t          |t                    r ||                                 v r| |         S |S t          |t                    rog }|j        D ]I}||                                 v r|                    | |                    4|                    |           Jt          t          |                    S t          |t                    r,g }|D ]%}|                    t          | |                     &|S t          |t                    r9g }|D ]%}|                    t          | |                     &t          |          S |S )z2
    Apply the most general unifier to a type
    )	
isinstancer   keysr   __args__r   r   listsubstitute_solution_one_type)mappingtnew_typetyps       r   r%   r%   9   s]    !S 1:H	Az	"	" : 	% 	%Cgllnn$$----$$$$%//***	At		  	H 	HCOO8#FFGGGG	Au		  	H 	HCOO8#FFGGGGX r   c                     d}|rNd}|D ]G}||         }||         |                                 v r||         }||         ||<   |||         k    rd}H|N| j        D ]}t          ||j                  |_        dS )z
    Apply the most general unifier to all types in a graph
    till reaching a fixed point. If the input and output graph
    are the same, we converge.
    TFN)r"   nodesr%   type)r   r&   flagkold_mapping_valnew_keyns          r   r   r   \   s     D
  	 	A%ajOqzW\\^^++!!*$W-
'!*,,   [ ? ?-gqv>>? ?r   c                 l    t          | j        |j                  D ]\  }}|j        |j        k    r dS dS )zv
    A check equality to be used in fixed points.
    We do not use graph equality but instead type
    equality.
    FT)zipr+   r,   )g1g2r1   ms       r   check_for_type_equalityr7   p   sE     BHbh''  16QV55 4r   N)/torch.fx.experimental.graph_gradual_typecheckerr   torch.fx.tensor_typer   !torch.fx.experimental.unificationr   r   r   r   r   r	   r%   r   r7    r   r   <module>r<      s    B B B B B B + + + + + + 8 8 8 8 8 8 8 8, , ,  &
" 
" 
"       F? ? ?(	 	 	 	 	r   