
    vhx                       U d dl mZ d dlmZmZmZ d dlZd dlZd dlm	Z	m
Z
 d dlZd dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZmZmZmZ d dlmZ d dl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z' d dlm(Z(  e(jR                  e*       e!Z+dHdZ,dIdZ-dJdZ.dKdZ/ej`                  	 	 dLd       Z1d Z2ej`                  	 	 dLd       Z3d Z4ej`                  d        Z5 G d d      Z6ejn                  jp                  ejn                  jr                  fZ:dMdZ;ejn                  jp                  ejn                  jx                  fZ=ejn                  jr                  ejn                  j|                  fZ?	 	 	 	 	 	 	 	 dNdZ@	 dO	 dPdZAd ZBej                  d        ZD	 	 dQdZE	 	 	 	 dRdZFej                  	 	 	 	 dSd        ZG	 	 dTd!ZHej                  dUd"       ZI e
d#$      	 dO	 	 	 dVd%       ZJdWd&ZKd' ZL eM       ZNd(d(d)d*ZO	 	 	 	 	 	 dXd+ZPej`                  d,        ZQd- ZRejn                  jr                  ZS	 	 	 	 	 	 	 	 dYd.ZT	 	 	 	 	 	 	 	 	 	 	 	 	 	 dZd/ZUd0 ZVd[d1ZWd2 ZXd\d3ZYd4d4dddd5	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d]d6ZZd^d7Z[	 	 	 	 d_d8Z\ ej                  d9      Z^d`d:Z_	 	 	 	 	 	 	 	 	 	 dad;Z`d< Za G d= d>      Zbdbd?Zc ed       Zed@efdA<   dcdBZgdddCZh G dD dEei      Zj	 	 dedFZkdfdGZly)g    )annotations)CallableIterableSequenceN)partial	lru_cache)Any)core)config)dtypes)AbstractRef)		PyTreeDeftree_flattentree_unflattentree_maptreedef_childrengenerate_key_pathsbroadcast_prefixprefix_errors_replace_nones)linear_util)safe_map
WrapKwArgsHashableHashableFunction
Unhashablesafe_zip)traceback_utilc                    t        j                  d| d      } 	 t        j                  |       S # t        $ r& t        t        t        j                  |             cY S w xY w)z2Ensure x is either an index or a tuple of indices.N/expected a static index or sequence of indices.r
   concrete_or_erroroperatorindex	TypeErrortuplemapxs    L/opt/face_recognition/venv/lib/python3.12/site-packages/jax/_src/api_util.py_ensure_indexr+   )   sP    
T1&WX!)>>!	 )X^^Q'(()s   . ,AAc                    t        j                  d| d      } 	 t        j                  |       fS # t        $ r& t        t        t        j                  |             cY S w xY w)z Convert x to a tuple of indices.Nr    r!   r(   s    r*   _ensure_index_tupler-   1   sS    
T1&WX!)NN1	 )X^^Q'(()s   / ,AAc                B    t        | t              st        d|        | S )Nzargument is not a string: )
isinstancestrr%   r(   s    r*   _ensure_strr1   9   s$    	As	
04
55	
(    c                Z    t        | t              r| fS t        t        t        |             S )z Convert x to a tuple of strings.)r/   r0   r&   r'   r1   r(   s    r*   _ensure_str_tupler4   >   s%    34K[!$%%r2   c                r    t        ||      \  }} | |i |}t        |      \  }}|j                  |       |S Nr   r   store)fr8   in_tree	args_flatpy_args	py_kwargsansout_trees           r*   flatten_funr@   E   sC     &gy9'9	7 i #s#-#x++h	*r2   c                z    |\  }}t        |i f      \  }}||k7  rt        d| d|        | | }t        ||      S Nz	Expected z, got r   r%   r   funio_treer<   in_tree_expectedr?   argsr:   r>   s           r*   apply_flat_funrI   N   sX    &H}--$  
i 01yA
BBT
#	#	&&r2   c                f    t        ||      } | | }t        |      \  }}|j                  |       |S r6   r7   )r9   r8   r:   r;   r<   r>   r?   s          r*   flatten_fun_nokwargsrK   V   s8     7I.'	7#s#-#x++h	*r2   c                v    |\  }}t        |      \  }}||k7  rt        d| d|        | | }t        ||      S rB   rC   rD   s           r*   apply_flat_fun_nokwargsrM   _   sT    &Hw'-$  
i 01yA
BBT
#	#	&&r2   c                   t        ||      } | | }t        |t        t        f      rt	        |      dk7  rt        dt        |       d|      |\  }}t        |      \  }}	t        |      \  }
}|j                  |	|f       ||
fS )N   zNexpected function with aux output to return a two-element tuple, but got type z with value )	r   r/   listr&   lenr%   typer   r8   )r9   r8   r:   r;   r<   pairr>   auxans_flatans_treeaux_flataux_trees               r*   flatten_fun_nokwargs2rY   g   s    7I.'	
G$	D4-	(CIN
 ++/:,l4(L M M(#s#C((H#C((H++x"#	8	r2   c                  (    e Zd ZdZdgZd Zd Zd Zy)_HashableWithStrictTypeEqualityz|Box object used when comparing static arguments as a jit key.

  Requires exact type equality using `is` and value equality.valc                    || _         y r6   r\   selfr\   s     r*   __init__z(_HashableWithStrictTypeEquality.__init__z   	    DHr2   c                ,    t        | j                        S r6   )hashr\   r`   s    r*   __hash__z(_HashableWithStrictTypeEquality.__hash__}   s    >r2   c                    t        | j                        t        |j                        u xr | j                  |j                  k(  S r6   )rR   r\   r`   others     r*   __eq__z&_HashableWithStrictTypeEquality.__eq__   s/    >T%))_,FUYY1FFr2   N)__name__
