
    Vpf%k                       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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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" 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,j-        e.           e&Z/ddZ0ddZ1ddZ2ddZ3e"j4        d             Z5d Z6e"j4        d             Z7d Z8dd#Z9e"j4        d$             Z: G d% d&          Z;ej<        j=        ej<        j>        fZ?dd,Z@ej<        j=        ej<        jA        fZBej<        j>        ej<        jC        fZDdd/ZEdd1ZFdd7ZGdd<ZHe"jI        d=             ZJddAZKe"jI        ddD            ZL e
dEF          	 dddI            ZMddJZNdK ZOdLdLdMdNZPddQZQe"j4        dR             ZRdS ZSej<        j>        ZTddWZUdd`ZVda ZWdb ZXdc ZYdd ZZi Z[dee\df<   dg Z]e]e[e^<   ddjZ_e_e[ej`        <   ddlZae[b                    dm eD                        ddoZce[b                    dp ejd        D                        ddrZeddxZfddyZgddzZhdd|Zie"j4        d}             Zj	 dddZkddZld Zm G d d          ZnddZo ep            Zqde\d<   dS )    )annotations)CallableIterableSequenceN)partial	lru_cache)Any)core)dtypes)numpy_scalar_types)ShapedArray)		PyTreeDeftree_flattentree_unflattentree_maptreedef_childrengenerate_key_pathskeystrbroadcast_prefixprefix_errors)_replace_nones)linear_util)TracingDebugInfo)safe_map
WrapKwArgsHashableHashableFunction
Unhashablesafe_zip)traceback_utilxr	   returnint | tuple[int, ...]c                    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r!   s    Q/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/api_util.py_ensure_indexr/   +   sg    
T1&WXX!)>!	 ) ) )X^Q''((((()s   , 1A A tuple[int, ...]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_tupler2   3   sj    
T1&WXX!)N1	 ) ) )X^Q''((((()s   - 1A! A!strc                T    t          | t                    st          d|            | S )Nzargument is not a string: )
isinstancer3   r*   r-   s    r.   _ensure_strr6   ;   s0    	As		 6
444
5
55	
(    str | Iterable[str]tuple[str, ...]c                v    t          | t                    r| fS t          t          t          |                     S )z Convert x to a tuple of strings.)r5   r3   r+   r,   r6   r-   s    r.   _ensure_str_tupler;   @   s3    3 &4K[!$$%%%r7   c              '  ^   K   t          | |          \  }}||fV }t          |          V  d S Nr   r   )in_tree	args_flatpy_args	py_kwargsanss        r.   flatten_funrD   G   sD      %gy99'9y   #Sr7   c                    |\  }}t          |i f          \  }}||k    rt          d| d|            | | }t          ||          S Nz	Expected z, got r   r*   r   funio_treerA   in_tree_expectedout_treeargsr?   rC   s           r.   apply_flat_funrN   M   si    &H}---$   
A 0AAAA
B
BBT
#	#	&	&&r7   c              '  X   K   t          | |          }|i fV }t          |          V  d S r=   r>   )r?   r@   rA   rC   s       r.   flatten_fun_nokwargsrP   U   s>      7I..'rk#Sr7   c                    |\  }}t          |          \  }}||k    rt          d| d|            | | }t          ||          S rF   rG   rH   s           r.   apply_flat_fun_nokwargsrR   [   se    &Hw''-$   
A 0AAAA
B
BBT
#	#	&	&&r7   fnlu.WrappedFun6tuple[PyTreeDef, Callable[[], PyTreeDef], bool] | Nonec                   t          t          t                    rt          t          j                  dk    sJ t          t
          t                    rt          t
          j                  dk    sJ t          j        d         t
          j        d         h	 fdt          | j        | j                  D             \  \  \  }}|fd|fS # t          $ r Y d S w xY w)N   r   c              3  Z   K   | ]%\  \  }}}|v |||t           j        d          u fV  &dS )r   N)rD   rM   ).0frM   storeflattenss       r.   	<genexpr>z(flattened_fun_in_tree.<locals>.<genexpr>q   sT       1P 1PIQuh 
ua;+A../AN1P 1Pr7   c                      j         S r=   val)out_tree_stores   r.   <lambda>z'flattened_fun_in_tree.<locals>.<lambda>w   s
    N. r7   )
