
    Vpf	N                    "   U d dl mZ d dlZd dlmZmZmZmZ d dlZd dlm	Z	 d dl
Zd dlZd dlZd dlmZmZmZmZmZ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  ej        e           Z!eZ" ed	          Z# ed
          Z$ ed          Z% ed          Z&er4edd            Z'edd            Z'edd            Z'edd            Z'd Z'nej'        Z'er4edd"            Z(edd$            Z(edd&            Z(edd(            Z(d) Z(nej(        Z(dd-Z)dd1Z*d2 Z+dd8Z,dd9Z-dd>Z.ddDZ/ddIZ0ddNZ1dO Z2ddRZ3e3Z4 e5            Z6ddTZ7dU Z8dV Z9dW Z:dX Z;dY Z<dZ Z=dd]Z> ej?                    a@d^ ZA e>d_          ZB	 	 dddeZC ej?                    aDdf ZE G dg dh          ZF G di dj          ZG G dk dl          ZHdm ZIddoZJddpZKddrZLds ZMdt ZN	 	 dddzZOd{ ZPd| ZQd} ZRd~ ZS G d d          ZTd ZU G d d          ZVd ZWd ZXddZY G d dee#                   ZZ G d d          Z[d Z\ddZ]er
ddZ^dddZ_nd Z^ddZ_	 ej`        ja        Zbdecd<   n# ed$ r
 eja        ZbY nw xY w G d deje                  Zf G d def          ZgdS )    )annotationsN)CallableIterableIteratorSequence)partial)AnyGenericTypeVaroverloadTYPE_CHECKINGcast)config)
xla_client)utilsTT1T2T3__arg1Iterable[T1]returnlist[tuple[T1]]c                    d S N )r   s    M/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/util.pysafe_zipr   /   s    9<    __arg2Iterable[T2]list[tuple[T1, T2]]c                    d S r   r   )r   r    s     r   r   r   1   s    SVSVr   __arg3Iterable[T3]list[tuple[T1, T2, T3]]c                    d S r   r   )r   r    r$   s      r   r   r   3   s    mpmpr   Iterable[Any]__arg4list[tuple[Any, ...]]c                    d S r   r   )r   r    r$   r)   argss        r   r   r   5   s     MP  MPr   c            	     6   t          t          t           |                     } t          | d                   }| dd          D ]B}t          |          |k    s-J dt          t          t          |                                  Ct          t          |            S Nr      zlength mismatch: )listmaplenzip)r,   nargs      r   r   r   8   s    D$  DDGAABBx G GXX]]]FSd^^0D0DFF]]]]T
r   fCallable[[T1], T]list[T]c                    d S r   r   )r6   r   s     r   safe_mapr:   G   s    GJsr   Callable[[T1, T2], T]c                    d S r   r   )r6   r   r    s      r   r:   r:   J   s    adadr   Callable[[T1, T2, T3], T]c                    d S r   r   )r6   r   r    r$   s       r   r:   r:   M   s    {~{~r   Callable[..., T]c                    d S r   r   )r6   r   r    r$   r)   r,   s         r   r:   r:   P   s     TW  TWr   c           	     >   t          t          t           |                    }t          |d                   }|dd          D ]B}t          |          |k    s-J dt          t          t          |                                 Ct          t          | g|R            S r.   )r0   r1   r2   )r6   r,   r4   r5   s       r   r:   r:   S   s    D$  DDGAABBx G GXX]]]FSd^^0D0DFF]]]]Ar   xysIterable[tuple[T1, T2]]%tuple[tuple[T1, ...], tuple[T2, ...]]c                    g }g }| D ]/\  }}|                     |           |                     |           0t          |          t          |          fS )z2Unzip sequence of length-2 tuples into two tuples.appendtuple)rB   xsysxys        r   unzip2rM   ]   sX    
 ""  daIIaLLLIIaLLLL	rE"II	r   xyzsIterable[tuple[T1, T2, T3]]5tuple[tuple[T1, ...], tuple[T2, ...], tuple[T3, ...]]c                    g }g }g }| D ]E\  }}}|                     |           |                     |           |                     |           Ft          |          t          |          t          |          fS )z4Unzip sequence of length-3 tuples into three tuples.rF   )rN   rI   rJ   zsrK   rL   zs          r   unzip3rT   i   sv    
 """  gaAIIaLLLIIaLLLIIaLLLL	rE"IIuRyy	((r   c                X    t          |           } |D ]
\  }}|| |<   t          |           S r   )r0   rH   )lstreplaceivs       r   subvalsrZ   w   s7    S		#  daCFF	sr   r,   Sequence[T]nsSequence[int]list[list[T]]c                    t          |           } g }|D ])}|                    | d |                    | |d          } *|                    |            |S r   )r0   rG   r,   r\   listsr4   s       r   
split_listrb   }   sa    	d$
%  a	LLbqb8DD,,t	,r   c                    t          |           } t          |          t          |           k    sJ g }|D ])}|                    | d |                    | |d          } *|S r   )r0   sumr2   rG   r`   s       r   split_list_checkedre      sl    	d$	RCII				
%  a	LLbqb8DD	,r   bsSequence[bool]ltuple[list[T], list[T]]c                    t          |           t          |          k    sJ g g f}t          | |          D ] \  }}||                             |           !|S r   )r2   r3   rG   )rf   rh   ra   brK   s        r   partition_listrl      sa    	RCFF				
b&%"ajj  da	!HOOA	,r   l0Sequence[T1]l1Sequence[T2]list[T1 | T2]c                x   t          |           t          |          k    r0t          |           t          |           z
  t          |          k    sJ t          |          t          |          cfd| D             }t                      }t	          |          t	          |          cxu r|u sn J |S )Nc                P    g | ]"}|rt                    nt                    #S r   next).0rk   i0i1s     r   