__module____qualname____doc__	__slots__ra   rf   rj    r2   r*   r[   r[   t   s!    A g)Gr2   r[   c           	     0   d}| j                   j                         D ]B  }|j                  t        v r|dz  }|j                  t        j
                  j                  u sB y |r3t        |       |kD  st        |      |k\  rt        d| d| d| d      yy)z
  Validate that the argnums are sensible for a given function.

  For functions that accept a variable number of positions arguments
  (`f(..., *args)`) all positive argnums are considered valid.
  r      NzJitted function has =z, but only accepts z positional arguments.)

parametersvalueskind_POSITIONAL_ARGUMENTSinspect	ParameterVAR_POSITIONALminmax
ValueError)sigargnumsargnums_name
n_pos_argsparams        r*   _validate_argnumsr      s     *~~$$& ezz**Aoj	w((77	7 3w<-*,G
0J
+L>7) D))34JL M M 1KWr2   c                   d}t               }t               }| j                  j                         D ]v  \  }}|j                  t        v r|j                  |       *|j                  t        j                  j                  u rd}S|j                  t        v sf|j                  |       x |t        |      z  x}rt        d| d| d      |ryt        |      |z
  x}rt        d| d| d      y)z
  Validate that the argnames are sensible for a given function.

  For functions that accept a variable keyword arguments
  (`f(..., **kwargs)`) all argnames are considered valid except those
  marked as position-only (`f(pos_only, /, ...)`).
  FTz%Jitted function has invalid argnames z in z. These are positional-onlyNz$. Function does not take these args.)setrt   itemsrv   _KEYWORD_ARGUMENTSaddrx   ry   VAR_KEYWORD_INVALID_KEYWORD_ARGUMENTSr}   )	r~   argnamesargnames_name
var_kwargsvalid_kwargsinvalid_kwargs
param_namer   invalid_argnamess	            r*   _validate_argnamesr      s    *5, U.>>//1 %j%zz''z"	w((44	4j	1	1$% )3x=899
<=M<N O(/)DF G G 
 h-,677