r5   rD   r   lenrM   rP   zip
transformsstores
ValueError)rS   r?   
has_kwargsr\   ra   s      @@r.   flattened_fun_in_treeri   c   s    
K	)	)Hc+2B.C.Cq.H.H.H.H
)7
3
3 /
"'
(
(A
-
-
-
-q!#7#<Q#?@(;1P 1P 1P 1P #BM29 = =1P 1P 1P-,Zg ....
:: 
   44s   .C 
CCc              '  >  K   t          | |          }|i fV }t          |t          t          f          rt	          |          dk    r"t          dt          |           d|          |\  }}t          |          \  }}t          |          \  }}	||f||	ffV  d S )N   zNexpected function with aux output to return a two-element tuple, but got type z with value )r   r5   listr+   rc   r*   typer   )
r?   r@   rA   pairrC   auxans_flatans_treeaux_flataux_trees
             r.   flatten_fun_nokwargs2rt   y   s      7I..'{		$	D4-	(	( MCIINN
 L+/::L LCGL L M M M(#s#C(((H#C(((H	8x2222222r7   c                  *    e Zd ZdZdgZd Zd Zd ZdS )_HashableWithStrictTypeEqualityz|Box object used when comparing static arguments as a jit key.

  Requires exact type equality using `is` and value equality.r`   c                    || _         d S r=   r_   selfr`   s     r.   __init__z(_HashableWithStrictTypeEquality.__init__       DHHHr7   c                *    t          | j                  S r=   )hashr`   ry   s    r.   __hash__z(_HashableWithStrictTypeEquality.__hash__   s    >>r7   c                r    t          | j                  t          |j                  u o| j        |j        k    S r=   )rm   r`   ry   others     r.   __eq__z&_HashableWithStrictTypeEquality.__eq__   s+    >>T%)__,FUY1FFr7   N)__name__
__module____qualname____doc__	__slots__rz   r   r    r7   r.   rv   rv      s[        A A g)    G G G G Gr7   rv   siginspect.Signatureargnumsargnums_nameNonec           	     (   d}| j                                         D ]1}|j        t          v r|dz  }|j        t          j        j        u r dS 2|r@t          |           |k    st          |          |k    rt          d| d| d| d          dS dS )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   rW   NzJitted function has =z, but only accepts z positional arguments.)

parametersvalueskind_POSITIONAL_ARGUMENTSinspect	ParameterVAR_POSITIONALminmaxrg   )r   r   r   
n_pos_argsparams        r.   _validate_argnumsr      s     *~$$&&  ez***Aojj	w(7	7	7ff 
8  M3w<<-*,,G
0J0J
 LL L L7 L L)3L L L M M MM M0J0Jr7   argnamesargnames_namec                   d}t                      }t                      }| j                                        D ]g\  }}|j        t          v r|                    |           )|j        t          j        j        u rd}D|j        t          v r|                    |           h|t          |          z  x}rt          d| d| d          |rdS t          |          |z
  x}rt          d| d| d          dS )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.)setr   itemsr   _KEYWORD_ARGUMENTSaddr   r   VAR_KEYWORD_INVALID_KEYWORD_ARGUMENTSrg   )	r   r   r   
var_kwargsvalid_kwargsinvalid_kwargs
param_namer   invalid_argnamess	            r.   _validate_argnamesr      sp    *55, UU.>//11 % %j%z'''z""""	w(4	4	4jj	1	1	1$$$ )3x==89 G
 F=M F F(F F F G G G  
F h--,67 P
 O=M O O(O O O P P PP Pr7   Tc           
        t                    t          dt                              |ryg }t                    D ]f\  }}|v r
