
    ukiw                       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mZ d dlmZ  d dl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( d dlm)Z)  e)jT                  e+       e"e,cZ,Z-e'e.cZ.Z/dFdZ0dGdZ1dHdZ2dIdZ3e jh                  	 	 dJd       Z5e jh                  	 	 dJd       Z6d Z7e jh                  	 	 dJd       Z8d Z9e jh                  d        Z: G d d      Z;ejx                  jz                  ejx                  j|                  fZ?dKdZ@ejx                  jz                  ejx                  j                  fZBejx                  j|                  ejx                  j                  fZD	 	 	 	 	 	 	 	 dLdZE	 dM	 dNdZFd ZGe j                  d        ZI	 	 dOdZJd  ZK	 	 	 	 dPd!ZLe j                  	 	 	 	 dQd"       ZM	 	 dRd#ZNe j                  dSd$       ZO e
d%&      	 dM	 	 	 dTd'       ZPdUd(ZQd) ZR eS       ZTd*d*d+d,ZU	 	 	 	 	 	 dVd-ZVe jh                  d.        ZWd/ ZXejx                  j|                  ZY	 	 	 	 	 	 	 	 dWd0ZZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 dXd1Z[d2 Z\dYd3Z]d4 Z^dZd5Z_d6d6ej                  ddd7	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d[d8Zad\d9Zb	 	 	 	 d]d:Zc ej                  d;      Zed^d<Zf	 	 	 	 	 	 	 	 	 	 d_d=Zg G d> d?      Zh	 	 d`d@ZidadAZj G dB dCek      Zl	 	 dbdDZmdcdEZny)d    )annotations)CallableIterableSequenceN)partial	lru_cache)Any)core)config)dtypes)AbstractRef)
	PyTreeDeftree_flattentree_unflattentreedef_childrentree_flatten_with_pathgenerate_key_pathsbroadcast_prefixprefix_errorsnone_leaf_registry'broadcast_flattened_prefix_with_treedef)linear_util)safe_map
WrapKwArgsHashableHashableFunction
Unhashablesafe_zipunzip2)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/home/cdr/jupyterlab/.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/   2   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_strr3   :   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.)r1   r2   r(   r)   r3   r*   s    r,   _ensure_str_tupler6   ?   s%    34K[!$%%r4   c                r    t        ||      \  }} | |i |}t        |      \  }}|j                  |       |S Nr   r   store)fr:   in_tree	args_flatpy_args	py_kwargsansout_trees           r,   flatten_funrB   F   sC     &gy9'9	7 i #s#-#x++h	*r4   c                    t        ||      \  }} | |i |}t        |      \  }}t        |      \  }	}|j                  ||	f       |S r8   )r   r   r   r:   )
r;   r:   r<   r=   r>   r?   r@   paths_and_ansrA   pathss
             r,   flatten_fun3rF   O   sW     &gy9'9	7 i #237-m$*%++x 	*r4   c                z    |\  }}t        |i f      \  }}||k7  rt        d| d|        | | }t        ||      S Nz	Expected z, got r   r'   r   funio_treer>   in_tree_expectedrA   argsr<   r@   s           r,   apply_flat_funrO   Y   sX    &H}--$  