<=M<N O(/)MO P P 8r2   c           
        t        |      }t        dt              |      }|rhg }t              D ]W  \  }}||v rt	        |      s(t        d| dt        |       d| j                   d      |j                  t        |             Y n*t              D cg c]  \  }}||vrt        |       }}}t        fd|D              }t        | |t        |            |fS c c}}w )NFuNon-hashable static arguments are not supported, as this can lead to unexpected cache-misses. Static argument (index 
) of type  for function  is non-hashable.c              3  (   K   | ]	  }|     y wr6   rp   .0irH   s     r*   	<genexpr>z"argnums_partial.<locals>.<genexpr>        0q470   )r-   _ensure_inboundsrQ   	enumerateis_hashabler}   rR   rk   appendr[   r   r&   _argnums_partial)r9   dyn_argnumsrH   require_static_args_hashable
fixed_argsr   argdyn_argss     `     r*   argnums_partialr      s    #K0+ D	;?+!JD/ >3	
k	8BBCJCyk

|3DFG 	G 7<=> 1:$ +fak) S/ +J +0K00(	![%
*;	<h	FF+s   C#c                :    t        | t        d |D                    S )Nc              3  2   K   | ]  }t        |        y wr6   )r   r   r   s     r*   r   z&prepend_static_args.<locals>.<genexpr>   s     &N3z#&Ns   )_prepend_static_argsr&   )r9   static_argss     r*   prepend_static_argsr      s    	a&N+&N!N	OOr2   c                @    t        d |D              }||z   } | |i |S )Nc              3  4   K   | ]  }|j                     y wr6   r^   r   s     r*   r   z'_prepend_static_args.<locals>.<genexpr>   s     5#cgg5s   )r&   )r9   r   rH   kwargsall_argss        r*   r   r      s,    555+4(	
H		r2   c                    g }|D ]>  }||k\  r| r| |cxk  r|k  sn t        d| d| d      |j                  ||z         @ t        |      S )z?Ensure argnum is within bounds. Also resolves negative argnums.zPositional argument indices, e.g. for `static_argnums`, must have value greater than or equal to -len(args) and less than len(args), but got value z for len(args) == .)r}   r   r&   )allow_invalidnum_argsr   resultr   s        r*   r   r      su     &  aH}9$H$#/z<= = MM!h,  
vr2   c          
        s| fS t        |t                    t        fdt        t                    D              }t        fd|D              }g }t	              D ]e  }|r|t              k\  r|   }t        |      s(t        d| dt        |       d| j                   d      |j                  t        |             g t        | |t        |            |fS )zIVersion of ``argnums_partial`` that checks hashability of static_argnums.c              3  ,   K   | ]  }|vs|  y wr6   rp   )r   r   static_argnumss     r*   r   z)argnums_partial_except.<locals>.<genexpr>  s     MAQn5LaMs   	c              3  (   K   | ]	  }|     y wr6   rp   r   s     r*   r   z)argnums_partial_except.<locals>.<genexpr>  r   r   r   r   r   r   )r   rQ   r&   rangesortedr   r}   rR   rk   r   r[   r   )	r9   r   rH   r   r   r   r   r   
static_args	    ``      r*   argnums_partial_exceptr      s     
d7N#M3t9nM.Ms4y!1MM+0K00(*.! Eac$iaJz"@@As**nQZZL8IKL L
 7
CDE 
![%
*;	<h	FFr2   c                   t               }|gt        |      t        |      z   z  }t        ||      D ]
  \  }}|||<    t        |      }	|D 
cg c]  }
|
|u rt	        |	      j
                  n|
 }}
t	        |	|      |u sJ  | |i |S c c}
w r6   )objectrQ   zipiternextr\   )_fun_dyn_argnums_fixed_argsr   r   sentinelrH   r   r   fixed_args_r)   s              r*   r   r     s     X(
s;'#h-7	8$L(+ faDG[!+AE	FA1=${


a
7	F$	F	k8	$	00	0	t	v	 
Gs   "B
c                t   |s| |fS |j                         D ci c]  \  }}||vs|| }}}i }|j                         D ]$  \  }}||vs	 t        |       t        |      ||<   & t        | t        |            |fS c c}}w # t        $ r) t	        d| dt        |       d| j                   d      w xY w)NztNon-hashable static arguments are not supported, as this can lead to unexpected cache-misses. Static argument (name r   r   r   )	r   rd   r   r%   r}   rR   rk   _argnames_partialr   )r9   static_argnamesr   kv
dyn_kwargsfixed_kwargsr   s           r*   argnames_partial_exceptr   "  s    	f9!'LA1O3K1L*L!#, 
(fa
(S	 #3-Q
( 
1j6	7	CC M  GAAB:Cyk

|3DFG 	GGs   A?A?B2B7c                    t        |j                  j                         D ci c]  \  }}||j                   c}}fi |} | |i |S c c}}w r6   )dictr\   r   )r   _fixed_kwargsrH   r   r   r   r   s          r*   r   r   7  sM    m&7&7&=&=&?@daAEE@OJO&	t	v	 As   A
i   )maxsizec                   g }|rt        |      \  }}n|d}}t        |j                               D ]1  \  }}t        || v       }	|j	                  |	f|j
                  z         3 |Vt        |j                         d   |j                               D ](  \  }
}|
|v }	|j	                  |	f|j
                  z         * t        |      S )af  Returns a tuple with a boolean value for each leaf in args and kwargs.

  What if a user specifies donate_argnums but calls the function with kwargs
  or vice-versa? In that case, in `resolve_argnums` using the signature of the
  function, the counterpart (donate_argnames or donate_argnums respectively) is
  calculated so when this function is called both donate_argnums and
  donate_argnames are available. This allows JAX to donate kwargs when only
  donate_argnums is specified and vice-versa.

  When both donate_argnums and donate_argnames are specified, only the args and
  kwargs specified are donated.
  Nrr   )	r   r   childrenboolextend
num_leavesr   	node_datar&   )donate_argnumsdonate_argnamesr:   kwsres	args_treekwargs_treer   r   donatekeyr\   s               r*   donation_vectorr   =  s     #-g6I{$d{I),,./ +fa!~%&FJJy3>>)*+ --/2K4H4H4JK -So%f	jj&S^^+,- 
sr2   c                   |s| st        t        |             S t        t        |            }t        t        |             } dx}x}}g }|t        |       k  rz|t        |      k  r||   | |   k(  rt	        d| d|  d      |t        |      k  r||   | |   k  r|dz  }|dz  }n|j                  | |   |z
         |dz  }|t        |       k  rzt        |      S )aE  Shifts donate to account for static.

  >>> rebase_donate_argnums((3, 4), (0, 1))
  (1, 2)

  Args:
    donate_argnums: An iterable of ints.
    static_argnums: An iterable of ints.

  Returns:
    A tuple of unique, sorted integer values based on donate_argnums with each
    element offset to account for static_argnums.
  r   z`static_argnums` z and `donate_argnums` z cannot intersect.rr   )r&   r   r   rQ   r}   r   )r   r   r   joouts         r*   rebase_donate_argnumsr   Z  s    N'((#n-..#n-..-!-a!
#	C3~>!#4q8I#I*>*: ;++9*::LN O O 	3~>!#4~a7H#H1fa1fa	jj"Q&'1fa 	
C 
sr2   c                :    	 t        |        y# t        $ r Y yw xY w)NTF)rd   r%   )r   s    r*   r   r   }  s#    I	 s    	F)r   tupled_argsc          
        t               }t        |t        g|j                  z        }g fd}	 t	        |t        ||      |       D 
cg c]
  }
|
|u rd n|
 c}
t              |j                  k(  sJ S # t        $ r~ |rt        |      \  }}|\  }}d}	|rM|	d|  dz  }	t        |j                               dk(  r(	 t        | ||f       |	d|  dz  }	n# t        $ r Y nw xY wt        |  d| d	| d
|	       d w xY wc c}
w )Nc                X    j                  | gt        t        |      d         z        S Nr   )r   rQ   r   )r   r)   axess     r*   <lambda>zflatten_axes.<locals>.<lambda>  s%    DKKc,q/!2D.E(EF r2    z Note that za that are non-trivial pytrees should always be wrapped in a tuple representing the argument list.rr   zE In particular, you're passing in a single argument which means that z/ might need to be wrapped in a singleton tuple.zS specification must be a tree prefix of the corresponding value, got specification z for value tree r   )r   r   SENTINELr   r   r   r}   r   rQ   r   flatten_axes)nametreedef	axis_treer   r   proxydummy
add_leaves_hintar   s              @r*   r   r     sn    (%
8*w/A/A"A
B%	$F*CZy95A. .2	2!u*$!
#	2$	Tg((	((	(	+1 
 C
 $G,jgqliD
TF #D E Fd	W	 A	%	*
tWyl
3  !!% '() *$  	
	 v ??Hk J''.iq8 9>BC'C, 
3s6   A; D;ADC
D	C'$D&C''Dc                    t        |      \  }}t        | t        |      |      \  } }| t        |t        |      |f      fS )N)closure)r   _flat_out_axesr&   r   )r9   out_specleavesr   out_axess        r*   flat_out_axesr    sD     !*/&'q%-9+!X	
Xfw/GH	HHr2   c                    | |i |}t        ||      }	 t        t        ||d             }|j                  |       |S # t        $ r4 t	        ||      ^}	}
 |	d      j
                  \  }|dz  }t        |      d w xY w)Nc                
    | d u S r6   rp   r(   s    r*   r   z _flat_out_axes.<locals>.<lambda>  s
    AI r2   )is_leafzpmap out_axesz

The full pytree is the output of the pmapped function. Ensure that the `out_axes` argument to `pmap` is a pytree prefix of the pmapped function's output.)r   r&   r   r}   r   rH   r8   )r   _store_leaves_treedefrH   r   r>   spec	spec_flater   msgs               r*   r   r     s    df#	'	*$	$&tS:MNOI 	,,y	* 
 $$$EA_""DC ) *C S/t#$s   A =A>c                    t        | t              rt        d|        t        |       st        d|        t	        j
                  |       rt        d|        y )Nz.staticmethod arguments are not supported, got zExpected a callable value, got z/Expected a function, got a generator function: )r/   staticmethodr%   callablerx   isgeneratorfunctionrE   s    r*   check_callabler    sa     \"
DSEJ
KK	#
5cU;
<<  %
EcUK
LL &r2   c                X   yt              t              fS | j                  }>J t              t        fdt	        |j                               D              fS t              t        fdt	        |j                               D              fS )z?Infer missing argnums and argnames for a function with inspect.)rp   rp   c              3  \   K   | ]#  \  }\  }}|j                   t        k(  r|v r| % y wr6   rv   _POSITIONAL_OR_KEYWORD)r   r   r   r   r   s       r*   r   z-infer_argnums_and_argnames.<locals>.<genexpr>  s4      a!U:://AM 	
   ),c              3  \   K   | ]#  \  }\  }}|j                   t        k(  r|v r| % y wr6   r  )r   r   r   r   r   s       r*   r   z-infer_argnums_and_argnames.<locals>.<genexpr>  s4      a!U:://AL 	
r  )r-   r4   rt   r&   r   r   )r~   r   r   rt   s    `` r*   infer_argnums_and_argnamesr    s     _)X1!'*G *HH~~*_ *H ()9)9);< G 
(	 "'*G ()9)9);< H
 
(	r2   c                t   |E|dn
t        |      }|dn
t        |      }|dn
t        |      }|t        d|  d      |J d}nTt        |||      \  }}t        |||      \  }}t	        ||d       t        ||d       t	        ||d       t        ||d       t        ||       t        ||      }||||fS )a  Validates and completes the argnum/argname specification for a jit.

  * fills in any missing pieces (e.g., names given numbers, or vice versa),
  * validates the argument names/numbers against the function signature,
  * validates that donated and static arguments don't intersect.
  * rebases the donated arguments so they index into the dynamic arguments,
    (after static arguments have been removed), in the order that parameters
    are passed into the compiled function.
  rp   z"Getting the signature of function z8 failed. Pass donate_argnums instead of donate_argnames.r   r   r   r   )r-   r4   r}   r  r   r   _assert_no_intersectionr   )rE   	signaturer   r   r   r   s         r*   resolve_argnumsr    s   "  *1R7J8N+3b9J:O)1R7J8N";C5 AI I J J"""O
 'A>?'4#NO&@>?'4#NO i1ABy/3DEi1ABy/3DE /?;(H.	./	IIr2   c                l    t        |       j                  t        |            }|rt        d| d      y )NzEstatic_argnames and donate_argnames cannot intersect. Argument names z3 appear in both static_argnames and donate_argnames)r   intersectionr}   )r   r   r   s      r*   r  r  '  sD    O))#o*>?#
O%B	DE E 	r2   c                F   t        | t              rd }  t        j                  |       j                  |i |}|j                          |j                  r=|j                  D cg c]	  }||v s| }}|rt        ddj                  |             |j                  S c c}w )zResolve input arguments to positional following a function's signature.

  This will raise a TypeError if any keyword-only arguments were passed by the
  caller.
  c                      y r6   rp   )rH   r   s     r*   r   z resolve_kwargs.<locals>.<lambda>7  s    r2   zDThe following keyword arguments could not be resolved to positions: z, )
r/   r   rx   r  bindapply_defaultsr   r%   joinrH   )rE   rH   r   bar   passed_kwargss         r*   resolve_kwargsr)  /  s     W
&C"w""D3F3"YY "		91Q&[Q9M9
PYY}%&(  
. :s   #	B-Bc                    	 t        j                  |       S # t        $ r" t        j                  t        | d            cY S w xY w)Ndtype)r   result_typer}   getattrr(   s    r*   _dtyper.  D  s?    3a  	 3ga1223s    (AAc                    | S r6   rp   )rE   tags     r*   api_hookr1  M  s    	*r2   rp   )r   r   result_paths_thunk
sourceinfor  c                   |t        |      }|t        |      }t        |||||      }	t        j                  | ||	|      S )a  Constructd core.DebugInfo for a function given example args and kwargs.

  `args` and `kwargs` are example positional and keyword arguments, users with
  `inspect.Signature` to get the names of arguments. The arguments that are
  considered static for tracing purposes should be included, and designated
  using `static_argnums` and `static_argnames`.

  See docstring for linear_util.DebugInfo.
  )fun_sourceinfofun_signature_non_static_arg_namesr
   	DebugInfo)

traced_forrE   rH   r   r   r   r2  r3  r  	arg_namess
             r*   
debug_infor;  Q  sO    , $Jc"I#ItV^$35)	
J	;M	NNr2   c                X    	 t        j                  |       S # t        t        f$ r Y y w xY wr6   )rx   r  r}   r%   r  s    r*   r6  r6  p  s/    S!!
i	  s    ))c                    t        |t        j                        r|j                  }nt	        |      rt        |      }nJ |       t        | d|       y )N__fun_sourceinfo__)r/   r
   r8  func_src_infor  r5  setattr)wrapperwrappedr?  s      r*   save_wrapped_fun_sourceinforC  v  sF     ())M"7+M'5	''7r2   z(?:<built-in function (\S+)>)c                   t        | dd       }||S t        | t              r| j                  } t        | t              rt	        j
                  |       } 	 | j                  j                  }| j                  j                  }| j                   d| d| S # t        $ rO}	 t        |       }n#  Y Y d }~yxY wt        j                  |      x}r|j                  d      cY d }~S Y d }~yd }~ww xY w)Nr>  z at :z	<unknown>rr   )r-  r/   r   funcrx   unwrap__code__co_filenameco_firstlinenork   AttributeErrorr0   _fun_name_rematchgroup)rE   r   filenamelinenor  fun_strms          r*   r5  r5    s    )40#_Sj3 
((C 	3 s#||''H\\((Fll^4z6(33	 
Cg w''q'WWQZ
s6   ?B 	C-B+*C(+B3-C(3*C(C-(C-c           	        t               t        dt        |      |      }t        |      }t	        |      D cg c]  \  }}||v rn| }	}}|j                         D 
ci c]  \  }
}|
|
|v rn| }}
}d}| 	  | j                  |	i |}t        d | j                  j                         D        d      }|j                  j                         D cg c]  \  }}||vr	||k7  r||f }}}t        d |j                         D        d       }|D cg c]  \  }}||j                  v r|n| d| d|f! }}}||z   }|Dd	|	fg}t        |j                         D cg c]  \  }}|usd
| d|f c}}d       }||z   }t        fd|D              S c c}}w c c}}
w c c}}w c c}}w # t        t        f$ r Y w xY wc c}}w )a  Returns the names of the non-static arguments.

  If the `fn_signature` is given then we get from it the names of the
  top-level arguments. In other cases, including when the `args` and `kwargs`
  do not match the signature, we use names like `args[0[]`, `args[1]`, etc.
  TNc              3  t   K   | ]0  \  }}|j                   t        j                  j                  k(  r| 2 y wr6   )rv   rx   ry   r   )r   r   ps      r*   r   z(_non_static_arg_names.<locals>.<genexpr>  s5      F74VVw'8'8'D'DD  Fs   68c              3  *   K   | ]  \  }}||f  y wr6   rp   )r   r   r)   s      r*   r   z(_non_static_arg_names.<locals>.<genexpr>  s     GGD!tQiGs   c                    | d   S r   rp   name_xs    r*   r   z'_non_static_arg_names.<locals>.<lambda>  s
     r2   )r   z['z']rH   zkwargs['c                    | d   S r   rp   rX  s    r*   r   z'_non_static_arg_names.<locals>.<lambda>  s
    q	 r2   c              3     K   | ]7  \  }}t        |      D ]$  \  }}|ur| t        j                  |        & 9 y wr6   )r   lu_clean_keystr_arg_names)r   r   r)   pathlstatics        r*   r   z(_non_static_arg_names.<locals>.<genexpr>  sX      H403H4q 22489: H: Hs   =A )r   r   rQ   r   r   r   r$  r   rt   	argumentsr   r}   r%   r&   )fn_signaturerH   r   r   r   static_argnums_static_argnames_r   r)   args_r   kwargs_ordered_argsr'  kwargs_namer   
positionalsorted_kwargskeywordr`  s                      @r*   r7  r7    s+    8&$T3t9nE/)=Ft_
MTQQ/)6q0
M%
MCI<<>R41aQ!//Q6R'R37,0<e/w/b
  Fl.E.E.K.K.M FGKMk .0\\-?-?-A C'$6)dk.A 1I Cj C Gw}}G":<m '45"4 !% 4[MD6QS:T 5m 5  -/l5/"Jgmmoa74QRZ`Q`$r*A.a13G'L	 H*H 