t	          |          s+t          d| dt          |           d| j         d          |                    t          |                     gnfdt                    D             }t          fdD                       }t          | t          |                    |fS )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                <    g | ]\  }}|v	t          |          S r   )r   )rY   iargdyn_argnumss      r.   
<listcomp>z#argnums_partial.<locals>.<listcomp>   s7     + + +fak)) S//)))r7   c              3  (   K   | ]}|         V  d S r=   r   rY   r   rM   s     r.   r]   z"argnums_partial.<locals>.<genexpr>   '      00q47000000r7   )r2   _ensure_inboundsrc   	enumerateis_hashablerg   rm   r   appendrv   r+   _argnums_partial)rZ   r   rM   require_static_args_hashable
fixed_argsr   r   dyn_argss    ``     r.   argnums_partialr      sW   #K00+ D		;??+! +JD// > >3	
k		8 GFBCF FCyyF F()
F F FG G 	G 7<<====>+ + + +	$ + + +J0000K00000(	![%
*;*;	<	<h	FFr7   allow_invalidboolnum_argsintSequence[int]c                    g }|D ]I}||k    r| r| |cxk    r|k     sn t          d| d| d          |                    ||z             Jt          |          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) == .)rg   r   r+   )r   r   r   resultr   s        r.   r   r      s     &    aH}}}9$$$$H$$$$<< <08< < <= = = MM!h,	vr7   rZ   static_argnumsrM   tuple[Any, ...]c          
     0   s| fS t          |t                              t          fdt          t                              D                       }t          fd|D                       }g }D ]|}|r|t                    k    r|         }t	          |          s+t          d| dt          |           d| j         d          |                    t          |                     }t          | |t          |                    |fS )zIVersion of ``argnums_partial`` that checks hashability of static_argnums.c              3  $   K   | ]
}|v|V  d S r=   r   )rY   r   r   s     r.   r]   z)argnums_partial_except.<locals>.<genexpr>  s-      MMAQn5L5La5L5L5L5LMMr7   c              3  (   K   | ]}|         V  d S r=   r   r   s     r.   r]   z)argnums_partial_except.<locals>.<genexpr>  r   r7   r   r   r   r   )r   rc   r+   ranger   rg   rm   r   r   rv   r   )	rZ   r   rM   r   r   r   r   r   
static_args	    ``      r.   argnums_partial_exceptr      sb    
 d7N#M3t99nMM.MMMMs4yy!1!1MMMMM+0000K00000(* E Ea c$iiaJz"" EK@AK K*K K-.ZK K KL L L
 7
CCDDDD	![%
*;*;	<	<h	FFr7   c              /    	K   t                      		gt          |          t          |          z   z  }t          | |          D ]
\  }}|||<   t          |          	fd|D             }t	          	          	u sJ ||fV }|V  d S )Nc                D    g | ]}|u rt                    j        n|S r   )nextr`   )rY   r!   fixed_args_sentinels     r.   r   z$_argnums_partial.<locals>.<listcomp>  s1    	F	F	FA1==${



a	F	F	Fr7   )objectrc   rd   iterr   )
r   r   r   kwargsrM   r   r   rC   r   r   s
           @@r.   r   r     s      XX(
s:X6	7$K**  faDGGZ  +	F	F	F	F	F	F	F	F$	k8	$	$	0	0	0	0Fl#)))))r7   static_argnamesr   dict[str, Any]c                   s| |fS fd|                                 D             }i }|                                 D ]e\  }}||vr\	 t          |           t          |          ||<   ,# t          $ r, t	          d| dt          |           d| j         d          w xY wft          | t          |                    |fS )Nc                $    i | ]\  }}|v	||S r   r   )rY   kvr   s      r.   
<dictcomp>z+argnames_partial_except.<locals>.<dictcomp>)  s)    LLLA1O3K3K13K3K3Kr7   ztNon-hashable static arguments are not supported, as this can lead to unexpected cache-misses. Static argument (name r   r   r   )	r   r}   r   r*   rg   rm   r   _argnames_partialr   )rZ   r   r   
dyn_kwargsfixed_kwargsr   r   s    `     r.   argnames_partial_exceptr   %  s   	 f9LLLLLLL*!#, 
( 
(fa
(S			 #3--Q  G G GFABF FCyyF F()
F F FG G 	GG  
1j66	7	7	CCs   A**6B r   r   c              /  z   K   t          d | j                                        D             fi |}||fV }|V  d S )Nc                $    i | ]\  }}||j         S r   r_   )rY   r   r   s      r.   r   z%_argnames_partial.<locals>.<dictcomp><  s     ???daAE???r7   )dictr`   r   )r   rM   r   r   rC   s        r.   r   r   :  sU      ??l&6&<&<&>&>???NN:NN&Fl#)))))r7   i   )maxsizekwstuple[bool, ...]c                   g }|rt          |          \  }}n|d}}t          |                                          D ]4\  }}t          || v           }	|                    |	f|j        z             5|bt          |                                d         |                                          D ]'\  }
}|
|v }	|                    |	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.
  NrW   )	r   r   childrenr   extend
num_leavesr   	node_datar+   )donate_argnumsdonate_argnamesr?   r   res	args_treekwargs_treer   r   donatekeyr`   s               r.   donation_vectorr   A  s     # +-g66I{{$d{I),,..// + +fa!~%&&FJJy3>)****[2244Q79M9M9O9OPP - -So%f	jj&S^+,,,,	sr7   c                H   |s| st          t          |                     S t          t          |                    }t          t          |                     } dx}x}}g }|t          |           k     r|t          |          k     r(||         | |         k    rt	          d| d|  d          |t          |          k     r||         | |         k     r|dz  }|dz  }n#|                    | |         |z
             |dz  }|t          |           k     t          |          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.rW   )r+   sortedr   rc   rg   r   )r   r   r   joouts         r.   rebase_donate_argnumsr   ^  sb     )N )''(((#n--...#n--...-!-a!
#	C3~>!#4q8I#I#I N> N N+9N N N O O O 	3~>!#4~a7H#H#H1fa1faa	jj"Q&'''1fa 	
C 
sr7   c                H    	 t          |            dS # t          $ r Y dS w xY w)NTF)r}   r*   )r   s    r.   r   r     s9    III4	   55s    
!!F)r   tupled_argsc          
     R  	
 t                      
t          |t                      g|j        z            }g 		fd}	 t          |t	          
|          |           n# t
          $ r |rt          |          \  }}|\  }}d}|r[|d|  dz  }t          |                                          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
