
    sgD                     t    d dl mZmZ d dlmZ ddlZg dZ G d de      Zd Z	d	 Z
d
 Zd Zd ZefdZd Zy)   )	_toposortgroupby)
isvariadic    N)AmbiguityWarning
supercedes
consistent	ambiguousambiguitiessuper_signatureedgeorderingc                       e Zd Zy)r   N)__name__
__module____qualname__     n/var/www/html/venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/conflict.pyr   r   	   s    r   r   c                    t        |       t        |      k  r#|  xr t        |      dk(  xr t        |d         S t        |       t        |      k(  rt        t        t        | |            S d}d}|t        |       k  r|t        |      k  r| |   }||   }t        |      s#t        |      st	        ||      sy|dz  }|dz  }nmt        |      r2|t        |       dz
  k(  sJ |t        |      dz
  k(  xr t	        ||      S t        |      r%|t        |      dz
  k(  sJ t	        ||      sy|dz  }|t        |       k  r|t        |      k  r|t        |      dz
  k(  xr |t        |       k(  S )z3 A is consistent and strictly more specific than B r   r   F)lenr   allmap
issubclassabp1p2cur_acur_bs         r   r   r      sc   
1vAu:Q1:AbE)::	Q3q6	3z1a()) 3q6kb3q6kbEEbEEu%E):!%/ aaE"SVaZ'''SVaZ'DJue,DDE"SVaZ'''!%/ a 3q6kb3q6k  SVaZ0B#a&L0r   c                 p   | s| xs t        |d         S |s|  xs t        | d         S t        |       t        |      k(  rt        d t        | |      D              S d}d}|t        |       k  r|t        |      k  r| |   }||   }t	        ||      st	        ||      syt        |      st        |      s|dz  }|dz  }n!t        |      r|dz  }nt        |      r|dz  }|t        |       k  r|t        |      k  rt              xr |t        |      k(  xs t              xr |t        |       k(  S )z= It is possible for an argument list to satisfy both A and B r   c              3   V   K   | ]!  \  }}t        ||      xs t        ||       # y wN)r   ).0aabbs      r   	<genexpr>zconsistent.<locals>.<genexpr>6   s2      ,r2 b"%;B);; ,s   ')Fr   )r   r   r   zipr   r   s         r   r	   r	   +   sA    u(
1Q4((u(
1Q4(( 1vQ ,!$Q, , 	, 3q6kb3q6kbEEbEEeU+Jue4Lu%E):aaE"aE"a 3q6kb3q6k 5!2bCFl 35!2bCFl	4r   c                 T    t        | |      xr t        | |      xs t        ||        S )z> A is consistent with B but neither is strictly more specific )r	   r   )r   r   s     r   r
   r
   M   s*    aJZ1%5%IAq9I JJr   c           	          t        t        t        |             } | D ch c]E  | D ]>  t              t              k  r%t	              rt        fd| D              sf@ G c}}S c c}}w )z5 All signature pairs such that A is ambiguous with B c              3   R   K   | ]  }t        |      xr t        |         y wr%   r   )r&   cr   r   s     r   r)   zambiguities.<locals>.<genexpr>X   s/      ! #1a(=Z1-== !s   $')listr   tuplehashr
   any)
signaturesr   r   s    ``r   r   r   R   sz    c%,-J& " "q
 "1Awa !Q !! ! F "F " " "s   A
A1c                     t        | d         t        fd| D              sJ t              D cg c]  t        fd| D        t               d   ! c}S c c}w )z* A signature that would break ambiguities r   c              3   :   K   | ]  }t        |      k(    y wr%   )r   )r&   sns     r   r)   z"super_signature.<locals>.<genexpr>_   s     /qs1v{/s   c              3   N   K   | ]  }t         j                  |           y wr%   )typemro)r&   sigis     r   r)   z"super_signature.<locals>.<genexpr>a   s     8c#a&!8s   "%)key)r   r   rangemax)r4   r=   r8   s    `@r   r   r   \   s]    JqMA/J//// 1X 8Z8cB1E   s   $Ac                 ^    t        | |      xr  t        ||        xs  ||        ||      kD  S )zV A should be checked before B
    Tie broken by tie_breaker, defaults to ``hash``
    r.   )r   r   tie_breakers      r   r   r   e   s3     aYZ1%5!5!XQ+VW.9XYr   c                    t        t        t        |             } | D cg c]  }| D ]  }t        ||      s||f  }}}t	        t        j                  d      |      }| D ]  }||vsg ||<    |j                         D ci c]  \  }}||D cg c]  \  }}|	 c}} }}}}}t        |      S c c}}w c c}}w c c}}}}w )z A sane ordering of signatures to check, first to last
    Topological sort of edges as given by ``edge`` and ``supercedes``
    r   )	r0   r   r1   r   r   operator
itemgetteritemsr   )r4   r   r   edgesr7   kvs          r   r   r   n   s     c%,-J'JJAtAqzaVJVJEJH''*E2E E>E!H /4kkm<<daQq!tq!!!<E<U K
 "<s"   B6B6C
B< C
<C
)utilsr   r   variadicr   rD   __all__Warningr   r   r	   r
   r   r   r2   r   r   r   r   r   <module>rN      sL    %   	w 	1<4DK
"   Zr   