i 01yA
BBT
#	#	&&r4   c                f    t        ||      } | | }t        |      \  }}|j                  |       |S r8   r9   )r;   r:   r<   r=   r>   r@   rA   s          r,   flatten_fun_nokwargsrQ   a   s8     7I.'	7#s#-#x++h	*r4   c                v    |\  }}t        |      \  }}||k7  rt        d| d|        | | }t        ||      S rH   rI   rJ   s           r,   apply_flat_fun_nokwargsrS   j   sT    &Hw'-$  
i 01yA
BBT
#	#	&&r4   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   r1   listr(   lenr'   typer   r:   )r;   r:   r<   r=   r>   pairr@   auxans_flatans_treeaux_flataux_trees               r,   flatten_fun_nokwargs2r_   r   s    7I.'	
G$	D4-	(CIN
 ++/:,l4(L M M(#s#C((H#C((H++x"#	8	r4   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 r8   rb   selfrb   s     r,   __init__z(_HashableWithStrictTypeEquality.__init__   	    DHr4   c                ,    t        | j                        S r8   )hashrb   rf   s    r,   __hash__z(_HashableWithStrictTypeEquality.__hash__   s    >r4   c                    t        | j                        t        |j                        u xr | j                  |j                  k(  S r8   )rX   rb   rf   others     r,   __eq__z&_HashableWithStrictTypeEquality.__eq__   s/    >T%))_,FUYY1FFr4   N)__name__
__module____qualname____doc__	__slots__rg   rl   rp    r4   r,   ra   ra      s!    A g)Gr4   ra   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Wr4   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.)setrz   itemsr|   _KEYWORD_ARGUMENTSaddr~   r   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 8r4   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r8   rv   .0irN   s     r,   	<genexpr>z"argnums_partial.<locals>.<genexpr>        0q470   )r/   _ensure_inboundsrW   	enumerateis_hashabler   rX   rq   appendra   r   r(   _argnums_partial)r;   dyn_argnumsrN   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r8   )r   r   r   s     r,   r   z&prepend_static_args.<locals>.<genexpr>   s     &N3z#&Ns   )_prepend_static_argsr(   )r;   static_argss     r,   prepend_static_argsr      s    	a&N+&N!N	OOr4   c                @    t        d |D              }||z   } | |i |S )Nc              3  4   K   | ]  }|j                     y wr8   rd   r   s     r,   r   z'_prepend_static_args.<locals>.<genexpr>   s     5#cgg5s   )r(   )r;   r   rN   kwargsall_argss        r,   r   r      s,    555+4(	
H		r4   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r4   c                     t        |t                      t         fdt        t                    D              }t        fd|D              } ||fS )Nc              3  ,   K   | ]  }|vs|  y wr8   rv   )r   r   static_argnumss     r,   r   z_split_args.<locals>.<genexpr>  s     MAQn5LaMs   	c              3  (   K   | ]	  }|     y wr8   rv   r   s     r,   r   z_split_args.<locals>.<genexpr>	  r   r   )r   rW   r(   range)r   rN   r   r   r   s   ``   r,   _split_argsr     sK    #M3t9nM.Ms4y!1MM+0K00(	h	..r4   c          
     J   |s| |fS t        |||      \  }}}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.r   r   r   r   )r   sortedrW   r   r   rX   rq   r   ra   r   r(   )	r;   r   rN   r   r   r   r   r   
static_args	            r,   argnums_partial_exceptr     s     
d7N*5dM++'.+x *.! Eac$iaJz"@@As**nQZZL8IKL L
 7
CDE 
![%
*;	<h	FFr4   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 r8   )objectrW   zipiternextrb   )_fun_dyn_argnums_fixed_argsr   r   sentinelrN   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   rj   r   r'   r   rX   rq   _argnames_partialr   )r;   static_argnamesr   kv
dyn_kwargsfixed_kwargsr   s           r,   argnames_partial_exceptr   1  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 r8   )dictrb   r   )r   _fixed_kwargsrN   r   r   r   r   s          r,   r   r   F  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.
  Nrx   )	r   r   childrenboolextend
num_leavesr   	node_datar(   )donate_argnumsdonate_argnamesr<   kwsres	args_treekwargs_treer   r   donatekeyrb   s               r,   donation_vectorr   L  s     #-g6I{$d{I),,./ +fa!~%&FJJy3>>)*+ --/2K4H4H4JK -So%f	jj&S^^+,- 
sr4   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.rx   )r(   r   r   rW   r   r   )r   r   r   joouts         r,   rebase_donate_argnumsr   i  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r4   c                :    	 t        |        y# t        $ r Y yw xY w)NTF)rj   r'   )r   s    r,   r   r     s#    I	 s    	F)r   tupled_argsc          
        t        j                  |      \  }}	 t        |||      }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)
N z Note that za that are non-trivial pytrees should always be wrapped in a tuple representing the argument list.rx   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   flattenr   r   r   rW   r   flatten_axesr   )
nametreedef	axis_treer   r   axis_tree_leavesaxis_treedefaxes_hints
             r,   r   r     s8   
 $6#=#=i#H LC2,1D0 
Tg((	((	(	+/ 
 C
 $G,jgqliD
TF #D E Fd	W	 A	%	*
tWyl
3  !!% '() *$  	
	 v ??Hk J''.iq8 9>BC'Cs0   A AC
B#
C
#	B/,C
.B//C
c                    t        |      \  }}t        | t        |      |      \  } }| t        |t        |      |f      fS )N)closure)r   _flat_out_axesr(   r   )r;   out_specleavesr   out_axess        r,   flat_out_axesr    sD     !*/&'q%-9+!X	
Xfw/GH	HHr4   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 r8   rv   r*   s    r,   <lambda>z _flat_out_axes.<locals>.<lambda>  s
    AI r4   )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   rN   r:   )r   _store_leaves_treedefrN   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: )r1   staticmethodr'   callabler~   isgeneratorfunctionrK   s    r,   check_callabler    sa     \"
