§
    Ÿ²ÅjË  ã                   óX   — d dl mZ d dlmZmZ d dlmZ d„ Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ ZdS )é    )ÚRefine)ÚunifyÚVar)Ú
TensorTypec                 óž   — 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      úXC:\Projects\Historical\venv\Lib\site-packages\torch/fx/experimental/unify_refinements.pyÚ infer_symbolic_types_single_passr      sC   € õ 	ˆv‰Œ€AØ‡H‚H�J„J€JÝ
�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Ø‡H‚H�J„J€JÝ
�1”=Ñ
!Ô
!€CÝ˜œ sÑ+Ô+Ð+åˆv‰Œ€AØ‡H‚H�J„J€JÝ
�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Øð ð ˆØ�
Š
�2”6ÑÔÐØ�
Š
�2”6ÑÔÐÐÝ�‰:Œ:•u˜S‘z”zÐ!Ð!r   c                 óF   — t          | ¦  «        \  }}t          ||¦  «        S )z@
    Apply unification to a set of
    equality constraints
    )r   r   )r   r   r   s      r   r	   r	   2   s#   € õ
 ˜*Ñ%Ô%�H€CˆÝ��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%   ;   s]  € õ �!•SÑÔð Ø�—’‘”ÐÐØ˜1”:ÐàˆHå	�A•zÑ	"Ô	"ð ØˆØ”:ð 	%ð 	%ˆCØ�g—l’l‘n”nÐ$Ð$Ø—’ ¨¤Ñ-Ô-Ð-Ð-à—’ Ñ$Ô$Ð$Ð$Ý�% ™/œ/Ñ*Ô*Ð*å	�A•tÑ	Ô	ð ØˆØð 	Hð 	HˆCØ�OŠOÕ8¸À#ÑFÔFÑGÔGÐGÐGØˆå	�A•uÑ	Ô	ð ØˆØð 	Hð 	HˆCØ�OŠOÕ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Ø% aœjˆOØ�qŒz˜WŸ\š\™^œ^Ð+Ð+Ø! !œ*�Ø$ WÔ-�˜‘
Ø '¨!¤*Ò,Ð,Ø�øð ð ð Œ[ð ?ð ?ˆÝ-¨g°q´vÑ>Ô>ˆŒˆð?ð ?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   s   sE   € õ �B”H˜bœhÑ'Ô'ð ð ‰ˆˆ1ØŒ6�Q”VÒÐØ�5�5ð àˆ4r   N)Ú/torch.fx.experimental.graph_gradual_typecheckerr   Ú!torch.fx.experimental.unificationr   r   Útorch.fx.tensor_typer   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   