<listcomp>zmerge_lists.<locals>.<listcomp>   s.    @@@A3R488@@@r   )rd   r2   iterobjectru   )rf   rm   ro   outsentinelrw   rx   s        @@r   merge_listsr~      s     
RCGG		B#b'' 1SWW < < < <88T"XX&"b@@@@@R@@@#XX(	b(		tB11	=	=	=	=X	=	=	=	=	=	=	*r   subsSequence[int | None]srcbasec                    t          |          fd| D             }t                      }t          |          |u sJ |S )Nc                B    g | ]}||         nt                    S r   rt   )rv   rX   base_r   s     r   ry   zsubs_list.<locals>.<listcomp>   s+    @@@a1=Qd5kk@@@r   )rz   r{   ru   )r   r   r   r|   r}   r   s    `   @r   	subs_listr      sV     t**%@@@@@4@@@#XX(	eX		(	*	*	*	*	*r   subs1subs2src1src2c                    t          |           t          |          k    sJ t          |          fdt          | |          D             }t                      }t	          |          |u sJ |S )Nc                \    g | ](\  }}||         n||         nt                    )S r   rt   )rv   f1f2r   r   r   s      r   ry   zsubs_list2.<locals>.<listcomp>   sL     	7 	7 	7 R ^bR^b	e	7 	7 	7r   )r2   rz   r3   r{   ru   )r   r   r   r   r   r|   r}   r   s     ``   @r   
subs_list2r      s     
Us5zz	!	!	!	!
t**%	7 	7 	7 	7 	7 	7$'u$5$5	7 	7 	7#XX(	eX		(	*	*	*	*	*r   c                J     t                       fd|D             } rJ |S )Nc                :    g | ]}                     |          S r   )pop)rv   namedcts     r   ry   zsplit_dict.<locals>.<listcomp>   s#    )))4)))r   )dict)r   namesrV   s   `  r   
split_dictr      s5    S		#))))5)))#...	*r   rI   Iterable[Sequence[T]]c                Z    t          t          j                            |                     S )z&Concatenates/flattens a list of lists.)r0   itchainfrom_iterable)rI   s    r   concatenater      s     	bh$$R((	)	))r   Iterable[T]c                ~    t          |           fd|D             }t          t                    t          u sJ |S )zpSplits `xs` into subsequences of lengths `ns`.

  Unlike `split_list`, the `sum(ns)` must be equal to `len(xs)`.c                F    g | ]}fd t          |          D             S )c                .    g | ]}t                    S r   rt   )rv   _xs_iters     r   ry   z(unflatten.<locals>.<listcomp>.<listcomp>   s    222A$w--222r   )range)rv   r4   r   s     r   ry   zunflatten.<locals>.<listcomp>   s4    ???q2222q222???r   )rz   ru   _unflatten_done)rI   r\   unflattenedr   s      @r   	unflattenr      sJ     HH'????B???+	g	'	'?	:	:	:	:	r   c                X     t          |           t          t          |                     S )zCurries arguments of f, returning a function on any remaining arguments.

  For example:
  >>> f = lambda x, y, z, w: x * y + z * w
  >>> f(2,3,4,5)
  26
  >>> curry(f)(2)(3, 4, 5)
  26
  >>> curry(f)(2, 3)(4, 5)
  26
  >>> curry(f)(2, 3, 4, 5)()
  26
  )wrapsr   r6   s    r   curryr      s$     