DSEJ
KK	#
5cU;
<<  %
EcUK
LL &r4   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.)rv   rv   c              3  \   K   | ]#  \  }\  }}|j                   t        k(  r|v r| % y wr8   r|   _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r8   r  )r   r   r   r   r   s       r,   r   z-infer_argnums_and_argnames.<locals>.<genexpr>  s4      a!U:://AL 	
r  )r/   r6   rz   r(   r   r   )r   r   r   rz   s    `` r,   infer_argnums_and_argnamesr    s     _)X1!'*G *HH~~*_ *H ()9)9);< G 
(	 "'*G ()9)9);< H
 
(	r4   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.
  rv   z"Getting the signature of function z8 failed. Pass donate_argnums instead of donate_argnames.r   r   r   r   )r/   r6   r   r  r   r   _assert_no_intersectionr   )rK   	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Ir4   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!  2  sD    O))#o*>?#
O%B	DE E 	r4   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 r8   rv   )rN   r   s     r,   r
  z resolve_kwargs.<locals>.<lambda>B  s    r4   zDThe following keyword arguments could not be resolved to positions: z, )
r1   r   r~   r"  bindapply_defaultsr   r'   joinrN   )rK   rN   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,   _dtyper2  O  s?    3a  	 3ga1223s    (AAc                    | S r8   rv   )rK   tags     r,   api_hookr5  X  s    	*r4   rv   )r   r   result_paths_thunk
sourceinfor"  c                   t        |dd      }	|	|	S |t        |      }|t        |      }t        |||||      }
t	        j
                  | ||
|      S )a  Construct core.DebugInfo for a function given example args and kwargs.

  `args` and `kwargs` are example positional and keyword arguments, used 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_debug_info__N)r1  fun_sourceinfofun_signature_non_static_arg_namesr
   	DebugInfo)
traced_forrK   rN   r   r   r   r6  r7  r"  r   	arg_namess              r,   
debug_infor@  \  sh    , 	)40#_J$Jc"I#ItV^$35)	
J	;M	NNr4   c                X    	 t        j                  |       S # t        t        f$ r Y y w xY wr8   )r~   r"  r   r'   r  s    r,   r;  r;  ~  s/    S!!
i	  s    ))c                    t        | d|       y )Nr9  )setattr)wrapperdbgs     r,   save_wrapped_fun_debug_inforF    s    	''-r4   z(?:<built-in function (\S+)>)c                   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)Nz at :z	<unknown>rx   )r1   r   funcr~   unwrap__code__co_filenameco_firstlinenorq   AttributeErrorr2   _fun_name_rematchgroup)rK   filenamelinenor  fun_strms         r,   r:  r:    s    3 
((C 	3 s#||''H\\((Fll^4z6(33	 
Cg w''q'WWQZ
s6   ?B 	CBCB"C"*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r8   )r|   r~   r   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r8   rv   )r   r   r+   s      r,   r   z(_non_static_arg_names.<locals>.<genexpr>  s     GGD!tQiGs   c                    | d   S Nr   rv   name_xs    r,   r
  z'_non_static_arg_names.<locals>.<lambda>  s
     r4   )r   z['z']rN   zkwargs['c                    | d   S r[  rv   r\  s    r,   r
  z'_non_static_arg_names.<locals>.<lambda>  s
    q	 r4   c              3     K   | ]7  \  }}t        |      D ]$  \  }}|ur| t        j                  |        & 9 y wr8   )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   rW   r   r   r   r(  r   rz   	argumentsr   r   r'   r(   )fn_signaturerN   r   r   r   static_argnums_static_argnames_r   r+   args_r   kwargs_ordered_argsr+  kwargs_namer   
positionalsorted_kwargskeywordrd  s                      @r,   r<  r<    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                  $    e Zd ZdgZd Zd Zd Zy)_HashableByObjectIdrb   c                    || _         y r8   rd   re   s     r,   rg   z_HashableByObjectId.__init__  rh   r4   c                ,    t        | j                        S r8   )idrb   rk   s    r,   rl   z_HashableByObjectId.__hash__  s    dhh<r4   c                2    | j                   |j                   u S r8   rd   rn   s     r,   rp   z_HashableByObjectId.__eq__  s    88uyy  r4   N)rq   rr   rs   ru   rg   rl   rp   rv   r4   r,   rq  rq    s    g)!r4   rq  c                   t         j                  j                  sJ i }t        t	        ||            D ]  \  }\  }}t        |t              s|j                  t        t        j                  |            |      x}|k7  sN |        }t        |rod|j                   d|j                   d|j                          d|j                  |j                  |   nd d|j                  |j                  |   nd 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 unknownz and r   zat both flat index z and flat index )r   mutable_array_checksvaluer   r   r1   r   
setdefaultrt  r
   get_referentr   func_src_infor>  	str_shortr?  )	dbg_fnmaybe_avalsrN   refsr   ar+   dup_idxrE  s	            r,   check_no_aliased_ref_argsr    s+   		$	$	*	**	*$Sd34 Fia!Q1k"OOBt'8'8';$<a@	@QFHc 	++.+<+<*=U3>>BR S//0{{}o=O%(]]%>3==!I