fd	D             	t          	          |j        k    sJ 	S )Nc                v                         | gt          t          |          d                   z            S )Nr   )r   rc   r   )r   r!   axess     r.   rb   zflatten_axes.<locals>.<lambda>  s-    DKKc,q//!2D.E.E(EFF r7    z Note that za that are non-trivial pytrees should always be wrapped in a tuple representing the argument list.rW   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   c                     g | ]
}|u rd n|S r=   r   )rY   aproxys     r.   r   z flatten_axes.<locals>.<listcomp>  s%    	2	2	2!u**$$!	2	2	2r7   )
r   r   r   r   r   rg   r   rc   r   flatten_axes)nametreedef	axis_treer   r   dummy
add_leaves_hintr  r  s            @@r.   r  r    s    ((%
688*w/A"A
B
B%	$FFFF*CZy995AAAA	 C C C
  $G,,jgqliD *
 ET E E E Fd	W	 	 A	%	%	*
tWyl
3
3
3  )!%) ) ) *$$  	 	 	
$	  8 8?H8 8'.8 8158 8 9 9>BC'C, 
3	2	2	2T	2	2	2$	Tg(	(	(	(	(	+s0   A AC<4C
C<
CC<CC<out_spectuple[lu.WrappedFun, Callable]c                    t          |          \  }}t          | t          |          |          \  } }| t          |t          |          |f          fS )Nclosure)r   _flat_out_axesr+   r   )rZ   r  leavesr	  out_axess        r.   flat_out_axesr    sT     !**/&'q%--99+!X	
Xfw/GHHH	HHr7   c              /    K   ||fV }t          ||           }	 t          t          ||d                     }nG# t          $ r: t	          ||          ^}} |d          j        \  }	|	dz  }	t          |	          d w xY w||fV  d S )Nc                
    | d u S r=   r   r-   s    r.   rb   z _flat_out_axes.<locals>.<lambda>  s
    AI r7   )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   rg   r   rM   )
r  r	  rM   r   rC   spec	spec_flater  msgs
             r.   r  r    s      Fl#		(	($	$&tS:M:MNNNOOII	 $ $ $$$$EA1_"DC ) *C S//t#$ 	Ys
    ; AA?c                    t          | t                    rt          d|            t          |           st          d|            t	          j        |           rt          d|            d S )Nz.staticmethod arguments are not supported, got zExpected a callable value, got z/Expected a function, got a generator function: )r5   staticmethodr*   callabler   isgeneratorfunctionrI   s    r.   check_callabler$    s     \"" L
