
    ^jJ/                       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ddZddZ	 	 	 	 	 	 	 	 d dZef	 	 	 	 	 	 	 d!dZef	 	 	 	 	 	 	 d"dZef	 	 	 	 	 	 	 d#dZef	 	 	 	 	 	 	 d$dZef	 	 	 	 	 	 	 d%dZef	 	 	 	 	 	 	 d&dZef	 	 	 	 	 	 	 	 	 d'dZd(dZef	 	 	 	 	 	 	 	 	 d)dZdef	 	 	 	 	 	 	 	 	 	 	 d*dZ 	 	 d+	 	 	 	 	 	 	 	 	 d,dZ!d-dZ"d.dZ#d/dZ$y)0    )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_inc                    |j                  dt              }|r,t        | j                   d|j	                         d    d      |S )Nfactoryz'() got an unexpected keyword argument 'r   ')popdict	TypeError__name__popitem)fkwargsr   s      ~/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/fx/experimental/unification/unification_tools.py_get_factoryr'   %   sM    JJy$/GzzlA&..BRSTBUAVVWX
 	
 N    c                     t        |       dk(  rt        | d   t              s| d   } t        t        |      } |       }| D ]  }|j                  |        |S )zMerge 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)dictsr%   r   rvds        r&   r   r   .   sW     5zQz%(G<a5&)G	B 
		!Ir(   c                   t        |      dk(  rt        |d   t              s|d   }t        t        |      } |       }|D ]9  }|j                         D ]$  \  }}||vr|g||<   ||   j                  |       & ; t        | ||      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
    r*   r   )r+   r,   r   r'   r   itemsappendr   )funcr.   r%   r   resultr0   kvs           r&   r   r   F   s    " 5zQz%(G<a:v.GYF $GGI 	$DAqCq	q	  #		$$ $((r(   c           
          |       }|j                  t        |j                         t        | |j	                                            |S )zApply 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
    )r-   zipkeysmapvaluesr4   r0   r   r/   s       r&   r   r   e   s6     
BIIc!&&(Cahhj123Ir(   c           	          |       }|j                  t        t        | |j                               |j	                                      |S )zApply 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
    )r-   r9   r;   r:   r<   r=   s       r&   r   r   w   s6     
BIIc#dAFFH%qxxz23Ir(   c                f     |       }|j                  t        | |j                                      |S )zApply function to items of dictionary

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

    See Also:
        keymap
        valmap
    )r-   r;   r2   r=   s       r&   r   r      s)     
BIIc$	"#Ir(   c                `     |       }|j                         D ]  \  }} | |      s|||<    |S )zFilter 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
    r2   	predicater0   r   r/   r6   r7   s         r&   r   r      ;     
B	 1Q<BqE Ir(   c                `     |       }|j                         D ]  \  }} | |      s|||<    |S )zFilter 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
    rA   rB   s         r&   r   r      rD   r(   c                d     |       }|j                         D ]  } | |      s|\  }}|||<    |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
    rA   )rC   r0   r   r/   itemr6   r7   s          r&   r   r      s@    $ 
B	 T?DAqBqE Ir(   c                @     |       }|j                  |        |||<   |S )zReturn 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}
    )r-   )r0   keyvaluer   d2s        r&   r   r      s$     
BIIaLBsGIr(   c                   t        t        |      } |       }t        |      t        |       dz  k  r"|j                  |        |D ]
  }||v s||=  |S t	        |       }|j                  |       |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   r+   r-   setdifference_update)r0   r:   r%   r   rK   rI   	remainingr6   s           r&   r   r      s     66*G	B
4y3q6C<
		! 	CbysG	 I	 F	##D) 	AaDBqE	Ir(   c                (    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 )xrJ   s    r&   <lambda>zassoc_in.<locals>.<lambda>"  s     r(   )r   )r0   r:   rJ   r   s     ` r&   r   r     s    $ Qoug>>r(   c                   t        |      }t        |      } |       x}}|j                  |        |D ]6  }	|| v r| |   }  |       }
|
j                  |        n	 |       x} }
|
x||<   }|	}8 || v r || |         ||<   |S  ||      ||<   |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nextr-   )r0   r:   r4   defaultr   ksr6   r/   innerrI   dtemps              r&   r   r   %  s    R 
dBRABIIaL 	6!AIELLO	!A  a5	 	Av!:a I =aIr(   c                x    	 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!   )r:   collrY   
no_defaults       r&   r   r   f  sG    J	
 	

 j), s    99c                     t         t              r/t               dk(  r
 d     fdS  rt        j                    S d S t        j                         S )Nr*   r   c                    |    fS rR   rS   )rT   indexs    r&   rU   zgetter.<locals>.<lambda>  s    ah[ r(   c                     y)NrS   rS   )rT   s    r&   rU   zgetter.<locals>.<lambda>  s    r(   )r,   listr+   r^   
itemgetter)rf   s   `r&   getterrj     sR    %u:?!HE((&&..""5))r(   c                    t        |       st        |       } t        j                  d       }|D ]  } | | |         |        i }|j	                         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 rR   )r3   rS   r(   r&   rU   zgroupby.<locals>.<lambda>  s
    		 r(   )callablerj   collectionsdefaultdictr2   __self__)rI   seqr0   rG   r/   r6   r7   s          r&   groupbyrr     sv    < C=Sk 12A #d)T%'B	 1

1Ir(   c                *    t        t        |             S )zBThe first element in a sequence

    >>> first("ABC")
    'A'
    )rX   rW   )rq   s    r&   firstrt     s     S	?r(   )r$   Callable[..., object]r%   zdict[str, object]returntype)r.   Mapping[object, object]r%   objectrv   ry   )r4   ru   r.   rx   r%   ry   rv   ry   )r4   zCallable[[_V], _V2]r0   Mapping[_K, _V]r   rw   rv   zdict[_K, _V2])r4   zCallable[[_K], _K2]r0   rz   r   rw   rv   zdict[_K2, _V])r4   z!Callable[[tuple[_K, _V]], object]r0   rz   r   rw   rv   zdict[object, object])rC   zCallable[[_V], bool]r0   rz   r   rw   rv   dict[_K, _V])rC   zCallable[[_K], bool]r0   rz   r   rw   rv   r{   )rC   zCallable[[tuple[_K, _V]], bool]r0   rz   r   rw   rv   r{   )
r0   rz   rI   ry   rJ   ry   r   rw   rv   r{   )r0   rx   r:   ry   r%   ry   rv   ry   )
r0   rx   r:   Iterable[object]rJ   ry   r   rw   rv   ry   )r0   rx   r:   r|   r4   ru   rY   ry   r   rw   rv   ry   )NF)
r:   r|   rb   ry   rY   ry   rc   boolrv   ry   )rf   ry   rv   ru   )rI   ry   rq   r|   rv   zdict[object, list[object]])rq   zIterable[_T]rv   r   )%
__future__r   rn   r^   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   rj   rr   rt   rS   r(   r&   <module>r      s   "   #  ) 2T]T]enenT]"0)
))@)LR))@ DH
"1<@& DH
"1<@& RV
+0?JN& JN#(7BF. JN#(7BF. UY.3BMQ6 EI#,2=A$B 	??
? ? 	?
 ?2 >>
>  > 	>
 > >H 	.
.
. . 	.
 .b
*&Rr(   