q''1%%	&	&&r   c                   | sg S t          |           } i t          |           }|rq|                                }t          |          v rt          |          xx         dz  cc<   n,dt          |          <   |                    |j                   |q| D ]}t          |          xx         dz  cc<    g }fd| D             }|sJ |r|                                }|                    |           |j        D ]N}t          |                   dk    r|                    |           1t          |          xx         dz  cc<   O||d d d         }t          |           |S )Nr/   c                F    g | ]}t          |                   d k    |S )r   id)rv   nodechild_countss     r   ry   ztoposort.<locals>.<listcomp>   s.    OOOd<43IQ3N3NT3N3N3Nr   )_remove_duplicatesr0   r   r   extendparentsrG   check_toposort)	end_nodesstackr   sorted_nodeschildless_nodesparentr   s         @r   toposortr      s   	2I ++),
y//% !99;;D	$xx<2d88! l2d88ll4<    	 !     dDa,OOOOiOOO/	 &  D, & &	bjj	!Q	&	&v&&&&RZZ   A%     	 & ddd#,	r   c                    t                      | D ]F}t          fd|j        D                       sJ                     t	          |                     Gd S )Nc              3  :   K   | ]}t          |          v V  d S r   r   )rv   r   visiteds     r   	<genexpr>z!check_toposort.<locals>.<genexpr>  s.      @@r&zzW$@@@@@@r   )setallr   addr   )nodesr   r   s     @r   r   r      sk    EE'  d@@@@4<@@@@@@@@KK4 r   c                    t                      }g }| D ]J}t          |          |vr7|                    t          |                     |                    |           K|S r   )r   r   r   rG   )	node_listseenr|   r4   s       r   r   r     sZ    	$
#  a	!uuD
hhr!uuooo	jjmmm	*r   c                    t          t          | |                    d t          |          D             }d t          |          D             }fd}|||fS )Nc                    g | ]	\  }}||
S r   r   rv   rK   ss      r   ry   zsplit_merge.<locals>.<listcomp>  s!    +++tq!++++r   c                    g | ]	\  }}||
S r   r   r   s      r   ry   zsplit_merge.<locals>.<listcomp>  s!    ///tq!Q////r   c                    g }D ]O}|r&|                     | d                    | dd          } *|                     |d                    |dd          }P|rJ | rJ |S Nr   r/   )rG   )new_lhsnew_rhsr|   r   sidess       r   mergezsplit_merge.<locals>.merge  s    
C  	
 

71:!""+

