
    ^jL                        d dl m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 g dZddZdd	Zdd
ZddZ eee      dd       Z	 	 	 	 	 	 	 	 ddZ eeee      dd       Zy)    )annotations)TYPE_CHECKING   )_reify_unifyreifyunify)dispatch)Var)	unifiablereify_objectunify_objectc                    t        j                  | | t        ft               t	        j                  | t        ft
               | S )a  Register standard unify and reify operations on class
    This uses the type and __dict__ or __slots__ attributes to define the
    nature of the term
    See Also:
    >>> # xdoctest: +SKIP
    >>> class A(object):
    ...     def __init__(self, a, b):
    ...         self.a = a
    ...         self.b = b
    >>> unifiable(A)
    <class 'unification.more.A'>
    >>> x = var("x")
    >>> a = A(1, 2)
    >>> b = A(1, x)
    >>> unify(a, b, {})
    {~x: 2}
    )
core_unifyadddictr   
core_reifyr   )clss    q/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/fx/experimental/unification/more.pyr   r      s0    $ NNCd#\2NNC;-J    c                J    t        | d      rt        | |      S t        | |      S )a  Reify a Python object with a substitution
    >>> # xdoctest: +SKIP
    >>> class Foo(object):
    ...     def __init__(self, a, b):
    ...         self.a = a
    ...         self.b = b
    ...
    ...     def __str__(self):
    ...         return "Foo(%s, %s)" % (str(self.a), str(self.b))
    >>> x = var("x")
    >>> f = Foo(1, x)
    >>> print(f)
    Foo(1, ~x)
    >>> print(reify_object(f, {x: 2}))
    Foo(1, 2)
    	__slots__)hasattr_reify_object_slots_reify_object_dictoss     r   r   r   2   s(    " q+"1a((!!Q''r   c                    t         j                  t        |             }t        | j                  |      }|| j                  k(  r| S |j                  j                  |       |S N)object__new__typer   __dict__update)r   r   objds       r   r   r   I   sK    
..a
!Cajj!AAJJLLJr   c                   | j                   D cg c]  }t        | |       }}t        ||      }||k(  r| S t        j	                  t        |             }t        | j                   |      D ]  \  }}t        |||        |S c c}w r    )r   getattrr   r!   r"   r#   zipsetattr)r   r   attrattrs	new_attrsnewobjslots          r   r   r   R   s     KK 	4E  eQI	Q(KK
 	(JD$ FD$'		(
 s   Bc                h    t        t        | j                  | j                  | j                  f|       S )zReify a Python ``slice`` object)slicer   startstopstepr   s     r   r   r   d   s)     %!&&!&&11566r   c           
     @   t        |       t        |      uryt        | d      rQt        | j                  D cg c]  }t	        | |       c}|j                  D cg c]  }t	        ||       c}|      S t        | j
                  |j
                  |      S c c}w c c}w )a  Unify two Python objects
    Unifies their type and ``__dict__`` attributes
    >>> # xdoctest: +SKIP
    >>> class Foo(object):
    ...     def __init__(self, a, b):
    ...         self.a = a
    ...         self.b = b
    ...
    ...     def __str__(self):
    ...         return "Foo(%s, %s)" % (str(self.a), str(self.b))
    >>> x = var("x")
    >>> f = Foo(1, x)
    >>> g = Foo(1, 2)
    >>> unify_object(f, g, {})
    {~x: 2}
    Fr   )r#   r   r	   r   r)   r$   )uvr   r0   s       r   r   r   p   s    & Awd1gq+ KK 4  KK 4  

 
	
 JJJJ
 	
s   BB
c                    t        | j                  | j                  | j                  f|j                  |j                  |j                  f|      S )zUnify a Python ``slice`` object)r	   r3   r4   r5   )r7   r8   r   s      r   r   r      s9     !''166166*QWWaffaff,EqIIr   N)r   r#   returnr#   )r   r!   r   dict[Var, object]r:   r!   )r   r2   r   r;   r:   r2   )r7   r!   r8   r!   r   r;   r:   dict[Var, object] | bool)r7   r2   r8   r2   r   r;   r:   r<   )
__future__r   typingr   corer   r   r   r   r   r	   r
   variabler   __all__r   r   r   r   r2   r   r    r   r   <module>rC      s    "      8:(.$ 
%7 7&
&
&
.&
&
R 
%J Jr   