JSJJ
K
KK	# =
;c;;
<
<< %% M
KcKK
L
LLM Mr7   int | Iterable[int] | Nonestr | Iterable[str] | None'tuple[tuple[int, ...], tuple[str, ...]]c                   dS $"t                    t                    fS | j        }NJ t                    t          fdt	          |                                          D                       nIt                    t          fdt	          |                                          D                       fS )z?Infer missing argnums and argnames for a function with inspect.N)r   r   c              3  P   K   | ] \  }\  }}|j         t          k    |v |V  !d S r=   r   _POSITIONAL_OR_KEYWORD)rY   r   r   r   r   s       r.   r]   z-infer_argnums_and_argnames.<locals>.<genexpr>  sJ        a!U:///AMM 	
4AMMM r7   c              3  P   K   | ] \  }\  }}|j         t          k    |v |V  !d S r=   r*  )rY   r   r   r   r   s       r.   r]   z-infer_argnums_and_argnames.<locals>.<genexpr>  sJ        a!U:///ALL 	
4@LLL r7   )r2   r;   r   r+   r   r   )r   r   r   r   s    `` r.   infer_argnums_and_argnamesr-    s    _)6X1!'**G **HH~*_ **H    ()9)9););<<    GG
 "'**G    ()9)9););<<    H
 
(	r7   rI   r   	signatureinspect.Signature | Noner   int | Sequence[int] | Noner   Ituple[tuple[int, ...], tuple[str, ...], tuple[int, ...], tuple[str, ...]]c                   |U|dnt          |          }|dnt          |          }|dnt          |          }|t          d|  d          |J d}nlt          |||          \  }}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.
  Nr   z"Getting the signature of function z8 failed. Pass donate_argnums instead of donate_argnames.r   r   r   r   )r2   r;   rg   r-  r   r   _assert_no_intersectionr   )rI   r.  r   r   r   r   s         r.   resolve_argnumsr4    s_   "  *1RR7J8 8N+3bb9J: :O)1RR7J8 8N" IC I I I J J J"""OO
 'A>?'4 '4#NO&@>?'4 '4#NO i1ABBBy/3DEEEi1ABBBy/3DEEE /?;;;(HH.	./	IIr7   c                    t          |                               t          |                    }|rt          d| d          d S )NzEstatic_argnames and donate_argnames cannot intersect. Argument names z3 appear in both static_argnames and donate_argnames)r   intersectionrg   )r   r   r   s      r.   r3  r3  '  sj    O))#o*>*>??# E
	D	D 	D 	DE E EE Er7   c                    	 t          j        |           S # t          $ r% t          j        t          | d                    cY S w xY w)Ndtype)r   result_typerg   getattrr-   s    r.   _dtyper;  /  sT    3a   	 3 3 3ga11222223s    ,AAc                   	 t          j        t          | t           j                  r| nt          j        |                     S # t
          $ r Y nw xY wt          | dd          }t          | d          rt          j	        | j
        d          }n t          dt          |            d          t          j        t          j        |           ||          S )	N	weak_typeFr8  Tallow_extended_dtypezCannot interpret value of type z9 as an abstract array; it does not have a dtype attributer=  )r
   raise_to_shapedr5   AbstractValueget_avalr*   r:  hasattrr   canonicalize_dtyper8  rm   r   npshape)r!   r=  r8  s      r.   _shaped_abstractify_slowrH  5  s    	a+,,Baa$-2B2BD D D	 	 	 	D	 ae,,)Q +%agDIIIEE
	*$q'' 	* 	* 	*+ + + 
	"(1++u		B	B	BBs   AA 