H H= NRC
5 	" 
( bs5   F #F&>F8 F,$F2%G
2
G
8G
	G
c                   g g g }}}t        |      D ]S  \  }}t        |      t        v r|j                  t	        |             2|j                  |       |j                  |       U t        | t        |      t        |            |fS r6   )r   rR   _class_with_attrsr   _HashableByObjectIdr   r&   )r9   	flat_argsidxsobjs
flat_args_r   r)   s          r*   hoist_obj_attrsrs    s}    r2j$	" daAw##
kk%a()
kk!n 
!U4[%+	6
	BBr2   c                  $    e Zd ZdgZd Zd Zd Zy)rn  r\   c                    || _         y r6   r^   r_   s     r*   ra   z_HashableByObjectId.__init__  rb   r2   c                ,    t        | j                        S r6   )idr\   re   s    r*   rf   z_HashableByObjectId.__hash__  s    dhh<r2   c                2    | j                   |j                   u S r6   r^   rh   s     r*   rj   z_HashableByObjectId.__eq__  s    88uyy  r2   N)rk   rl   rm   ro   ra   rf   rj   rp   r2   r*   rn  rn    s    g)!r2   rn  c                .    t         j                  |        y r6   )rm  r   )ts    r*   register_class_with_attrsr{    s    r2   z	set[type]rm  c                   t         j                  j                  sJ i }t        t	        ||            D ]  \  }\  }}t        |t              s|j                  t        t        j                  |            |      x}|k7  sNt        | rSd| j                   d| j                   d|j                          d| j                  |    d| j                  |    d      d d| d|       d  y )	Nzconly one reference to a mutable array may be passed as an argument to a function, but when tracing  for z% the mutable array reference of type z appeared at both z and r   zat both flat index z and flat index )r   mutable_array_checksvaluer   r   r/   r   
