§
    P�’j1  ã                  óˆ  — d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 e	rd dlmZmZ  e
d¦  «        Z e
d¦  «        Z e
d	¦  «        Z e
d
¦  «        Z e
d¦  «        Zg d¢ZdCd„ZdDd„ZdEd„ZefdFd„ZefdGd"„ZefdHd%„ZefdId)„ZefdJd+„ZefdKd-„ZefdLd0„ZdMd2„ZefdNd4„ZdefdOd6„Z 	 	 dPdQd;„Z!dRd=„Z"dSd@„Z#dTdB„Z$dS )Ué    )ÚannotationsN)ÚMapping)Úreduce)ÚTYPE_CHECKINGÚTypeVar)ÚCallableÚIterableÚ_KÚ_VÚ_K2Ú_V2Ú_T)ÚmergeÚ
merge_withÚvalmapÚkeymapÚitemmapÚ	valfilterÚ	keyfilterÚ
itemfilterÚassocÚdissocÚassoc_inÚ	update_inÚget_inÚfúCallable[..., object]Úkwargsúdict[str, object]ÚreturnÚtypec                ó¤   — |                      dt          ¦  «        }|r2t          | j        › d|                     ¦   «         d         › d�¦  «        ‚|S )NÚfactoryz'() got an unexpected keyword argument 'r   ú')ÚpopÚdictÚ	TypeErrorÚ__name__Úpopitem)r   r   r#   s      úaC:\Projects\DSCons\.venv\Lib\site-packages\torch\fx\experimental\unification\unification_tools.pyÚ_get_factoryr+   %   s\   € Ø—J’J˜y­$Ñ/Ô/€GØð 
ÝØŒzÐXÐXÀ&Ç.Â.ÑBRÔBRÐSTÔBUÐXÐXÐXñ
ô 
ð 	
ð €Nó    ÚdictsúMapping[object, object]Úobjectc                 óä   — t          | ¦  «        dk    r#t          | d         t          ¦  «        s| d         } t          t          |¦  «        } |¦   «         }| D ]}|                     |¦  «         Œ|S )zóMerge a collection of dictionaries

    >>> merge({1: "one"}, {2: "two"})
    {1: 'one', 2: 'two'}

    Later dictionaries have precedence

    >>> merge({1: 2, 3: 4}, {3: 3, 4: 4})
    {1: 2, 3: 3, 4: 4}

    See Also:
        merge_with
    é   r   )ÚlenÚ
isinstancer   r+   r   Úupdate)r-   r   r#   ÚrvÚds        r*   r   r   .   sm   € õ ˆ5�z„z�Q‚€�z¨%°¬(µGÑ<Ô<€Ø�a”ˆÝ�5 &Ñ)Ô)€Gà	ˆ‰Œ€BØð ð ˆØ
�	Š	�!‰ŒˆˆØ€Ir,   Úfuncc                óX  — t          |¦  «        dk    r#t          |d         t          ¦  «        s|d         }t          t          |¦  «        } |¦   «         }|D ]B}|                     ¦   «         D ]+\  }}||vr|g||<   Œ||                              |¦  «         Œ,ŒCt          | ||¦  «        S )a¥  Merge dictionaries and apply function to combined values

    A key may occur in more than one dict, and all values mapped from the key
    will be passed to the function as a list, such as func([val1, val2, ...]).

    >>> merge_with(sum, {1: 1, 2: 2}, {1: 10, 2: 20})
    {1: 11, 2: 22}

    >>> merge_with(first, {1: 1, 2: 2}, {2: 20, 3: 30})  # doctest: +SKIP
    {1: 1, 2: 2, 3: 30}

    See Also:
        merge
    r1   r   )r2   r3   r   r+   r   ÚitemsÚappendr   )r7   r-   r   r#   Úresultr6   ÚkÚvs           r*   r   r   F   s¼   € õ" ˆ5�z„z�Q‚€�z¨%°¬(µGÑ<Ô<€Ø�a”ˆÝ�: vÑ.Ô.€GàˆW‰YŒY€FØð $ð $ˆØ—G’G‘I”Ið 	$ð 	$‰DˆAˆqØ˜ˆˆØ˜C��q‘	�	à�q”	× Ò  Ñ#Ô#Ð#Ð#ð		$õ
 �$˜ Ñ(Ô(Ð(r,   úCallable[[_V], _V2]r6   úMapping[_K, _V]r#   údict[_K, _V2]c           
     óÄ   —  |¦   «         }|                      t          |                     ¦   «         t          | |                     ¦   «         ¦  «        ¦  «        ¦  «         |S )zÝApply function to values of dictionary

    >>> bills = {"Alice": [20, 15, 30], "Bob": [10, 35]}
    >>> valmap(sum, bills)  # doctest: +SKIP
    {'Alice': 65, 'Bob': 45}

    See Also:
        keymap
        itemmap
    )r4   ÚzipÚkeysÚmapÚvalues©r7   r6   r#   r5   s       r*   r   r   e   sJ   € ð 