AAc                    t                               t          |           d           }| ||           nt          |           S r=   )_shaped_abstractify_handlersgetrm   rH  )r!   handlers     r.   shaped_abstractifyrM  F  s=    (,,T!WWd;;'*0H0K0KKr7   z,dict[Any, Callable[[Any], core.ShapedArray]]rJ  c                H    t          d|  dt          |            d          )Nz
Argument 'z
' of type z is not a valid JAX type)r*   rm   r-   s    r.   _str_abstractifyrO  M  s*    MqMMDGGMMMNNNr7   
np.ndarrayr   c                    | j         }t          j        |           t          | j        t          j        |d                    S NTr>  )r8  r   check_valid_dtyper   rG  rE  r!   r8  s     r.   _numpy_array_abstractifyrU  Q  sF    
'%5!!!	QWDAAA
C 
C Cr7   
np.genericc                    t          j        |           }t          j        |           t	          t          j        |           t          j        |d                    S rR  )rF  r8  r   rS  r   rG  rE  rT  s     r.   _np_scalar_abstractifyrX  X  sR    
(1++%5!!!	RXa[[DAAA
C 
C Cr7   c              #  (   K   | ]}|t           fV  d S r=   )rX  rY   ts     r.   r]   r]   ]  sD       $A $A() &'(>$? $A $A $A $A $A $Ar7   int | float | complex | boolc                    t          |           }t          j        ||           }t          d||t          j        v           S )Nr   r@  )rm   r   _scalar_type_to_dtyper   _weak_types)r!   typr8  s      r.   _python_scalar_abstractifyra  `  s<    Q#

&sA
.
.%	R#1C*C	D	D	DDr7   c              #  (   K   | ]}|t           fV  d S r=   )ra  rZ  s     r.   r]   r]   d  sD       $J $J() &'(B$C $J $J $J $J $J $Jr7   tagc                    | S r=   r   )rI   rc  s     r.   api_hookre  i  s    	*r7   
traced_forsrc
str | Nonefun_signatureTracingDebugInfo | Nonec                T    t          |||||          }|dS t          | ||d          S )zGTry to build trace-time debug info for fun when applied to args/kwargs.N)
_arg_namesr   )rf  rg  ri  rM   r   r   r   	arg_namess           r.   
debug_inforn  m  s=     fn(* *)4	*c9d	;	;;r7   c                \    	 t          j        |           S # t          t          f$ r Y d S w xY wr=   )r   r.  rg   r*   r#  s    r.   ri  ri  y  s?    S!!!
i	    44s    ++c                    t          | t                    r| j        } t          | t                    t          j        |           } 	 | j        j        }| j        j        }| j         d| d| S # t          $ r Y d S w xY w)Nz at :)
r5   r   funcr   unwrap__code__co_filenameco_firstlinenor   AttributeError)rI   filenamelinenos      r.   fun_sourceinforz    s    3   
(C 	3   s#|'H\(Fl33336333	   44s   &A. .
A<;A<tuple[str, ...] | Nonec                  	 | d S t                      t          dt          |          |          	t          |          	fdt	          |          D             }fd|                                D             }	  | j        |i |}n# t          t          f$ r Y d S w xY wt          fd|j
                                        D                       S )NTc                &    g | ]\  }}|v rn|S r   r   )rY   r   r!   staticstatic_argnums_s      r.   r   z_arg_names.<locals>.<listcomp>  s+    
M
M
MTQQ/))66q
M
M
Mr7   c                (    i | ]\  }}||v rn|S r   r   )rY   r   r!   r~  static_argnames_s      r.   r   z_arg_names.<locals>.<dictcomp>  s.    PPPAA---ff1PPPr7   c              3  v   K   | ]3\  }}t          |          D ]\  }}|u	| t          |           V  4d S r=   )r   r   )rY   r  r!   pathlr~  s        r.   r]   z_arg_names.<locals>.<genexpr>  sl       H H74033H H4q &t&&7FH Hr7   )r   r   rc   r   r   r   bindrg   r*   r+   	arguments)
fn_signaturerM   r   r   r   args_bar~  r  r  s
          @@@r.   rl  rl    s   $$88&$T3t99nEE/))
M
M
M
M
MYt__
M
M
M%PPPPPPPP&		E	,V	,	,BB
i	    44	 H H H Hbl6H6H6J6J H H H 
H 
H Hs   B B$#B$c               /  P   K   | |fV }|d t          |          D             fV  dS )zKlinear_util transform to get output pytree paths of pre-flattened function.c                2    g | ]\  }}t          |          S r   )r   )rY   r  r  s      r.   r   z result_paths.<locals>.<listcomp>  s"    BBBwtQfTllBBBr7   N)r   )rM   r   rC   s      r.   result_pathsr    sF       Fl#BB*<S*A*ABBBBBBBBBr7   jaxpr
core.Jaxprtrace_debugr  c                    || S |du|j         duz  sJ ||                                 }t          j        |j        |j        |j        t          |                    }|                     |          S )zFAdd debug info to jaxpr, given trace-time debug info and result paths.N)rn  )r  r
   JaxprDebugInforf  func_src_inform  r+   replace)r  r  r  rn  s       r.   jaxpr_debug_infor    s     L