71:!""+Jr   )r0   r1   r3   )	predicaterI   lhsrhsr   r   s        @r   split_merger     sw    
s9b!!
"
"%++s2u~~+++#//s2u~~///#     
c5r   c                     d S r   r   r   r   r   _ignorer   !  s    ddr      Tc                      fd}|S )Nc                     t          j                   fd            t          j                    fd            }j        |_        j        |_        t
                              |j                   |S )Nc                     |i |S r   r   )r   r,   kwargsr6   s      r   cachedz#cache.<locals>.wrap.<locals>.cached&  s    Qr   c                     t           j        j        r | i |S  rt          j                    nt	                      g| R i |S r   )r   check_tracer_leaksvaluetrace_contextr   )r,   r   r   r6   trace_context_in_keys     r   wrapperz$cache.<locals>.wrap.<locals>.wrapper*  sn    		"	( "q$!&!!!V.BQF(***		 %% % %#% % %r   )	functools	lru_cacher   cache_clear
cache_infocache_clearing_funsr   )r6   r   r   max_sizer   s   ` @r   wrapzcache.<locals>.wrap%  s    ""        #"  _Q% % % % % % % !,G*GG/000Nr   r   )r   r   r   s   `` r   cacher   $  s)           
+r   c                 .    t           D ]}  |              d S r   )r   )clears    r   clear_all_cachesr   9  s(    "  e	EGGGG r   )r      callr   r   boolc                    t          j        |rt          j        nt          | |          }t
                              |           |S )a	  
  Least recently used cache decorator with weakref support.

  The cache will take a weakref to the first argument of the wrapped function
  and strong refs to all subsequent operations. In all other respects it should
  behave similar to `functools.lru_cache`.
  )xcweakref_lru_cacher   r   r   _weakref_lru_cachesr   )r   maxsizer   cached_calls       r   r   r   @  sG     $2?f
G + +&&&	r   c                 B    t           D ]} |                                  d S r   )r   r   )r   s    r   clear_all_weakref_lru_cachesr   R  s0    (  k r   c                       e Zd ZdgZd Zd ZdS )
Unhashablevalc                    || _         d S r   r   selfr   s     r   __init__zUnhashable.__init__Y      DHHHr   c                "    | j         |j         k    S r   r   r  others     r   __eq__zUnhashable.__eq__\      8uy  r   N)__name__
__module____qualname__	__slots__r  r  r   r   r   r   r   V  s9        g)  ! ! ! ! !r   r   c                  &    e Zd ZdgZd Zd Zd ZdS )Hashabler   c                    || _         d S r   r   r   s     r   r  zHashable.__init__b  r  r   c                *    t          | j                  S r   )hashr   r  s    r   __hash__zHashable.__hash__e  s    >>r   c                "    | j         |j         k    S r   r   r  s     r   r  zHashable.__eq__h  r  r   Nr	  r
  r  r  r  r  r  r   r   r   r  r  _  sH        g)    ! ! ! ! !r   r  c                  &    e Zd ZdgZd Zd Zd ZdS )
WrapKwArgsr   c                    || _         d S r   r   r   s     r   r  zWrapKwArgs.__init__n  r  r   c           	         t          t          d t          | j                                                  D                                 S )Nc              3  $   K   | ]\  }}||fV  d S r   r   )rv   krY   s      r   r   z&WrapKwArgs.__hash__.<locals>.<genexpr>r  s*      BBAq!fBBBBBBr   )r  rH   sortedr   itemsr  s    r   r  zWrapKwArgs.__hash__q  s;    BB0@0@)A)ABBBBBCCCr   c                "    | j         |j         k    S r   r   r  s     r   r  zWrapKwArgs.__eq__t  r  r   Nr  r   r   r   r  r  k  sK        g)  D D D! ! ! ! !r   r  c                    |dz   | z   dz   S )N()r   )r   transform_names     r   	wrap_namer#  w  s    	#		$s	**r   func                $    t          | dd          S )Nr	  <unnamed function>getattrr$  s    r   fun_namer*  z  s    	j"6	7	77r   c           	     B    t          | dt          | dd                    S )Nr  r	  r&  r'  r)  s    r   fun_qual_namer,  }  s+    	nj*>??
A 
A Ar   intc                    t          j        |           } | | cxk    r|k     sn t          d|  d|           | dk     r| |z   } | S )z?Canonicalize an axis in [-num_dims, num_dims) to [0, num_dims).zaxis z) is out of bounds for array of dimension r   )operatorindex
ValueError)axisnum_dimss     r   canonicalize_axisr4    sh    			$
d	%	%	%	%X	%	%	%	%
VTVVHVV
W
WW	AXX(?D	+r   c                    |k    r S t          t                    rft          |t                    r|f} fdD              fd|D             }fdt          t          j                             D             }t          t          |                    D ]\  }}|                    ||                                |          S )Nc                :    g | ]}t          |j                  S r   r4  ndimrv   arK   s     r   ry   zmoveaxis.<locals>.<listcomp>  &    333!	1af	%	%333r   c                :    g | ]}t          |j                  S r   r7  r9  s     r   ry   zmoveaxis.<locals>.<listcomp>  r;  r   c                    g | ]}|v|	S r   r   )rv   rX   r   s     r   ry   zmoveaxis.<locals>.<listcomp>  s    	7	7	7!3,,!,,,r   )	
isinstancer-  r   npr8  r  r3   insert	transpose)rK   r   dstpermdr   s   ``    r   moveaxisrE    s    CZZHS &CS &C3333s333#3333s333#	7	7	7	7U271::&&	7	7	7$Sc]]##  daKK1	
T		r   c                    |  |z   S r   r   )rK   rL   s     r   ceil_of_ratiorG    s    27r   wrappednamestr
str | NonedocstrCallable[[T], T]c                      d fd}|S )zs
  Like functools.wraps, but with finer-grained control over the name and docstring
  of the resulting function.
  r$  r   r   c                   	 t                    }t          dd          pd}| j                            t          di                      t          di           | _        |n                    |          | _        t          dd          | _        |n j        d
||d| _        t          d	| j                  | _	        | _
        | S # | c cY S xY w)N__doc__ __dict____annotations__r)  r
  z<unknown module>)r$  docr  r   )r*  r(  rQ  updaterR  formatr	  r
  rO  r  __wrapped__)r$  r   rS  rK  r   rI  rH  s      r   r   zwraps.<locals>.wrapper  s    gdGY++1rc	l'':r::;;;#G->CCc$_TT'..T.2J2Jclw6HIIcn"NSS'&-DDcDDVDD 
k .#,GGccojSjjjjjjjjs   CC C)r$  r   r   r   r   )rH  rI  rK  r   r   s   ```` r   r   r     s:             
.r   c                J    t          dt          |           j                   )NzUnhandled case: )AssertionErrortyper	  )rK   s    r   assert_unreachablerZ    s"    <$q''*:<<===r   c                    d|cxk    rt          |           k    sn J |t          |           f            | d |         |fz   | |d          z   S Nr   r2   tidxr   s      r   tuple_insertra    sa    	
c				SVV					c3q66]				
4C4C6	AcddG	##r   c                    d|cxk    rt          |           k     sn J |t          |           f            | d |         | |dz   d          z   S r   r]  )r_  r`  s     r   tuple_deleterc    s^    	
c				CFF					S#a&&M				
4C41S1WXX;	r   c                    d|cxk    rt          |           k     sn J |t          |           f            | d |         |fz   | |dz   d          z   S r   r]  r^  s      r   tuple_updatere    se    	
c				CFF					S#a&&M				
4C4C6	Ac!effI	%%r   c                  0    e Zd ZdZd Zd Zd Zd Zd ZdS )HashableFunctiona
  Decouples function equality and hash from its identity.

  Local lambdas and function defs are reallocated on each function call, making
  the functions created on different calls compare as unequal. This breaks our
  caching logic, which should really only care about comparing the semantics and
  not actual identity.

  This class makes it possible to compare different functions based on their
  semantics. The parts that are taken into account are: the bytecode of the
  wrapped function (which is cached by the CPython interpreter and is stable
  across the invocations of the surrounding function), and `closure` which
  should contain all values in scope that affect the function semantics. In
  particular `closure` should contain all elements of the function closure, or
  it should be possible to derive the relevant elements of the true function
  closure based solely on the contents of the `closure` argument (e.g. in case
  some closed-over values are not hashable, but are entirely determined by
  hashable locals).
  c                "    || _         || _        d S r   r6   closure)r  r6   rj  s      r   r  zHashableFunction.__init__  s    DFDLLLr   c                    t          |          t          u o)| j        j        |j        j        k    o| j        |j        k    S r   )rY  rg  r6   __code__rj  r  s     r   r  zHashableFunction.__eq__  s=    KK++ *FOuw//*LEM)+r   c                B    t          | j        j        | j        f          S r   )r  r6   rl  rj  r  s    r   r  zHashableFunction.__hash__  s    $,/000r   c                     | j         |i |S r   r   r  r,   r   s      r   __call__zHashableFunction.__call__  s    464"6"""r   c                2    d| j         j         d| j         dS )Nz
<hashable z with closure=>)r6   r	  rj  r  s    r   __repr__zHashableFunction.__repr__  s!    FFFt|FFFFr   N)	r	  r
  r  rO  r  r  r  rp  rs  r   r   r   rg  rg    sn         &  + + +
1 1 1# # #G G G G Gr   rg  c                      fdS )Nc                $    t          |           S r   )rg  ri  s    r   <lambda>z&as_hashable_function.<locals>.<lambda>  s    #Aw// r   r   )rj  s   `r   as_hashable_functionrw    s    	/	/	/	//r   c                  &    e Zd Zd Zd Zd Zd ZdS )HashablePartialc                0    || _         || _        || _        d S r   r6   r,   r   )r  r6   r,   r   s       r   r  zHashablePartial.__init__  s    DFDIDKKKr   c                    t          |          t          u o9| j        j        |j        j        k    o| j        |j        k    o| j        |j        k    S r   )rY  ry  r6   rl  r,   r   r  s     r   r  zHashablePartial.__eq__  sQ    KK?* DFOuw//DI#D(,u|(CEr   c           
         t          | j        j        | j        t	          t          | j                                        d                     f          S )Nc                    | d         S r\  r   )kvs    r   rv  z*HashablePartial.__hash__.<locals>.<lambda>  s
    A r   )key)r  r6   rl  r,   rH   r  r   r  r  s    r   r  zHashablePartial.__hash__  sO    	fT[&&((.>.>???@@  r   c                >     | j         g | j        |R i | j        |S r   r{  ro  s      r   rp  zHashablePartial.__call__  s0    46=49=t===t{=f===r   N)r	  r
  r  r  r  r  rp  r   r   r   ry  ry    sS          
E E E
  > > > > >r   ry  c                    	 t          j        |           }d}n# t          $ r d}Y nw xY w|r ||           n
 ||          S )NFT)r/  r0  	TypeError)r2  if_posif_namedposnameds        r   maybe_named_axisr    s`    
.

CEE	   EEE 	1$ffSkk1s    ((c                    t           j        j        rdg}	 |                    | d         d          d| d         d                     | dd         D ] \  }}|                    d| d|            !nB# t          $ r5}|                    d           |                    |            Y d}~nd}~ww xY w|                    d           t
                              d	                    |                     dS dS )
zFormat and log `pairs` if config.jax_distributed_debug is enabled.

  Args:
    pairs: A sequence of label/value pairs to log. The first pair is treated as
    a heading for subsequent pairs.
  z
DISTRIBUTED_DEBUG_BEGINr   z: r/   Nz  z!DISTRIBUTED_DEBUG logging failed!DISTRIBUTED_DEBUG_END
)r   distributed_debugr   rG   	Exceptionloggerwarningjoin)pairslineslabelr   es        r   distributed_debug_logr    s-    # 
%()ElleAhqk22U1Xa[22333) , ,,%*%**5**++++,   ll6777lla6 
LL()))
NN499U##$$$$$
% 
%s   AA4 4
B3>+B..B3r   c                Z    t                               |                                           S )zbReturns unique elements from `it` in the order of occurrence.

  The elements must be hashable.
  )r   fromkeyskeys)r   s    r   stable_uniquer  $  s"    
 
r					!	!!r   c                  R    e Zd ZU ded<   ded<   d Zdd
ZddZddZddZddZ	dS )
OrderedSetzset[T]elts_setr8   	elts_listc                :    t                      | _        g | _        d S r   )r   r  r  r  s    r   r  zOrderedSet.__init__0  s    EEDMDNNNr   eltr   r   Nonec                    || j         vr6| j                             |           | j                            |           d S d S r   )r  r   r  rG   r  r  s     r   r   zOrderedSet.add4  sI    
$-
m
nC       r   eltsSeq[T]c                :    |D ]}|                      |           d S r   )r   )r  r  r  s      r   rT  zOrderedSet.update9  s,      
hhqkkkk r   Iterator[T]c                *    t          | j                  S r   )rz   r  r  s    r   __iter__zOrderedSet.__iter__=  s    r   r-  c                *    t          | j                  S r   )r2   r  r  s    r   __len__zOrderedSet.__len__@  s    t~r   r   c                    || j         v S r   )r  r  s     r   __contains__zOrderedSet.__contains__C  s    $-r   N)r  r   r   r  )r  r  r   r  )r   r  r   r-  )r  r   r   r   )
r	  r
  r  rR  r  r   rT  r  r  r  r   r   r   r  r  ,  s           ! ! ! !
                        r   r  c                  6    e Zd ZU ded<   ded<   d Zd Zd ZdS )	HashableWrapperr	   rK   z
int | Noner  c                Z    || _         t          |          | _        d S #  d | _        Y d S xY wr   )rK   r  )r  rK   s     r   r  zHashableWrapper.__init__J  s-    DF!WWDIIIIs    	*c                F    | j         | j         nt          | j                  S r   )r  r   rK   r  s    r   r  zHashableWrapper.__hash__N  s    	-4992df::=r   c                z    t          |t                    sdS | j        | j        |j        k    n| j        |j        u S )NF)r>  r  r  rK   r  s     r   r  zHashableWrapper.__eq__P  s=    e_-- U $	 546UW46UW;LLr   N)r	  r
  r  rR  r  r  r  r   r   r   r  r  G  s]         &&&  > > >M M M M Mr   r  c                    t          | t                    rt          t          |           j        S t          | t          j                  r| j        S | S r   )r>  propertyr   fgetr   cached_propertyfuncr   s    r   _original_funcr  V  sH    8 !!!!Y.// 6M	
(r   modulestrc                     d fd}|S )Nr  r   r   c                    | _         | S r   )r
  )r  r  s    r   r   zset_module.<locals>.wrapper_  s    doKr   )r  r   r   r   r   )r  r   s   ` r   
set_moduler  ^  s(          
.r   cpp_clsr	   c                    dd}|S )Nclsr   r   c                    | S r   r   r  s    r   r   zuse_cpp_class.<locals>.wrapperh      jr   r  r   r   r   r   r  r   s     r   use_cpp_classr  g         Nr   
is_enabledc                    dd}|S )Nr  r   r   c                    | S r   r   r  s    r   r   zuse_cpp_method.<locals>.wrapperm  r  r   r  r   )r  r   s     r   use_cpp_methodr  l  r  r   c                      fd}|S )zAA helper decorator to replace a python class with its C++ versionc                    | S h d}i }| j                                         D ]=\  }}||vr4t          t          |          d          r|||<   ,t	          ||           >| j        _        |_        S )N>   rO  rQ  r
  _use_cpp)rQ  r  hasattrr  setattrrO  _original_py_fns)r  exclude_methods	originals	attr_nameattrr  s        r   r   zuse_cpp_class.<locals>.wrapperu  s    	
===oi \//11 . ./)TO++^D)):66 .#'Ii  GY---go!*gnr   r   r  s   ` r   r  r  r  s#        & Nr   c                Z      fd}t           t                    st          d          |S )zRA helper decorator to exclude methods from the set that are forwarded to C++ classc                8    rt          |           }d|_        | S )NT)r  r  )r6   original_funcr  s     r   	decoratorz!use_cpp_method.<locals>.decorator  s%    	 &&q))!%hr   z@Decorator got wrong type: @use_cpp_method(is_enabled: bool=True))r>  r   r  )r  r  s   ` r   r  r    sM         j$'' 
L   r   ztype[Warning]NumpyComplexWarningc                  4    e Zd ZdZd Zej        Zej        ZdS )StrictABCMetaa%  A variant of `abc.ABCMeta` which does not allow virtual subclasses.

  Virtual subclasses support require `abc.ABCMeta` to roundtrip through
  pure Python when doing instance/subclass checking. This if fine for ABCs
  which need virtual subclasses, but is wasteful for the ones which don't.
  c                (    ~t          |  d          )Nz$ does not support virtual subclasses)NotImplementedError)r  subclasss     r   registerzStrictABCMeta.register  s    
JJJ
K
KKr   N)r	  r
  r  rO  r  rY  __instancecheck____subclasscheck__r   r   r   r  r    s@         L L L ,,r   r  c                      e Zd ZdZdS )	StrictABCr   N)r	  r
  r  r  r   r   r   r  r    s        )))r   r  )	metaclass)r   r   r   r   )r   r   r    r!   r   r"   )r   r   r    r!   r$   r%   r   r&   )
r   r(   r    r(   r$   r(   r)   r(   r   r*   )r6   r7   r   r   r   r8   )r6   r;   r   r   r    r!   r   r8   )
r6   r=   r   r   r    r!   r$   r%   r   r8   )r6   r?   r   r(   r    r(   r$   r(   r)   r(   r   r8   )rB   rC   r   rD   )rN   rO   r   rP   )r,   r[   r\   r]   r   r^   )rf   rg   rh   r[   r   ri   )rf   rg   rm   rn   ro   rp   r   rq   )r   r   r   r[   r   r[   r   r8   )r   r   r   r   r   r[   r   r[   r   r[   r   r8   )rI   r   r   r8   )rI   r   r\   r]   r   r^   )r   T)r   T)r   r   r   r   )r$  r   r  )NN)rH  r   rI  rJ  rK  rJ  r   rL  )r   r   r   r   )r  r  r   rL  )r  r	   r   rL  )T)r  r   r   rL  )h
__future__r   abccollections.abcr   r   r   r   r   r   	itertoolsr   loggingr/  typingr	   r
   r   r   r   r   weakrefnumpyr?  jax._srcr   jax._src.libr   r   r   jaxlib_utils	getLoggerr	  r  Seqr   r   r   r   r   r:   rM   rT   rZ   rb   re   rl   r~   r   r   r   r   flattenr{   r   r   r   r   r   r   r   r   r   WeakSetr   r   memoizer   r   r   r   r  r  r#  r*  r,  r4  rE  rG  r   rZ  ra  rc  re  rg  rw  ry  r  r  r  r  r  r  r  r  r  
exceptionsComplexWarningr  rR  AttributeErrorABCMetar  r  r   r   r   <module>r     s   # " " " " " " 



 B B B B B B B B B B B B                 I I I I I I I I I I I I I I I I            ) ) ) ) ) ) . . . . . .		8	$	$GCLLWT]]WT]]WT]]  # <<< 8<VVV 8Vppp 8p P  P  P 8 P    "(  # JJJ 8Jddd 8d~~~ 8~ W  W  W 8 W    "(
 
 
 
) ) ) )           	 	 	 	   
 
 
 
  * * * * &((   ' ' '   @      (      & &go''   
 %


.237      &go''   ! ! ! ! ! ! ! !
! 
! 
! 
! 
! 
! 
! 
!
! 
! 
! 
! 
! 
! 
! 
!+ + +8 8 8 8A A A A            :> > >$ $ $  & & &$G $G $G $G $G $G $G $GL0 0 0> > > > > > > >.2 2 2% % %(" " " "               6M M M M M M M M       0   
       0   *')}'CCCCCC * * *)*
- - - - -CK - - -    -      s   	I I*)I*