ˆ‰Œ€BØ‡I‚I�c�!—&’&‘(”(�C  a§h¢h¡j¤jÑ1Ô1Ñ2Ô2Ñ3Ô3Ð3Ø€Ir,   úCallable[[_K], _K2]údict[_K2, _V]c           	     óÄ   —  |¦   «         }|                      t          t          | |                     ¦   «         ¦  «        |                     ¦   «         ¦  «        ¦  «         |S )zñApply function to keys of dictionary

    >>> bills = {"Alice": [20, 15, 30], "Bob": [10, 35]}
    >>> keymap(str.lower, bills)  # doctest: +SKIP
    {'alice': [20, 15, 30], 'bob': [10, 35]}

    See Also:
        valmap
        itemmap
    )r4   rB   rD   rC   rE   rF   s       r*   r   r   w   sJ   € ð 
ˆ‰Œ€BØ‡I‚I�c•#�d˜AŸFšF™HœHÑ%Ô% q§x¢x¡z¤zÑ2Ô2Ñ3Ô3Ð3Ø€Ir,   ú!Callable[[tuple[_K, _V]], object]údict[object, object]c                ó„   —  |¦   «         }|                      t          | |                     ¦   «         ¦  «        ¦  «         |S )zÛApply function to items of dictionary

    >>> accountids = {"Alice": 10, "Bob": 20}
    >>> itemmap(reversed, accountids)  # doctest: +SKIP
    {10: "Alice", 20: "Bob"}

    See Also:
        keymap
        valmap
    )r4   rD   r9   rF   s       r*   r   r   ‰   s8   € ð 
ˆ‰Œ€BØ‡I‚I�c�$˜Ÿš™	œ	Ñ"Ô"Ñ#Ô#Ð#Ø€Ir,   Ú	predicateúCallable[[_V], bool]údict[_K, _V]c                ón   —  |¦   «         }|                      ¦   «         D ]\  }} | |¦  «        r|||<   Œ|S )zåFilter items in dictionary by value

    >>> iseven = lambda x: x % 2 == 0
    >>> d = {1: 2, 2: 3, 3: 4, 4: 5}
    >>> valfilter(iseven, d)
    {1: 2, 3: 4}

    See Also:
        keyfilter
        itemfilter
        valmap
    ©r9   ©rM   r6   r#   r5   r<   r=   s         r*   r   r   ›   óI   € ð 
ˆ‰Œ€BØ—’‘	”	ð ð ‰ˆˆ1Øˆ9�Q‰<Œ<ð 	ØˆBˆq‰EøØ€Ir,   úCallable[[_K], bool]c                ón   —  |¦   «         }|                      ¦   «         D ]\  }} | |¦  «        r|||<   Œ|S )zãFilter items in dictionary by key

    >>> iseven = lambda x: x % 2 == 0
    >>> d = {1: 2, 2: 3, 3: 4, 4: 5}
    >>> keyfilter(iseven, d)
    {2: 3, 4: 5}

    See Also:
        valfilter
        itemfilter
        keymap
    rQ   rR   s         r*   r   r   ±   rS   r,   úCallable[[tuple[_K, _V]], bool]c                ór   —  |¦   «         }|                      ¦   «         D ]} | |¦  «        r
