U
    Jบc
  ใ                   @   s  d dl mZ d dlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	gZeeed
d Ze eeedd Ze eeedd Ze eeedd Ze eeedd Zdd ZeeefZeeeedd Zeeeedd	 Ze eeedd	 ZdS )้    )ฺIterator)ฺpartial้   )ฺassoc)ฺtransitive_get)ฺisvar)ฺdispatchฺreifyฺunifyc                 C   s   t tt|d| S )Nฉฺs)ฺmapr   r	   ฉฺtr   ฉ r   ๚J/tmp/pip-unpacked-wheel-gikjz4vx/torch/fx/experimental/unification/core.pyฺ_reify   s    r   c                 C   s   t tt| |S ฉN)ฺtupler	   ฺiterr   r   r   r   r      s    c                 C   s   t tt| |S r   )ฺlistr	   r   r   r   r   r   r      s    c                    s   t  fdd|  ก D S )Nc                 3   s    | ]\}}|t | fV  qd S r   )r	   )ฺ.0ฺkฺvr   r   r   ฺ	<genexpr>!   s     z_reify.<locals>.<genexpr>)ฺdictฺitems)ฺdr   r   r   r   r      s    c                 C   s   | S r   r   )ฺor   r   r   r   r   $   s    c                 C   s,   t | r"| |krt||  |S | S t| |S )a   Replace variables of expression with substitution
    >>> # xdoctest: +SKIP
    >>> x, y = var(), var()
    >>> e = (1, x, (3, y))
    >>> s = {x: 2, y: 4}
    >>> reify(e, s)
    (1, 2, (3, 4))
    >>> e = {1: x, 3: (y, 5)}
    >>> reify(e, s)
    {1: 2, 3: (4, 5)}
    )r   r	   r   )ฺer   r   r   r   r	   (   s    c                 C   sF   t | t |krdS t| |D ]"\}}t|||}|dkr dS q|S )NF)ฺlenฺzipr
   )ฺur   r   ฺuuฺvvr   r   r   ฺ_unify>   s    r%   c                 C   sT   t | |} t ||}| |kr |S t| r4t|| |S t|rHt||| S t| ||S )z| Find substitution so that u == v while satisfying s
    >>> x = var('x')
    >>> unify((1, x), (1, 2), {})
    {~x: 2}
    )ฺwalkr   r   r%   )r"   r   r   r   r   r   r
   b   s    

c                 C   s   t | |i S r   )r
   )r"   r   r   r   r   r
   t   s    N)ฺcollections.abcr   ฺ	functoolsr   Zunification_toolsr   ฺutilsr   r&   ฺvariabler   r   ฺ__all__r   r   r   r   ฺobjectr	   ฺseqr%   r
   r   r   r   r   ฺ<module>   s:   







#

