
    $Sh                        d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 er
ddlmZmZmZ dddd(dZe
d)d            Ze
d*d            Ze
d+d            Ze
d,d!            Zd-d#Zd.d'ZdS )/zUtility functions for OpTree.    )annotations)IterableSequence)TYPE_CHECKINGAnyCallableoverload)STUNFkeyreverseiterableIterable[T]r   Callable[[T], Any] | Noner   boolreturnlist[T]c                  t          |           }	 t          ||          S # t          $ r7 d	d}nd	fd}	 t          |||          cY S # t          $ r |cY cY S w xY ww xY w)
zSort an iterable in a total order.

    This is useful for sorting objects that are not comparable, e.g., dictionaries with different
    types of keys.
    r   Nxr   r   tuple[str, Any]c                <    | j         j         d| j         j         | fS N.	__class__
__module____qualname__)r   s    R/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/optree/utils.pykey_fnz"total_order_sorted.<locals>.key_fn/   s&    ;1NNAK4LNNPQRR    c                T     |           }|j         j         d|j         j         |fS r   r   )r   yr   s     r    r!   z"total_order_sorted.<locals>.key_fn4   s4    CFF;1NNAK4LNNPQRRr"   )r   r   r   r   )listsorted	TypeError)r   r   r   sequencer!   s    `   r    total_order_sortedr)      s     H~~HhC9999   ;S S S S S
S S S S S S	 (@@@@@@ 	 	 	OOOOO	!s,   $ A%AA%A!A% A!!A%iter1zip[tuple[T]]c                   d S N )r*   s    r    safe_zipr/   @   s	     Cr"   iter2Iterable[S]zip[tuple[T, S]]c                   d S r-   r.   )r*   r0   s     r    r/   r/   G   s	    
 sr"   iter3Iterable[U]zip[tuple[T, S, U]]c                   d S r-   r.   )r*   r0   r4   s      r    r/   r/   O   s	     #r"   Iterable[Any]iter4iterszip[tuple[Any, ...]]c                   d S r-   r.   )r*   r0   r4   r9   r:   s        r    r/   r/   X   s	     3r"   argsc            	         d | D             }t          t          t          t           |                              dk    r2t          dt	          t          t           |                               t          | S )z=Strict zip that requires all arguments to be the same length.c                Z    g | ](}t          |t                    r|nt          |          )S r.   )
isinstancer   r%   ).0args     r    
<listcomp>zsafe_zip.<locals>.<listcomp>e   s1    LLL:c8,,;CC$s))LLLr"      zlength mismatch: )lensetmap
ValueErrorr%   zip)r=   seqss     r    r/   r/   c   si    LLtLLLD
3s3~~!##CT#c4..-A-ACCDDD:r"   xysIterable[tuple[T, S]]#tuple[tuple[T, ...], tuple[S, ...]]c                   g }g }| D ]/\  }}|                     |           |                     |           0t          |          t          |          fS )z2Unzip sequence of length-2 tuples into two tuples.)appendtuple)rK   xsysr   r$   s        r    unzip2rS   k   sX    
 
B	B  1
		!
		!99eBiir"   )r   r   r   r   r   r   r   r   )r*   r   r   r+   )r*   r   r0   r1   r   r2   )r*   r   r0   r1   r4   r5   r   r6   )r*   r8   r0   r8   r4   r8   r9   r8   r:   r8   r   r;   )r=   r8   r   r;   )rK   rL   r   rM   )__doc__
__future__r   collections.abcr   r   typingr   r   r   r	   optree.typingr
   r   r   r)   r/   rS   r.   r"   r    <module>rY      s\   $ # " " " " " " . . . . . . . . 9 9 9 9 9 9 9 9 9 9 9 9  &%%%%%%%%%% &*" " " " " "J 
   
 
   
 
   
 
   
   
  
  
  
  
  
 r"   