setdefaultrw  r
   get_referentr}   r?  r9  	str_shortr:  )dbgavalsrH   refsr   r   r)   dup_idxs           r*   _check_no_aliased_ref_argsr    s   		$	$	*	**	*$S-. 	Fia!Q1k"OOBt'8'8';$<a@	@QF
 		++.+<+<*=U3>>BR S//0{{}o=O==!
"%a(8'9	<< BFF gY&6qc:< BFF	Fr2   c                *   t         j                  j                  sJ |D ch c]C  }t        t	        j
                  |      t              rt        t	        j                  |            E }}t        |      D ]  \  }}t        t	        j                  |            |v s't	        j                  |      }t        | rOd| j                   d| j                   d|j                          d| j                  t!        |            |          d       y c c}w )Nzwhen tracing r}  z$, a mutable array reference of type z1 was both closed over and passed as the argument zat flat index {i})r   r~  r  r/   r
   get_avalr   rw  r  r   shaped_abstractifyr}   r?  r9  r  safe_arg_namesrQ   )r  constsrH   cr  r   r)   r   s           r*   "_check_no_aliased_closed_over_refsr    s   		$	$	*	**	*6< B!$--"2K@ t((+, B$ Bo Qda	$

A
4'

!
!!
$a 47 #++,E#..1A B%%&[[]O 4$D	*1-.0Q Q =P	Q QQBs   ADc                  *    e Zd ZU ded<   ded<   ddZy)InternalFloatingPointErrorr0   r   tyc                     || _         || _        y r6   )r   r  )r`   r   r  s      r*   ra   z#InternalFloatingPointError.__init__  s    DIDGr2   N)r   r0   r  r0   )rk   rl   rm   __annotations__ra   rp   r2   r*   r  r    s    )	'r2   r  c                v    t        d       	  ||i |}t        |        y # t        t        f$ r}|d d }~ww xY w)NzdInvalid nan value encountered in the output of a jax.jit function. Calling the de-optimized version.)print_raise_no_nan_in_deoptimizedFloatingPointErrorZeroDivisionError)r  rE   rH   r   r   e2s         r*   maybe_recursive_nan_checkr    sM     	6 7$TVA !# /	0 
$s   ! 838c                6    t        |        d}t        |      d )Na  . Because jax_config.debug_nans.value and/or config.jax_debug_infs is set, the de-optimized function (i.e., the function as if the `jit` decorator were removed) was called in an attempt to get a more precise error message. However, the de-optimized function did not produce invalid values during its execution. This behavior can result from `jit` optimizations causing the invalid value to be produced. It may also arise from having nan/inf literals as inputs or outputs, like `jax.jit(lambda ...: jax.numpy.nan)(...)`. 