|\  }}|||<   Œ|S )a  Filter items in dictionary by item

    >>> def isvalid(item):
    ...     k, v = item
    ...     return k % 2 == 0 and v < 4

    >>> d = {1: 2, 2: 3, 3: 4, 4: 5}
    >>> itemfilter(isvalid, d)
    {2: 3}

    See Also:
        keyfilter
        valfilter
        itemmap
    rQ   )rM   r6   r#   r5   Úitemr<   r=   s          r*   r   r   Ç   sN   € ð$ 
ˆ‰Œ€BØ—’‘	”	ð ð ˆØˆ9�T‰?Œ?ð 	Ø‰DˆAˆqØˆBˆq‰EøØ€Ir,   ÚkeyÚvaluec                óN   —  |¦   «         }|                      | ¦  «         |||<   |S )zòReturn a new dict with new key value pair

    New dict has d[key] set to value. Does not modify the initial dictionary.

    >>> assoc({"x": 1}, "x", 2)
    {'x': 2}
    >>> assoc({"x": 1}, "y", 3)  # doctest: +SKIP
    {'x': 1, 'y': 3}
    )r4   )r6   rY   rZ   r#   Úd2s        r*   r   r   á   s,   € ð 
ˆ‰Œ€BØ‡I‚Iˆa�L„L€LØ€B€s�GØ€Ir,   rC   c                ó6  — t          t          |¦  «        } |¦   «         }t          |¦  «        t          | ¦  «        dz  k     r"|                     | ¦  «         |D ]	}||v r||= Œ
n4t	          | ¦  «        }|                     |¦  «         |D ]}| |         ||<   Œ|S )aB  Return a new dict with the given key(s) removed.

    New dict has d[key] deleted for each supplied key.
    Does not modify the initial dictionary.

    >>> dissoc({"x": 1, "y": 2}, "y")
    {'x': 1}
    >>> dissoc({"x": 1, "y": 2}, "y", "x")
    {}
    >>> dissoc({"x": 1}, "y")  # Ignores missing keys
    {'x': 1}
    g333333ã?)r+   r   r2   r4   ÚsetÚdifference_update)r6   rC   r   r#   r\   rY   Ú	remainingr<   s           r*   r   r   ó   s±   € õ �6 6Ñ*Ô*€GØ	ˆ‰Œ€Bå
ˆ4�y„y•3�q‘6”6˜C‘<ÒÐØ
�	Š	�!‰ŒˆØð 	ð 	ˆCØ�bˆyˆyØ�s�Gøð	õ ˜‘F”Fˆ	Ø×#Ò# DÑ)Ô)Ð)Øð 	ð 	ˆAØ�a”DˆBˆq‰EˆEØ€Ir,   úIterable[object]c                ó0   ‡— t          | |ˆfd„‰|¦  «        S )aÓ  Return a new dict with new, potentially nested, key value pair

    >>> purchase = {
    ...     "name": "Alice",
    ...     "order": {"items": ["Apple", "Orange"], "costs": [0.50, 1.25]},
    ...     "credit card": "5555-1234-1234-1234",
    ... }
    >>> assoc_in(purchase, ["order", "costs"], [0.25, 1.00])  # doctest: +SKIP
    {'credit card': '5555-1234-1234-1234',
     'name': 'Alice',
     'order': {'costs': [0.25, 1.00], 'items': ['Apple', 'Orange']}}
    c                ó   •— ‰S ©N© )ÚxrZ   s    €r*   ú<lambda>zassoc_in.<locals>.<lambda>"  s   ø€ ¨€ r,   )r   )r6   rC   rZ   r#   s     ` r*   r   r     s!   ø€ õ$ �Q˜˜o˜o˜o˜o¨u°gÑ>Ô>Ð>r,   Údefaultc                ó^  — t          |¦  «        }t          |¦  «        } |¦   «         x}}|                     | ¦  «         |D ]C}	|| v r(| |         }  |¦   «         }
|
                     | ¦  «         n |¦   «         x} }