d
"{'?t'K	LLLL++--L"k7U<002 2* 
*	-	--r7   dbg	res_pathsCallable[[], tuple[str, ...]]c                    || S |j         J t          |d          }t          j        | |                    |                    S )zLAttach trace-time debug info and result paths lazy thunk to an lu.WrappedFunNr   r  )r  )r  r   luadd_debug_info_replace)rZ   r  r  
res_paths_s       r.   debug_info_finalr    sO     	[(			!	!	!	2666*		1cll
lCC	D	DDr7   c                X   g g g }}}t          |          D ]h\  }}t          |          t          v r#|                    t	          |                     >|                    |           |                    |           it          | t          |          t          |                    |fS r=   )r   rm   _class_with_attrsr   _HashableByObjectIdr   r+   )rZ   	flat_argsidxsobjs
flat_args_r   r!   s          r.   hoist_obj_attrsr    s    r2j$	""  daAww###
kk%a(())))
kk!nnn	!U4[[%++	6	6
	BBr7   c                  &    e Zd ZdgZd Zd Zd ZdS )r  r`   c                    || _         d S r=   r_   rx   s     r.   rz   z_HashableByObjectId.__init__  r{   r7   c                *    t          | j                  S r=   )idr`   r~   s    r.   r   z_HashableByObjectId.__hash__  s    dh<<r7   c                    | j         |j         u S r=   r_   r   s     r.   r   z_HashableByObjectId.__eq__  s    8uy  r7   N)r   r   r   r   rz   r   r   r   r7   r.   r  r    sH        g)    ! ! ! ! !r7   r  r[  rm   c                :    t                               |            d S r=   )r  r   )r[  s    r.   register_class_with_attrsr    s    r7   z	set[type]r  )r!   r	   r"   r#   )r!   r	   r"   r0   )r!   r3   r"   r3   )r!   r8   r"   r9   )rS   rT   r"   rU   )r   r   r   r0   r   r3   r"   r   )r   r   r   r9   r   r3   r"   r   )T)r   r   r   r   r   r   r"   r0   )rZ   rT   r   r0   rM   r   r   r   )rZ   rT   r   r9   r   r   )r   r   )r   r   r"   r   )r"   r0   )rZ   rT   r  r	   r"   r  )r   r   r   r%  r   r&  r"   r'  )rI   r   r.  r/  r   r0  r   r&  r   r0  r   r&  r"   r1  )r!   rP  r"   r   )r!   rV  r"   r   )r!   r\  r"   r   )rc  r3   )rf  r3   rg  rh  ri  r/  rM   r   r   r   r   r0   r   r9   r"   rj  )rI   r   r"   r/  )rI   r   r"   rh  )r"   r{  r=   )r  r  r  rj  r  r{  r"   r  )rZ   rT   r  rj  r  r  r"   rT   )r[  rm   r"   r   )r
__future__r   collections.abcr   r   r   r   r(   	functoolsr   r   typingr	   numpyrF  jax._srcr
   r   jax._src.abstract_arraysr   jax._src.corer   jax._src.tree_utilr   r   r   r   r   r   r   r   r   r   r   r  jax._src.linear_utilr   jax._src.utilr   r   r   r   r   r   r    register_exclusion__file__r,   r/   r2   r6   r;   transformation_with_auxrD   rN   rP   rR   ri   rt   rv   r   POSITIONAL_ONLYPOSITIONAL_OR_KEYWORDr   r   r   r   KEYWORD_ONLYr   r   r   r   r   transformationr   r   r   r   r   r   r  r  r  r$  r+  r-  r4  r3  r;  rH  rM  rJ  __annotations__rO  r3   rU  ndarrayrX  updatera  python_scalar_dtypesre  rn  ri  rz  rl  r  r  r  r  r  r  r   r  r   r7   r.   <module>r     s   # " " " " " " 8 8 8 8 8 8 8 8 8 8   ( ( ( ( ( ( ( (                       7 7 7 7 7 7 % % % % % %                      . - - - - - & & & & & & 1 1 1 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 # # # # # # ! !( + + +) ) ) )) ) ) )   
& & & &   
' ' '   
' ' '; ; ; ;, 	3 	3 	3G G G G G G G G  
#	) 
M M M M* 
#	"  
)	  #P #P #P #PLG G G G&   G G G G2 	 	 	D D D D*     4 $    8       F   38U $ $ $ $ $LI I I I   M M M !*@    @2J 2J 2J 2JjE E E3 3 3C C C"L L L NP  O O O OO O O$4 S !C C C C
 ,D RZ (C C C C
  # # $A $A-?$A $A $A A A AE E E E  # # $J $J-3-H$J $J $J J J J
   
< 
< 
< 
<   	 	 	 	H H H H C C C =A. . . . .E E E EC C C! ! ! ! ! ! ! !   "suu  $ $ $ $ $ $r7   