
    sg                     <    d dl mZ g dZd Zd Zd Zd Zd Zd Zy	)
    )OrderedDict)raisesexpand_tuplesreverse_dictgroupbytypenamec                 *    	  |        y# | $ r Y yw xY w)NFT )errlamdas     k/var/www/html/venv/lib/python3.12/site-packages/torch/fx/experimental/unification/multipledispatch/utils.pyr   r      s!     s   
 c                     | sdgS t        | d   t              s%t        | dd       }|D cg c]  }| d   f|z    c}S t        | dd       }|D cg c]  }| d   D ]  }|f|z   
  c}}S c c}w c c}}w )zh
    >>> 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#%)*1!**QqrU#%);ad;d!;;; + <s   A,A1c                    t        |       t        d j                         D              t        j                  fd| D              }g }|rf|j	                         \  }}|j                  |       | j                  |d      D ]*  }||   v sJ |   j                  |       |   r&d||<   , |rft        fd| D              rt        d      |S )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   <   K   | ]  \  }}|t        |      f  y wN)set).0kvals      r   	<genexpr>z_toposort.<locals>.<genexpr>/   s&      !G%+Q #$SX !Gs   c              3   ,   K   | ]  }|vs|  y wr   r
   r   vincoming_edgess     r   r   z_toposort.<locals>.<genexpr>1   s     I1.1HQIs   	r
   Nc              3   B   K   | ]  }j                  |d         y wr   )getr   s     r   r   z_toposort.<locals>.<genexpr><   s     
61>a&
6s   zInput has cycles)
r   r   itemsfromkeyspopitemappendr#   removeany
ValueError)edgesSr   n_mr!   s         @r   	_toposortr0   !   s     "%(N  !G/=/C/C/E!G GNIIIA
A
yy{1	1b! 	Aq))))1$$Q'!!$!		  
6
66+,,H    c                 n    t               }| D ]%  }| |   D ]  }|j                  |d      |fz   ||<    ' |S )a  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   A   sO     ]F 7S6 	7C **S"-6F3K	77 Mr1   c                 r    t               }|D ]'  } | |      }||vrg ||<   ||   j                  |       ) |S )a   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seqr3   r   r5   s        r   r   r   T   sJ     	A 4ja<AcF	#d	
 Hr1   c                     	 | j                   S # t        $ r> t        |       dk(  r
t        |  cY S ddj	                  t        t        |              dcY S w xY w)a5  Get 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   i   sU     5}} 5t9>T?"499S4012!445s    A#AAN)	collectionsr   __all__r   r   r0   r   r   r   r
   r1   r   <module>rD      s,    #
L<&@&*5r1   