|
x||<   }|	}ŒD|| v r || |         ¦  «        ||<   n ||¦  «        ||<   |S )aæ  Update value in a (potentially) nested dictionary

    inputs:
    d - dictionary on which to operate
    keys - list or tuple giving the location of the value to be changed in d
    func - function to operate on that value

    If keys == [k0,..,kX] and d[k0]..[kX] == v, update_in returns a copy of the
    original dictionary with v replaced by func(v), but does not mutate the
    original dictionary.

    If k0 is not a key in d, update_in creates nested dictionaries to the depth
    specified by the keys, with the innermost value set to func(default).

    >>> inc = lambda x: x + 1
    >>> update_in({"a": 0}, ["a"], inc)
    {'a': 1}

    >>> transaction = {
    ...     "name": "Alice",
    ...     "purchase": {"items": ["Apple", "Orange"], "costs": [0.50, 1.25]},
    ...     "credit card": "5555-1234-1234-1234",
    ... }
    >>> update_in(transaction, ["purchase", "costs"], sum)  # doctest: +SKIP
    {'credit card': '5555-1234-1234-1234',
     'name': 'Alice',
     'purchase': {'costs': 1.75, 'items': ['Apple', 'Orange']}}

    >>> # updating a value when k0 is not in d
    >>> update_in({}, [1, 2, 3], str, default="bar")
    {1: {2: {3: 'bar'}}}
    >>> update_in({1: "foo"}, [2, 3, 4], inc, 0)
    {1: 'foo', 2: {3: {4: 1}}}
    )ÚiterÚnextr4   )r6   rC   r7   rh   r#   Úksr<   r5   ÚinnerrY   Údtemps              r*   r   r   %  sÒ   € õR 
ˆd‰Œ€BÝˆR‰Œ€Aà�‘”Ð€BˆØ‡I‚Iˆa�L„L€Làð 	ð 	ˆØ�ˆ6ˆ6Ø�!”ˆAØ�G‘I”IˆEØ�LŠL˜‰OŒOˆOˆOà˜™	œ	Ð!ˆA�à Ð ˆˆa‰�5ØˆˆàˆA€v€vØ�4˜˜!œ‘:”:ˆˆa‰ˆà�4˜‘=”=ˆˆa‰Ø€Ir,   FÚcollÚ
no_defaultÚboolc                ó~   — 	 t          t          j        | |¦  «        S # t          t          t
          f$ r |r‚ |cY S w xY w)a  Returns coll[i0][i1]...[iX] where [i0, i1, ..., iX]==keys.

    If coll[i0][i1]...[iX] cannot be found, returns ``default``, unless
    ``no_default`` is specified, then it raises KeyError or IndexError.

    ``get_in`` is a generalization of ``operator.getitem`` for nested data
    structures such as dictionaries and lists.

    >>> transaction = {
    ...     "name": "Alice",
    ...     "purchase": {"items": ["Apple", "Orange"], "costs": [0.50, 1.25]},
    ...     "credit card": "5555-1234-1234-1234",
    ... }
    >>> get_in(["purchase", "items", 0], transaction)
    'Apple'
    >>> get_in(["name"], transaction)
    'Alice'
    >>> get_in(["purchase", "total"], transaction)
    >>> get_in(["purchase", "items", "apple"], transaction)
    >>> get_in(["purchase", "items", 10], transaction)
    >>> get_in(["purchase", "total"], transaction, 0)
    0
    >>> get_in(["y"], {}, no_default=True)
    Traceback (most recent call last):
        ...
    KeyError: 'y'

    See Also:
        itertoolz.get
        operator.getitem
    )r   ÚoperatorÚgetitemÚKeyErrorÚ
IndexErrorr'   )rC   ro   rh   rp   s       r*   r   r   f  s^   € ðJ	ÝÝÔØØñ
ô 
ð 	
øõ
 •j¥)Ð,ð ð ð Øð 	ØØˆˆˆðøøøs   ‚ �<»<Úindexc                ó¼   ‡ — t          ‰ t          ¦  «        r3t          ‰ ¦  «        dk    r‰ d         Š ˆ fd„S ‰ rt          j        ‰ Ž S d„ S t          j        ‰ ¦  «        S )Nr1   r   c                ó   •— | ‰         fS rd   re   )rf   rw   s    €r*   rg   zgetter.<locals>.<lambda>›  s   ø€ ˜a œh˜[€ r,   c                ó   — dS )Nre   re   )rf   s    r*   rg   zgetter.<locals>.<lambda>Ÿ  s   € ˜R€ r,   )r3   Úlistr2   rs   Ú
