
    sh                     <    S SK Jr  / SQrS rS rS rS rS rS rg	)
    )OrderedDict)raisesexpand_tuplesreverse_dictgroupbytypenamec                 ,     U" 5         g! U  a     gf = f)NFT )errlamdas     ڌ/Users/tiagomarins/Projetos/claudeai/copy_bank/venv/lib/python3.13/site-packages/torch/fx/experimental/unification/multipledispatch/utils.pyr   r      s!     s   
 c                    U (       d  S/$ [        U S   [        5      (       d'  [        U SS 5      nU Vs/ s H  o S   4U-   PM     sn$ [        U SS 5      nU VVs/ s H  o S     H  o34U-   PM
     M     snn$ s  snf s  snnf )zT
>>> expand_tuples([1, (2, 3)])
[(1, 2), (1, 3)]
>>> expand_tuples([1, 2])
[(1, 2)]
r
   r      N)
isinstancetupler   )Lresttitems       r   r   r      s     t!e$$QqrU#%)*T1!T**QqrU#%);Tdd!dT;; + <s   A<Bc                   ^ [        U 5      m[        S TR                  5        5       5      m[        R                  " U4S jU  5       5      n/ nU(       at  UR	                  5       u  p4UR                  U5        U R                  US5       H2  nUTU   ;   d   eTU   R                  U5        TU   (       a  M.  SX'   M4     U(       a  Mt  [        U4S jU  5       5      (       a  [        S5      eU$ )a  Topological sort algorithm by Kahn [1] - O(nodes + vertices)
inputs:
    edges - a dict of the form {a: {b, c}} where b and c depend on a
outputs:
    L - an ordered list of nodes that satisfy the dependencies of edges
>>> _toposort({1: (2, 3), 2: (3,)})
[1, 2, 3]
>>> # Closely follows the wikipedia page [2]
>>> # [1] Kahn, Arthur B. (1962), "Topological sorting of large networks",
>>> # Communications of the ACM
>>> # [2] http://en.wikipedia.org/wiki/Toposort#Algorithms
c              3   @   #    U  H  u  pU[        U5      4v   M     g 7fN)set).0kvals      r   	<genexpr>_toposort.<locals>.<genexpr>1   s      T=S61!SX=Ss   c              3   6   >#    U  H  oT;  d  M
  Uv   M     g 7fr   r
   r   vincoming_edgess     r   r   r   2   s     I1.1HQQs   		r
   Nc              3   H   >#    U  H  nTR                  US 5      v   M     g 7fr   )getr    s     r   r   r   =   s!     
61>a&&s   "zInput has cycles)
r   r   itemsfromkeyspopitemappendr$   removeany
ValueError)edgesSr   n_mr"   s         @r   	_toposortr1   #   s     "%(N  T^=Q=Q=S TTNIIIA
A
yy{	1b!Aq))))1$$Q'!!$$	 " ! 
6
666+,,H    c                 r    [        5       nU  H&  nX    H  nUR                  US5      U4-   X'   M     M(     U$ )ay  Reverses direction of dependence dict
>>> d = {"a": (1, 2), "b": (2, 3), "c": ()}
>>> reverse_dict(d)  # doctest: +SKIP
{1: ('a',), 2: ('a', 'b'), 3: ('b',)}
:note: dict order are not deterministic. As we iterate on the
    input dict, it make the output of this function depend on the
    dict order. So this function output order should be considered
    as undeterministic.
r
   )r   r$   )dresultkeyr   s       r   r   r   B   sA     ]F6C **S"-6FK   Mr2   c                 t    [        5       nU H'  nU " U5      nXB;  a  / X$'   X$   R                  U5        M)     U$ )az  Group a collection by a key function
>>> names = ["Alice", "Bob", "Charlie", "Dan", "Edith", "Frank"]
>>> groupby(len, names)  # doctest: +SKIP
{3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
>>> iseven = lambda x: x % 2 == 0
>>> groupby(iseven, [1, 2, 3, 4, 5, 6, 7, 8])  # doctest: +SKIP
{False: [1, 3, 5, 7], True: [2, 4, 6, 8]}
See Also:
    ``countby``
)r   r(   )funcseqr4   r   r6   s        r   r   r   U   s?     	A4j<AF	d	 
 Hr2   c                      U R                   $ ! [         a?    [        U 5      S:X  a
  [        U 6 s $ SSR	                  [        [        U 5      5       S3s $ f = f)zGet the name of `type`.
Parameters
----------
type : Union[Type, Tuple[Type]]
Returns
-------
str
    The name of `type` or a tuple of the names of the types in `type`.
Examples
--------
>>> typename(int)
'int'
>>> typename((int, float))
'(int, float)'
r   (z, ))__name__AttributeErrorlenr   joinmap)types    r   r   r   j   sU     5}} 5t9>T?"499S4012!445s    !A#AAN)	collectionsr   __all__r   r   r1   r   r   r   r
   r2   r   <module>rE      s.    # M<&>&*5r2   