Ë
    ÄÓ^jj  ã                   óÞ  — d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ g d¢Zdej                  j                  d	dfd
„Zdej                  j                  d	dfd„Zdee   d	eeedf   eedf   f   fd„Zdee   d	efd„Zdeeef   ded	efd„Zdej                  j2                  deeef   d	dfd„Zdej                  j2                  dej                  j2                  d	efd„Zy)é    )ÚAnyN)ÚRefine)ÚEquality)ÚunifyÚVar)Ú
TensorType)Úcheck_for_type_equalityÚ
convert_eqÚinfer_symbolic_typesÚ infer_symbolic_types_single_passÚsubstitute_all_typesÚsubstitute_solution_one_typeÚunify_eqÚtracedÚreturnc                 ó�   — t        | «      }|j                  «        t        |j                  «      }t	        | j
                  |«       y)z-
    Calls our symbolic inferencer once.
    N)r   Úrefiner   Úconstraintsr   Úgraph©r   ÚrÚmgus      úr/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/fx/experimental/unify_refinements.pyr   r      s2   € ô 	ˆv‹€AØ‡H�H„JÜ
�1—=‘=Ó
!€CÜ˜Ÿ™ sÕ+ó    c                 ó<  — t        | «      }|j                  «        t        |j                  «      }t	        | j
                  |«       t        | «      }|j                  «        t        |j                  «      }t	        | j
                  |«       |j                  «        y)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   r   r       sl   € ô 	ˆv‹€AØ‡H�H„JÜ
�1—=‘=Ó
!€CÜ˜Ÿ™ sÔ+äˆv‹€AØ‡H�H„JÜ
�1—=‘=Ó
!€CÜ˜Ÿ™ sÔ+à×ÑÕr   Ú
list_of_eq.c                 ó°   — g }g }| D ]8  }|j                  |j                  «       |j                  |j                  «       Œ: t        |«      t        |«      fS )za
    Convert equality constraints in the right format
    to be used by unification library.
    )ÚappendÚlhsÚrhsÚtuple)r   r    r!   Úeqs       r   r
   r
   4   sR   € ð
 €CØ
€CØò ˆØ�
‰
�2—6‘6ÔØ�
‰
�2—6‘6Õðô �‹:”u˜S“zÐ!Ð!r   c                 ó6   — t        | «      \  }}t        ||«      S )z@
    Apply unification to a set of
    equality constraints
    )r
   r   )r   r    r!   s      r   r   r   A   s   € ô
 ˜*Ó%�H€CˆÜ��c‹?Ðr   ÚmappingÚtc                 óè  — t        |t        «      r|| v r| |   S |S t        |t        «      rQg }|j                  D ],  }|| v r|j	                  | |   «       Œ|j	                  |«       Œ. t        t        |«      «      S t        |t        «      r&g }|D ]  }|j	                  t        | |«      «       Œ |S t        |t
        «      r/g }|D ]  }|j	                  t        | |«      «       Œ t        |«      S |S )z2
    Apply the most general unifier to a type
    )Ú
isinstancer   r   Údimsr   r"   Úlistr   )r%   r&   Únew_typeÚtyps       r   r   r   J   sø   € ô �!”SÔØ�‰<Ø˜1‘:ÐàˆHä	�A”zÔ	"ØˆØ—6‘6ò 	%ˆCØ�g‰~Ø—‘ ¨¡Õ-à—‘ Õ$ð		%ô
 œ% ›/Ó*Ð*ä	�A”tÔ	ØˆØò 	HˆCØ�O‰OÔ8¸À#ÓFÕGð	Hàˆä	�A”uÔ	ØˆØò 	HˆCØ�O‰OÔ8¸À#ÓFÕGð	Hä�X‹Ðð ˆr   r   c                 óÄ   — d}|r0d}|D ]&  }||   }||   |v r||   }||   ||<   |||   k7  sŒ%d}Œ( |rŒ0| j                   D ]  }t        ||j                  «      |_        Œ y)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   m   s‰   € ð €DÙ
ØˆØò 	ˆAØ% a™jˆOØ�q‰z˜WÑ$Ø! !™*�Ø$ WÑ-�˜‘
Ø '¨!¡*Ó,Ø‘ð	ò ð �[‰[ò ?ˆÜ-¨g°q·v±vÓ>ˆ�ñ?r   Úg1Úg2c                 óŠ   — t        | j                  |j                  «      D ]   \  }}|j                  |j                  k7  sŒ  y y)zv
    A check equality to be used in fixed points.
    We do not use graph equality but instead type
    equality.
    FT)Úzipr.   r/   )r5   r6   r4   Úms       r   r	   r	   ‚   s>   € ô �B—H‘H˜bŸh™hÓ'ò ‰ˆˆ1Ø�6‰6�Q—V‘VÓÙðð r   )Útypingr   ÚtorchÚtorch.fxÚ/torch.fx.experimental.graph_gradual_typecheckerr   Ú&torch.fx.experimental.refinement_typesr   Ú!torch.fx.experimental.unificationr   r   Útorch.fx.tensor_typer   Ú__all__ÚfxÚGraphModuler   r   r*   r"   r
   r   ÚdictÚobjectr   ÚGraphr   Úboolr	   © r   r   ú<module>rI      s  ðÝ ã Û Ý BÝ ;ß 8Ý +ò€ð,¨U¯X©X×-AÑ-Að ,Àdó ,ð §¡×!5Ñ!5ð ¸$ó ð(
"˜4 ™>ð 
"¨e°E¸#¸s¸(±OÀUÈ3ÐPSÈ8Á_Ð4TÑ.Uó 
"ð˜˜h™ð ¨Có ð ¨$¨v°v¨~Ñ*>ð  À6ð  Ècó  ðF? §¡§¡ð ?¸¸fÀf¸nÑ9Mð ?ÐRVó ?ð*	 §¡§¡ð 	°E·H±H·N±Nð 	Àtô 	r   