itemgetter)rw   s   `r*   Úgetterr}   —  sk   ø€ Ý�%�ÑÔð 	*Ýˆu‰:Œ:˜Š?ˆ?Ø˜!”HˆEØ(Ð(Ð(Ð(Ð(Øð 	 ÝÔ&¨Ð.Ð.à�<ÐåÔ" 5Ñ)Ô)Ð)r,   Úseqúdict[object, list[object]]c                óö   — t          | ¦  «        st          | ¦  «        } t          j        d„ ¦  «        }|D ]} | | |¦  «                 |¦  «         Œi }|                     ¦   «         D ]\  }}|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]}

    Non-callable keys imply grouping on a member.

    >>> groupby(
    ...     "gender",
    ...     [
    ...         {"name": "Alice", "gender": "F"},
    ...         {"name": "Bob", "gender": "M"},
    ...         {"name": "Charlie", "gender": "M"},
    ...     ],
    ... )  # doctest:+SKIP
    {'F': [{'gender': 'F', 'name': 'Alice'}],
     'M': [{'gender': 'M', 'name': 'Bob'},
           {'gender': 'M', 'name': 'Charlie'}]}

    Not to be confused with ``itertools.groupby``

    See Also:
        countby
    c                 ó   — g j         S rd   )r:   re   r,   r*   rg   zgroupby.<locals>.<lambda>Ä  s   € ¨¬	€ r,   )Úcallabler}   ÚcollectionsÚdefaultdictr9   Ú__self__)rY   r~   r6   rX   r5   r<   r=   s          r*   Úgroupbyr†   ¤  s‘   € õ< �C‰=Œ=ð Ý�S‰kŒkˆÝÔÐ 1Ð 1Ñ2Ô2€AØð ð ˆØˆˆ#ˆ#ˆd‰)Œ)Œ�TÑÔÐÐØ%'€BØ—’‘	”	ð ð ‰ˆˆ1Ø”
ˆˆ1‰ˆØ€Ir,   úIterable[_T]c                ó:   — t          t          | ¦  «        ¦  «        S )zBThe first element in a sequence

    >>> first("ABC")
    'A'
    )rk   rj   )r~   s    r*   Úfirstr‰   Í  s   € õ •�S‘	”	‰?Œ?Ðr,   )r   r   r   r   r    r!   )r-   r.   r   r/   r    r/   )r7   r   r-   r.   r   r/   r    r/   )r7   r>   r6   r?   r#   r!   r    r@   )r7   rG   r6   r?   r#   r!   r    rH   )r7   rJ   r6   r?   r#   r!   r    rK   )rM   rN   r6   r?   r#   r!   r    rO   )rM   rT   r6   r?   r#   r!   r    rO   )rM   rV   r6   r?   r#   r!   r    rO   )
r6   r?   rY   r/   rZ   r/   r#   r!   r    rO   )r6   r.   rC   r/   r   r/   r    r/   )
r6   r.   rC   ra   rZ   r/   r#   r!   r    r/   )r6   r.   rC   ra   r7   r   rh   r/   r#   r!   r    r/   )NF)
rC   ra   ro   r/   rh   r/   rp   rq   r    r/   )rw   r/   r    r   )rY   r/   r~   ra   r    r   )r~   r‡   r    r   )%Ú
__future__r   rƒ   rs   Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   r	   r
   r   r   r   r   Ú__all__r+   r   r   r&   r   r   r   r   r   r   r   r   r   r   r   r}   r†   r‰   re   r,   r*   ú<module>r�      s·  ðØ "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )ð ð 3Ø2Ð2Ð2Ð2Ð2Ð2Ð2Ð2à€WˆT�]„]€Ø€WˆT�]„]€Ø€gˆe�n„n€Ø€gˆe�n„n€Ø€WˆT�]„]€ðð ð €ð"ð ð ð ðð ð ð ð0)ð )ð )ð )ð@ DHðð ð ð ð ð& DHðð ð ð ð ð& RVðð ð ð ð ð& JNðð ð ð ð ð. JNðð ð ð ð ð. UYðð ð ð ð ð6 EIðð ð ð ð ð$ð ð ð ðB ð	?ð ?ð ?ð ?ð ?ð2 Øð>ð >ð >ð >ð >ðH Øð	.ð .ð .ð .ð .ðb
*ð 
*ð 
*ð 
*ð&ð &ð &ð &ðRð ð ð ð ð r,   