N O#&==#<s}}Q)LA		O< BFF gY&6qc:< BFF	Fr4   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 rw  z$, a mutable array reference of type z1 was both closed over and passed as the argument zat flat index {i})r   ry  rz  r1   r
   get_avalr   rt  r|  r   shaped_abstractifyr   r}  r>  r~  safe_arg_namesrW   )rE  constsrN   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)InternalFloatingPointErrorr2   r   tyc                     || _         || _        y r8   )r   r  )rf   r   r  s      r,   rg   z#InternalFloatingPointError.__init__   s    DIDGr4   N)r   r2   r  r2   )rq   rr   rs   __annotations__rg   rv   r4   r,   r  r    s    )	'r4   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  rK   rN   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.)r2   r  )r  r  s     r,   r  r    s&    F8 ) 
)# 	3T)r4   )r+   r	   returnzint | tuple[int, ...])r+   r	   r  tuple[int, ...])r+   r2   r  r2   )r+   zstr | Iterable[str]r  tuple[str, ...])r;   r   r:   zlu.Storer<   r   )r   inspect.Signaturer   r  r   r2   r  None)r   r  r   r  r   r2   r  r  )T)r;   lu.WrappedFunr   zint | Sequence[int]rN   r   )r   r   r   intr   Sequence[int]r  r  )r;   r  r   r  rN   tuple[Any, ...]r   r   )r   r   r   r  r   r   )r;   r  r   r  r   dict[str, Any])r   r   )r   r   r  ztuple[bool, ...])r  r  )r;   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, ...]])rK   r   r"  inspect.Signature | Noner   int | Sequence[int] | Noner   r  r   r  r   r  r  zItuple[tuple[int, ...], tuple[str, ...], tuple[int, ...], tuple[str, ...]])rK   r   r  r  )r4  r2   )r>  r2   rK   r   rN   Sequence[Any]r   r  r   r  r   Sequence[str]r6  z7Callable[[], tuple[str, ...]] | core.InitialResultPathsr7  z
str | Noner"  r  r  core.DebugInfo)rK   r   r  r  )rD  r   rE  r  r  r  )rK   r   r  r2   )rf  r  rN   r  r   r  r   r  r   r  r  r  )r  zCallable[[], core.DebugInfo]r  r  )rE  r  r  r  )r  	ExceptionrK   r   r  r  )r  r  )o
__future__r   collections.abcr   r   r   r~   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   r`  jax._src.utilr   r   r   r   r   r   r   r    register_exclusion__file__r)   
unsafe_mapr   
unsafe_zipr-   r/   r3   r6   transformation_with_aux2rB   rF   rO   rQ   rS   r_   ra   r   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDr}   r   r   r   KEYWORD_ONLYr   r   r   r   transformation2r   r   r   r   r   r   r   r   r   r   r   SENTINELr   r  r  r  r  r  r#  r!  r-  r2  r5  initial_result_pathsr@  r;  rF  compilerO  r:  r<  rq  r  r  r  r  r  r  rv   r4   r,   <module>r     s   # 8 8   ( 	     ,A A A '9 9 9 # ! ! !( +CZCZ))
& "  " ' "+ ' 
 
G G  
##	)) 
M* 
##	""  
))	   #P	#P&5#PFI#P	#PN BFG"G,P    )/G!0GDHG0 
#0
"*
 
D$2D*  
 4 $)9 8 F 8 38U  D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 %'%'RVRkRk!*.OO	O O 	O "O #O PO O (O OD.%3.8<. rzz:;,0H -0H7E0H*70H ,90H  /	0Hf! !F48F"Q 	$		$*r4   