§
    5P„jª  ã                  óÖ   — 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)
z�Sort 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    úQ/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/optree/utils.pyÚkey_fnz"total_order_sorted.<locals>.key_fn/   s&   € Øœ;Ô1ÐNÐN°A´KÔ4LÐNÐNÐPQÐ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˜‘F”F�Øœ;Ô1ÐNÐN°A´KÔ4LÐNÐNÐPQÐRÐRr"   )r   r   r   r   )ÚlistÚsortedÚ	TypeError)r   r   r   Úsequencer!   s    `   r    Útotal_order_sortedr)      sÖ   ø€ õ �H‰~Œ~€Hðå�h C°Ð9Ñ9Ô9Ð9øÝð ð ð Øˆ;ðSð Sð Sð Sð Sð
Sð Sð Sð Sð Sð Sð	õ ˜(¨¸Ð@Ñ@Ô@Ð@Ð@Ð@øÝð 	ð 	ð 	ØˆOˆOˆOˆOˆOð	øøøð!øøø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À•:˜c¥8Ñ,Ô,Ð;ˆCˆCµ$°s±)´)ÐLÐLÐLr"   é   zlength mismatch: )ÚlenÚsetÚmapÚ
ValueErrorr%   Úzip)r=   Úseqss     r    r/   r/   c   si   € àLÐLÀtÐLÑLÔL€DÝ
�3�s•3˜‰~Œ~ÑÔÑÔ !Ò#Ð#ÝÐC­Tµ#µc¸4±.´.Ñ-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Ø
�	Š	�!‰ŒˆØ
�	Š	�!‰ŒˆˆÝ�‰9Œ9•e˜B‘i”iÐÐ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"   