
    N j:                     V    S SK Jr  S SKJrJr  S SKJr  S rS rS r	S r
S rS	 rS
 rg)    )Refine)unifyVar)
TensorTypec                     [        U 5      nUR                  5         [        UR                  5      n[	        U R
                  U5        g)z%
Calls our symbolic inferencer once.
N)r   refineunify_eqconstraintssubstitute_all_typesgraphtracedrmgus      x/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/torch/fx/experimental/unify_refinements.py infer_symbolic_types_single_passr      s2     	vAHHJ
1==
!Cs+    c                 <   [        U 5      nUR                  5         [        UR                  5      n[	        U R
                  U5        [        U 5      nUR                  5         [        UR                  5      n[	        U R
                  U5        UR                  5         g)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 broadcasting.
N)r   r   r	   r
   r   r   symbolic_relationsr   s      r   infer_symbolic_typesr      sl     	vAHHJ
1==
!Cs+vAHHJ
1==
!Cs+r   c                     / n/ nU  H9  nUR                  UR                  5        UR                  UR                  5        M;     [        U5      [        U5      4$ )zU
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   %   sM    
 C
C

266

266  :uSz!!r   c                 2    [        U 5      u  p[        X5      $ )z4
Apply unification to a set of
equality constraints
)r   r   )r   r   r   s      r   r	   r	   2   s    
 *%HC?r   c                    [        U[        5      (       a  X;   a  X   $ U$ [        U[        5      (       aT  / nUR                   H.  nX0;   a  UR	                  X   5        M  UR	                  U5        M0     [        [        U5      5      $ [        U[        5      (       a'  / nU H  nUR	                  [        X5      5        M     U$ [        U[
        5      (       a0  / nU H  nUR	                  [        X5      5        M     [        U5      $ U$ )z*
Apply the most general unifier to a type
)
isinstancer   r   __args__r   r   listsubstitute_solution_one_type)mappingtnew_typetyps       r   r$   r$   ;   s     !S<:H	Az	"	"::C~-$	 
 %/**	At		COO8FG 	Au		COO8FG X r   c                     SnU(       a6  SnU H%  nX   nX   U;   a
  X   nX   X'   XAU   :w  d  M#  SnM'     U(       a  M6  U R                    H  n[        XR                  5      Ul        M     g)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)nodesr$   type)r   r%   flagkold_mapping_valnew_keyns          r   r   r   ^   ss     D
A%jOzW$!*$-
!*,  $ [[-gvv> r   c                     [        U R                  UR                  5       H!  u  p#UR                  UR                  :w  d  M!    g   g)zf
A check equality to be used in fixed points.
We do not use graph equality but instead type
equality.
FT)zipr*   r+   )g1g2r0   ms       r   check_for_type_equalityr6   s   s7     BHHbhh'66QVV ( r   N)/torch.fx.experimental.graph_gradual_typecheckerr   !torch.fx.experimental.unificationr   r   torch.fx.tensor_typer   r   r   r   r	   r$   r   r6    r   r   <module>r;      s2    B 8 +,(
" F?*	r   