o
    Zhr                     @   s|   d dl Z ddlmZmZ ddlmZ g dZG dd deZdd	 Z	d
d Z
dd Zdd Zdd ZefddZdd ZdS )    N   )	_toposortgroupby)
isvariadic)AmbiguityWarning
supercedes
consistent	ambiguousambiguitiessuper_signatureedgeorderingc                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   j/var/www/auris/lib/python3.10/site-packages/torch/fx/experimental/unification/multipledispatch/conflict.pyr      s    r   c                 C   sJ  t | t |k r|  ot |dkot|d S t | t |kr'ttt| |S d}d}|t | k r|t |k r| | }|| }t|sWt|sWt||sNdS |d7 }|d7 }n4t|rr|t | d kseJ |t |d koqt||S t|r|t |d ksJ t||sdS |d7 }|t | k r|t |k s7|t |d ko|t | kS )z1A is consistent and strictly more specific than Br   r   F)lenr   allmap
issubclassabp1p2Zcur_aZcur_br   r   r   r      s0   


r   c                 C   s   | s| p
t |d S |s|  pt | d S t| t|kr*tdd t| |D S d}d}|t| k r||t|k r|| | }|| }t||sNt||sNdS t |s_t |s_|d7 }|d7 }nt |rh|d7 }nt |rp|d7 }|t| k r||t|k s:t |r|t|kpt |o|t| kS )z;It is possible for an argument list to satisfy both A and Br   c                 s   s(    | ]\}}t ||pt ||V  qd S N)r   ).0ZaaZbbr   r   r   	<genexpr>A   s   & zconsistent.<locals>.<genexpr>Fr   )r   r   r   zipr   r   r   r   r   r   6   s6   



r   c                 C   s    t | |ot| |pt||  S )z<A is consistent with B but neither is strictly more specific)r   r   r   r   r   r   r   r	   [   s    r	   c                    s    t tt   fdd D S )z3All signature pairs such that A is ambiguous with Bc                    sP   h | ]$ D ]t  t k rt rt fd dD s fqqS )c                 3   s$    | ]}t | ot |V  qd S r   r   )r   cr!   r   r   r   i   s   " z(ambiguities.<locals>.<setcomp>.<genexpr>)hashr	   anyr   
signaturesr!   r   	<setcomp>c   s    zambiguities.<locals>.<setcomp>)listr   tupler'   r   r'   r   r
   `   s   
r
   c                    s<   t d  t fddD sJ fddt D S )z(A signature that would break ambiguitiesr   c                 3   s    | ]	}t | kV  qd S r   )r   )r   s)nr   r   r   p   s    z"super_signature.<locals>.<genexpr>c                    s*   g | ] t  fd dD tdd qS )c                 3   s    | ]
}t |  V  qd S r   )typemro)r   sigir   r   r   r   s    z-super_signature.<locals>.<listcomp>.<genexpr>)keyr   )maxr   r&   r'   r1   r   
<listcomp>r   s   * z#super_signature.<locals>.<listcomp>)r   r   ranger'   r   )r-   r(   r   r   m   s   r   c                 C   s&   t | |ot ||  p|| ||kS )zUA should be checked before B
    Tie broken by tie_breaker, defaults to ``hash``
    r"   )r   r   Ztie_breakerr   r   r   r   u   s   
r   c                    sd   t tt   fdd D }ttd|} D ]
}||vr$g ||< qdd | D }t|S )zA sane ordering of signatures to check, first to last
    Topological sort of edges as given by ``edge`` and ``supercedes``
    c                    s(   g | ]} D ]}t ||r||fqqS r   )r   r   r   r   r'   r   r   r5      s   ( zordering.<locals>.<listcomp>r   c                 S   s    i | ]\}}|d d |D qS )c                 S   s   g | ]\}}|qS r   r   r7   r   r   r   r5      s    z'ordering.<locals>.<dictcomp>.<listcomp>r   )r   kvr   r   r   
<dictcomp>   s     zordering.<locals>.<dictcomp>)r*   r   r+   r   operator
itemgetteritemsr   )r(   edgesr,   r   r'   r   r      s   r   )r;   utilsr   r   Zvariadicr   __all__Warningr   r   r   r	   r
   r   r$   r   r   r   r   r   r   <module>   s   %