It may be possible to avoid the invalid value by removing the `jit` decorator, at the cost of losing optimizations. 

If you see this error, consider opening a bug report at https://github.com/jax-ml/jax.)r0   r  )r  r  s     r*   r  r    s&    F8 ) 
)# 	3T)r2   )r)   r	   returnzint | tuple[int, ...])r)   r	   r  tuple[int, ...])r)   r0   r  r0   )r)   zstr | Iterable[str]r  tuple[str, ...])r9   r   r8   zlu.Storer:   r   )r~   inspect.Signaturer   r  r   r0   r  None)r~   r  r   r  r   r0   r  r  )T)r9   lu.WrappedFunr   zint | Sequence[int]rH   r   )r   r   r   intr   Sequence[int]r  r  )r9   r  r   r  rH   tuple[Any, ...]r   r   )r   r   r   r  r   r   )r9   r  r   r  r   dict[str, Any])r   r   )r   r   r  ztuple[bool, ...])r  r  )r9   r  r  r	   r  ztuple[lu.WrappedFun, Callable])r~   r  r   zint | Iterable[int] | Noner   str | Iterable[str] | Noner  z'tuple[tuple[int, ...], tuple[str, ...]])rE   r   r  inspect.Signature | Noner   int | Sequence[int] | Noner   r  r   r  r   r  r  zItuple[tuple[int, ...], tuple[str, ...], tuple[int, ...], tuple[str, ...]])rE   r   r  r  )r0  r0   )r9  r0   rE   r   rH   Sequence[Any]r   r  r   r  r   Sequence[str]r2  z$Callable[[], tuple[str, ...]] | Noner3  z
str | Noner  r  r  core.DebugInfo)rE   r   r  r  )rA  r   rB  zCallable | core.DebugInfor  r  )rE   r   r  r0   )rb  r  rH   r  r   r  r   r  r   r  r  r  )rz  rR   r  r  )r  r  )r  r  r  r  )r  	ExceptionrE   r   r  r  )r  r  )m
__future__r   collections.abcr   r   r   rx   r#   	functoolsr   r   retypingr	   jax._srcr
   r   r   jax._src.state.typesr   jax._src.tree_utilr   r   r   r   r   r   r   r   r   r   r\  jax._src.utilr   r   r   r   r   r   r   r   register_exclusion__file__r'   r+   r-   r1   r4   transformation_with_aux2r@   rI   rK   rM   rY   r[   ry   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDrw   r   rz   r   KEYWORD_ONLYr   r   r   r   transformation2r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r  r  r)  r.  r1  r;  r6  rC  compilerL  r5  r7  rs  rn  r{  r   rm  r  r  r  r  r  r  r  rp   r2   r*   <module>r     s   # 8 8   ( 	     ,# # # '8 8 # ! ! !( +))
& " ' "+ ' 
 
G G  
##	)) 
M* 
##	""  
))	   #P	#P&5#PFI#P	#PN BFG"G,P    )G!0GDHG2 
#0
"*
 
D$2D*  
 4 $)9 8 F 8 38U $LII #I#I   M !**@@ 	' ) /	@2J	2J'2J /2J 0	2J
 /2J 02J O2JjE*3 %'%'?C!*.OO	O O 	O "O #O =O O (O O>
8)B
8GK
8 rzz:;00H -0H7E0H*70H ,90H  /	0HfC! !"u 9 $FQ 	$		$*r2   