
    vh">             	      
   d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	m
Z
 d dlZd dlZd dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZmZ d dlZd dl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% 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- d dl.m/Z/m0Z0 d dl!m1Z1 d dl!m2Z2 d dl!m3Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d dlLmMZM d dlLmNZN d dlLmOZO d dlLmPZP d d lQmRZR d d!lSmTZTmUZUmVZVmWZW d dlXZYd dlZm[Z\  e$j                  d"d#d$%      Z^ e$j                  d& e` ej                  d'd(            d)%      Zb e$j                  d* e` ej                  d+d,            d-      Zc e$j                  d. e$j                  d/d0      d1%      Zf e$j                  d2 e$j                  d3d0      d4%      Zg e$j                  d5 ej                  d6d7      d8%      Zh ej                  d9      Zjdd:Zkdd;Zldd<Zmddd=Zndd>Zodd?Zp	 	 	 	 	 	 dd@ZqdddAZre
ddB       Zs eesej                        Zu eesej                        Zw G dC dDej                        Zy ey       ZzdE Z{e{e2_|        dF Z} e}dG      Z~ e}dH      Z e}dI      Z e}dJ      Z e}dK      Z e}dL      Z e}dM      Z e}dN      Ze
dO        Ze
dP        Ze
dQ        Ze
ddR       Ze
dS        Ze
dT        ZddUZdV ZdW ZdX ZdY ZdZ Zdd[Zdd\Zdd]Zdd^Zdd_Zddd`ZddaZddbZ G dc dd      Zde ZddfZd0e_        dg Zdh Zdi Zdj ZddkZdl ZddmZdn ZddoZdp Z G dq dr      Z G ds dte      Z G du dve      Z e       Z e       Zdw Zdx Zdy Zdz Zd{ Z ejd                  d|}      d~        Zdd fdZddZddZd Zd Zd ZddZd ZddZd Zd Zd Zd Zd ZddZddZd Zd Zd Zd Zd Zd Zd Zd Zd Zej                  d        Zd Zd Zd Zd ZddZe
d        Ze
d        Z G d d      Ze
d        Z G d dej                        Zej                  Zde_        d Zde_        eefZ G d de٫      Ze-j                  Zeeee`f      Ze
dd       Zd Zd ZddZddZ G d d      Z G d d      Z e       Z(d Z ej                  d      ZddZd Zddd	 	 	 	 	 ddZe
d        Ze
d        Zd Zd ZddZ G d deYj                        Z G d dë      ZdddĄZy)    )annotationsN)Callable	GeneratorIterableSequence)	ExitStackcontextmanager)partial)AnyTextIO)parameterized)lax)api)compilation_cache)config)core)deprecations)dispatchdtypes)lib)
monitoring)test_warning_util)	ArrayLike	DTypeLike)
xla_bridge)util)meshrunning_in_cloud_tpu_vm)mlir)hlo)promote_dtypespromote_dtypes_inexact)_assert_numpy_allclose_check_dtypes_match_default_tolerance_dtypecheck_closecheck_grads	check_jvp	check_vjpdefault_gradient_tolerancedefault_tolerance	rand_like	toleranceToleranceDict)thread_unsafe_test)thread_unsafe_test_class)JaxTestLoader)TEST_NUM_THREADS)unzip2)tree_alltree_flattentree_maptree_unflattenjax_test_dut zJDescribes the device under test in case special consideration is required.)helpjax_num_generated_casesJAX_NUM_GENERATED_CASES10z!Number of generated cases to testmax_cases_sampling_retriesJAX_MAX_CASES_SAMPLING_RETRIES100zNumber of times a failed test sample should be retried. When an unseen case cannot be generated in this many trials, the sampling process is terminated.jax_skip_slow_testsJAX_SKIP_SLOW_TESTSFz$Skip tests marked as slow (> 5 sec).*jax_test_with_persistent_compilation_cache*JAX_TEST_WITH_PERSISTENT_COMPILATION_CACHEzIf enabled, the persistent compilation cache will be enabled for all test cases. This can be used to increase compilation cache coverage.hypothesis_profileJAX_HYPOTHESIS_PROFILEdeterministicz^Select the hypothesis profile to use for testing. Available values: deterministic, interactivez[ \"'\[\](){}<>=,._]+c                .    t         j                  d|       S )N_)kSanitizeNameREsub)ss    M/opt/face_recognition/venv/lib/python3.12/site-packages/jax/_src/test_util.pysanitize_test_namerQ   x   s    			S!	$$    c                f    t        j                  t        j                  |             j                  S N)_dtypesfinfocanonicalize_dtypebitsdtypes    rP   num_float_bitsr[   {   s"    	w11%8	9	>	>>rR   c                    t        j                  |       } t        j                  j	                  | j
                  j                        }|r$| j                  t        j                  |            S | S )a  Convert a value to an array with JAX's default dtype.

  This is generally used for type conversions of values returned by numpy functions,
  to make their dtypes take into account the state of the ``jax_enable_x64`` and
  ``jax_default_dtype_bits`` flags.
  )	npasarrayrU   _default_typesgetrZ   kindastyperW   )arrrZ   s     rP   to_default_dtyperd   ~   sP     	

3#

 
 
$
$SYY^^
4%:?G..u5	6HSHrR   c                F     t        j                          fd       }|S )aE  Return a version of a function with outputs that match JAX's default dtypes.

  This is generally used to wrap numpy functions within tests, in order to make
  their default output dtypes match those of corresponding JAX functions, taking
  into account the state of the ``jax_enable_x64`` and ``jax_default_dtype_bits``
  flags.

  Args:
    use_defaults : whether to convert any given output to the default dtype. May be
      a single boolean, in which case it specifies the conversion for all outputs,
      or may be a pytree with the same structure as the function output.
  c                 |     | i |}t        t              rrt        t        |      S |S d }t        ||      S )Nc                     |rt        |       S | S rT   )rd   )rc   use_defaults     rP   <lambda>z:with_jax_dtype_defaults.<locals>.wrapped.<locals>.<lambda>   s    K#3C#8 S rR   )
isinstanceboolr9   rd   )argskwargsresultffuncuse_defaultss       rP   wrappedz(with_jax_dtype_defaults.<locals>.wrapped   sE    4"6"F,%3?X&/KVK
Paa..rR   	functoolswraps)rp   rq   rr   s   `` rP   with_jax_dtype_defaultsrv      s'     ??4/ / 
.rR   c                :    	 t        |        y# t        $ r Y yw xY w)NTF)iter	TypeErrorxs    rP   is_sequencer|      s'    G  
 s    	c                    | xs d} t        | t              r7| j                         D ci c]  \  }}t        j                  |      | c}}S t        j                  t        |       S c c}}w Nr   )rj   dictitemsr]   rZ   fromkeysr'   )tolkvs      rP   _normalize_tolerancer      sS    q#T'*yy{3tq!BHHQKN33==+S11 4s    A(c                    t        |       } t        |      }| }|j                         D ]$  \  }}t        || j                  |d            ||<   & |S r~   )r   r   maxr`   )tol1tol2outr   r   s        rP   join_tolerancer      sU     
d	#$	d	#$#jjl $daDHHQN#CF$	*rR   c                R    t        t        |      }t        t        || |             y )N)err_msg)r
   r%   r7   r9   )xsysr   assert_closes       rP   check_eqr      s     /A,
8L"b)*rR   c              #    K   ddfd}t        j                  dd      5 }t        j                  | j	                               }t        j
                  |j	                         | j	                                	 | | j                          t        j                  | j	                                |j                  d       |j                         t        j
                  || j	                                	 ddd       y# | j                          t        j                  | j	                                |j                  d       |j                         t        j
                  || j	                                w xY w# 1 sw Y   yxY ww)a  Context manager to capture all output written to a given file object.

  Unlike ``contextlib.redirect_stdout``, this context manager works for
  any file object and also for both pure Python and native code.

  Example::

    with capture_output(sys.stdout) as get_output:
      print(42)
    print("Captured": get_output())

  Yields:
    A function returning the captured output. The function must be called
    *after* the context is no longer active.
  Nc                 "     t        d       S )Nz0get_output() called while the context is active.)
ValueError)captureds   rP   
get_outputz#_capture_output.<locals>.get_output   s    IJJOrR   zw+zutf-8)modeencodingr   )returnstr)
tempfileNamedTemporaryFileosdupfilenodup2flushfsyncseekread)fpr   ro   original_fdr   s       @rP   _capture_outputr      s	    $ (
 ""w? (1&&%KGGAHHJ		$( 	hhjhhryy{ffQihggk299;'( ( 	hhjhhryy{ffQihggk299;'( (s7    F	AE=:D >A8E=7	F	 A:E::E==FF	c                      e Zd Zd Zy)EventThreadLocalStatec                J    i | _         d| _        d | _        d | _        d | _        y r~   )countsnested_device_put_countinfer_params_fun_countslower_jaxpr_to_fun_countscollect_lowered_jaxprsselfs    rP   __init__zEventThreadLocalState.__init__   s+    DK#$D  $(D %)D""&DrR   N)__name__
__module____qualname__r    rR   rP   r   r      s    'rR   r   c                "   t         j                  }|j                  | d      dz   || <   | dk(  rEt         j                  dk(  r|j                  dd      dz   |d<   t         xj                  dz  c_        y | dk(  rt         xj                  dz  c_        y | dk(  r%t         j                  }||\  }||xx   dz  cc<   y y | dk(  r%t         j
                  }||\  }||xx   dz  cc<   y y | dk(  r%t         j                  }||j                  |       y y y )	Nr      batched_device_put_startbatched_device_putbatched_device_put_endzpjit._infer_params_impllower_jaxpr_to_funzmlir.collect_lowered_jaxprs)thread_local_stater   r`   r   r   r   r   append)namerl   r   infer_countsfunlower_counts
collections          rP   event_listenerr      s,   $$&D!$q(&, 
''11Q6%+ZZ0Da%H1%Lf!"..!3.''..!3.(( &==Lfs31   ## &??Lfs31   ,,#::J  -rR   c                $     t          fd       }|S )zJReturns a context-manager that yields a function that counts a test event.c               3  `    K   t         j                  j                  d        fd y w)Nr   c                 J    t         j                  j                  d       z
  S r~   r   r   r`   beforeevents   rP   ri   z3count_events.<locals>.count_event.<locals>.<lambda>#  s     $++//q9FB rR   r   r   s   @rP   count_eventz!count_events.<locals>.count_event   s%     &&**5!4F
BBs   *.)r	   )r   r   s   ` rP   count_eventsr     s    C C 
rR   r   batched_copy_array
pjit_lowercreate_pjit_jaxprstages_compiled_calllower_jaxpr_to_modulepxla_cached_compilation_array_shard_argc               #     K   t         j                  j                          dg 	  fd t         j                  j                         j                   d<   y # t         j                  j                         j                   d<   w xY ww)Nc                      d   S r~   r   counts   rP   ri   z*count_primitive_compiles.<locals>.<lambda>6  s    %( rR   r   )r   xla_primitive_callablecache_clear
cache_infomissesr   s   @rP   count_primitive_compilesr   0  sh     
!!--/$%C
..99;BBE!Hx..99;BBE!Hs   "B	A ,B	-BB	c               #     K   t         j                  J t        j                         } | t         _        	 |  d t         _        y # d t         _        w xY wwrT   )r   r   collectionsCounterr   s    rP   !count_jit_infer_params_cache_missr   :  sK     		3	3	;;	; &/5,6
L15..s   2AA AAAc              #      K   t         j                  J t        j                         t         _        	  fd d t         _        y # d t         _        w xY ww)Nc                         S rT   r   )r   fun_names   rP   ri   z2count_subjaxpr_to_hlo_conversion.<locals>.<lambda>J  s    &" rR   )r   r   r   r   )r   r   s   `@rP    count_subjaxpr_to_hlo_conversionr   D  sM     		5	5	==	= &17.8
""37040s   2AA AAAc               #     K   t         j                  J g } | t         _        	 |  dt         _        y# dt         _        w xY ww)zF
  Collects all the pairs of (jaxpr, mlir_module) that are lowered.
  N)r   r   )r   s    rP   r   r   O  sE      
	2	2	::	:>@*.8+5
04--s    A3 AA  Ac              #     K   t               5 }d  d d d                | k7  rt        d|  d |              y # 1 sw Y   *xY ww)NzExpected exactly z  XLA compilations, but executed )count_jit_and_pmap_loweringsAssertionError)timesr   s     rP   $assert_num_jit_and_pmap_compilationsr   ]  sY     #% 
	

W
,UG 4)).	3 4 4 
 
s   A;)AA Ac               #  8  K   t         j                  j                  j                  j	                         } i 	 fd t         j                  j                  j                  j	                         }|j                         D ]%  \  }}|| j                  |d      z
  }|dk7  s!||<   ' y # t         j                  j                  j                  j	                         }|j                         D ]%  \  }}|| j                  |d      z
  }|dk7  s!||<   ' w xY ww)Nc                      S rT   r   r   s   rP   ri   z,count_internal_device_puts.<locals>.<lambda>j  s    & rR   r   )jax_srcr   _jaxget_internal_device_put_infor   r`   )r   afterr   r   diffr   s        @rP   count_internal_device_putsr   e  s     88<<99;&&
HHLL::<E 1Aq!!d	q	 HHLL::<E 1Aq!!d	q	s*   5DB+  A"D#D+A#DDDc                 "    t         j                  S rT   )_jaxlibversionr   rR   rP   jaxlib_versionr   r  s    	rR   c                 b    t         j                  xs t        j                         j                  S rT   )	_TEST_DUTvaluer   get_backendplatformr   rR   rP   device_under_testr   v  s     		=J224===rR   c                 ^   t               dk(  rt        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                   t        j"                  t        j$                  h} nPt               dk(  rt        j                  t        j
                  t        j                  t        j                  t        j&                  t        j                  t        j                  t        j                  t        j(                  t        j                  t        j                  t        j                  t        j*                  t        j                  t        j,                  t        j                   t        j$                  h} n?t               dk(  r1t        j                  t        j                  t        j                  h} nt        j                  t        j                  t        j
                  t        j                  t        j                  t        j&                  t        j                  t        j                  t        j                  t        j                  t        j(                  t        j                  t        j                  t        j                  t        j*                  t        j                  t        j,                  h} t.        j0                  j2                  sA| t        j(                  t        j&                  t        j*                  t        j,                  hz  } | S )NtpugpuMETAL)r   r]   bool_rU   int4int8int16int32uint4uint8uint16uint32bfloat16float16float32	complex64float8_e4m3fnfloat8_e4m3b11fnuzfloat8_e5m2int64uint64float64
complex128r   
enable_x64r   )typess    rP   supported_dtypesr  y  s   E!XXw||RWWbhh]]BHHbiirzz2::r||""G$>$>  	"E
 e#XXrww"((BHHXXryy"))RYYrzz2::rzz\\2=='*?*?  	"E
 g%XXryy"**-EXXw||RWWbhh"((]]BHHbiiBIIrzz2::rzz\\2==*E 
			 	 	bii2::r}}==E	,rR   c                 B    dt        j                         j                  v S )Nrocmr   r   platform_versionr   rR   rP   is_device_rocmr         	:))+<<	<<rR   c                 B    dt        j                         j                  v S )Ncudar  r   rR   rP   is_device_cudar$    r!  rR   c                     t         S rT   r   r   rR   rP   is_cloud_tpur&    s    	  rR   c                :   t        j                  | ||      }t               syt        j                         j
                  j                  d      d   }t        j                  d|      }t        |      dk7  ry|j                  t        |d   dd             }||k\  S )NT
r   z\(.*?\)r   r   )datetimedater&  r   r   r  splitrefindalllenfromtimestampint)yearmonthdayr*  r  results
build_dates          rP   if_cloud_tpu_at_leastr6    s    	tUC	($	
  ++->>DDTJ2NJJz#34'\Q!!#gaj2&6"78*	t	rR   c                >    t        j                         }|y|| |fk\  S )NT)r   backend_pjrt_c_api_version)major_versionminor_versionpjrt_c_api_versionss      rP   pjrt_c_api_version_at_leastr<    s*    "==? 	 >	>>rR   c                    t        j                         }|yt        j                  dj	                  t        t        |            |       |k(  S )NT.)r   backend_stablehlo_versionr"   get_smaller_versionjoinmapr   )required_versionplugin_versions     rP   stablehlo_version_at_leastrE    sJ    779.		 	 	hhs3'(*:

 rR   c                     t               dk7  rt        d      t        j                         d   j                  } t        j                  d|       }|t        d|  d      t        |j                  d            S )Nr  zDevice is not TPUr   zTPU[^\d]*(\d+)zDevice kind z is not supportedr   )	r   r   r   devicesdevice_kindr,  matchr0  group)ra   rI  s     rP   get_tpu_versionrK    sm    E!
(
))	q		%	%$
(($d
+%
]
|D6):;
<<	U[[^	rR   c                8    t               dk7  ryt               | k\  S )Nr  F)r   rK  )r   s    rP   is_device_tpu_at_leastrM    s    E!		g	%%rR   c                    t               dk7  ry| yt        j                         d   j                  }d|  | }|dk(  rd|v S |dk(  rd	|v S ||v S )
Nr  FTr   r   v5ezv5 litev6ezv6 lite)r   r   rG  rH  )r   variantrH  expected_versions       rP   is_device_tpurS    sp    E!_a ,,+	'+##5 ##	[	((rR   c                    t               syt        j                  d      ^}}t        d | j	                  d      D              }t        d |j
                  j	                  d      D              }||k\  S )NFr  backendc              3  2   K   | ]  }t        |        y wrT   r0  .0r{   s     rP   	<genexpr>z6is_cuda_compute_capability_at_least.<locals>.<genexpr>       7AQ7   r>  c              3  2   K   | ]  }t        |        y wrT   rX  rY  s     rP   r[  z6is_cuda_compute_capability_at_least.<locals>.<genexpr>       BQ#a&Br]  r$  r   local_devicestupler+  compute_capability
capabilitydrL   targetcurrents        rP   #is_cuda_compute_capability_at_leastri    f    		


E
*%!a7!1!1#!677&B!"6"6"<"<S"ABB'	F	rR   c                    t               syt        j                  d      ^}}t        d | j	                  d      D              }t        d |j
                  j	                  d      D              }||k(  S )NFr  rU  c              3  2   K   | ]  }t        |        y wrT   rX  rY  s     rP   r[  z3is_cuda_compute_capability_equal.<locals>.<genexpr>  r\  r]  r>  c              3  2   K   | ]  }t        |        y wrT   rX  rY  s     rP   r[  z3is_cuda_compute_capability_equal.<locals>.<genexpr>  r_  r]  r`  rd  s        rP    is_cuda_compute_capability_equalrn    rj  rR   c                      e Zd ZdZd Zd Zy)CudaArchSpecificTestz:A mixin with methods allowing to skip arch specific tests.c                >    t        d      s| j                  d       y y )Nz9.0z'Only works on GPU with capability sm90arn  skipTestr   s    rP   skip_unless_sm90az&CudaArchSpecificTest.skip_unless_sm90a  s    +E2
mm=> 3rR   c                >    t        d      s| j                  d       y y )Nz10.0z(Only works on GPU with capability sm100arr  r   s    rP   skip_unless_sm100az'CudaArchSpecificTest.skip_unless_sm100a  s    +F3
mm>? 4rR   N)r   r   r   __doc__rt  rv  r   rR   rP   rp  rp    s    B?@rR   rp  c                     t               rt               dh} | S t               rt               dh} | S t               dk(  rt               dh} | S t               h} | S )z7returns a set of tags defined for the device under testr  r#  r  r  )r   r   r$  )device_tagss    rP   _get_device_tagsrz    so    $&/K 
 $&/K
 
	 g%$&.K 
 %&'K	rR   c                    t        | t              rJ d       t               }| D ]  }t        |t              sJ |       ||v s y y)Nz(device_types should be a list of stringsTF)rj   r   rz  )device_typestagsdevice_types      rP   test_device_matchesr     s_    C 0/0 
 
	$! kk3'44'd 
rR   c                      fd}|S )Nc                F     t        j                          fd       }|S )Nc                    t               }        s(t        dd      }t        j                  | d| d       | g|i |S )Nr   [unknown test]z# not supported on device with tags r>  )rz  getattrunittestSkipTest)r   rl   rm   ry  	test_name	predicatetest_methods        rP   test_method_wrapperz9_device_filter.<locals>.skip.<locals>.test_method_wrapper  sZ    $&k[K5EF	K:;-q
IK 	K////rR   rs   )r  r  r  s   ` rP   skipz_device_filter.<locals>.skip  s&    __[!0 "0 rR   r   )r  r  s   ` rP   _device_filterr    s    	 
+rR   c                       t         fd      S )zAA decorator for test methods to skip the test on certain devices.c                     t                S rT   r  disabled_devicess   rP   ri   z!skip_on_devices.<locals>.<lambda>  s    $78H$I I rR   r  r  s   `rP   skip_on_devicesr    s    	I	JJrR   c                       t         fd      S )zEA decorator for test methods to run the test only on certain devices.c                     t               S rT   r  enabled_devicess   rP   ri   z run_on_devices.<locals>.<lambda>   s     3O D rR   r  r  s   `rP   run_on_devicesr    s    	D	EErR   c                     t        d       S )z\A decorator for test methods to run the test only on devices that support
  buffer donation.c                 4    t        t        j                        S rT   )r  r!   _platforms_with_donationr   rR   rP   ri   z1device_supports_buffer_donation.<locals>.<lambda>&  s    !$"?"?@ rR   r  r   rR   rP   device_supports_buffer_donationr  "  s     
@
 rR   c                    t         j                  j                  | k  r6t         j                  j	                          	 t        j                  d|        yy# t        $ r Y yw xY w)a  Requests at least `nr_devices` CPU devices.

  request_cpu_devices should be called at the top-level of a test module before
  main() runs.

  It is not guaranteed that the number of CPU devices will be exactly
  `nr_devices`: it may be more or less, depending on how exactly the test is
  invoked. Test cases that require a specific number of devices should skip
  themselves if that number is not met.
  jax_num_cpu_devicesN)r   num_cpu_devicesr   r   r   r   updateRuntimeError)
nr_devicess    rP   request_cpu_devicesr  *  sW     %%
2&&(mm):6 3  
s   A 	A! A!c                      fd}|S )zAA decorator for test methods to skip the test when flags are set.c                H     t        j                          fd       }|S )Nc                    t        j                        }|k(  r*t        dd      }t        j                  | d d|        | g|i |S )Nr   r  z not supported when FLAGS.z is )r   _readr  r  r  )r   rl   rm   
flag_valuer  	flag_name
skip_valuer  s        rP   r  z7skip_on_flag.<locals>.skip.<locals>.test_method_wrapperB  sg    <<	*j	z	!K5EF	K1)D
MO 	O////rR   rs   )r  r  r  r  s   ` rP   r  zskip_on_flag.<locals>.skipA  s&    __[!0 "0 rR   r   )r  r  r  s   `` rP   skip_on_flagr  ?  s    	 
+rR   c                      fd}|S )zDA decorator for test classes or methods to pytest.mark if installed.c                h    	 dd l } t        |j                        |       S # t        $ r | cY S w xY wr~   )pytestImportErrorr  mark)func_or_classr  markers     rP   wrapz&pytest_mark_if_available.<locals>.wrapP  s<     (76;;'66  s   # 11r   )r  r  s   ` rP   pytest_mark_if_availabler  N  s    7 
+rR   c                 &    dt         j                  v S )Nr  )sysmodulesr   rR   rP   is_running_under_pytestr  Y  s    	S[[	  rR   c                     d z     fd}|S )zDA decorator for test methods to skip the test when run under pytest.zRunning under pytest: c                L     t        j                  t                     |       S rT   )r  skipIfr  )r  reasons    rP   r  zskip_under_pytest.<locals>.skip`  s    =8??24f=kJJrR   r   )r  r  s   ` rP   skip_under_pytestr  ]  s    #f,&K	+rR   c                    d t        ||      D        }dj                  | j                         dj                  |            S )Nc              3  :   K   | ]  \  }}t        ||        y wrT   )format_shape_dtype_string)rZ  shaperZ   s      rP   r[  z*format_test_name_suffix.<locals>.<genexpr>f  s#      ?&% 0u= ?s   z{}_{}rL   )zipformat
capitalizerA  )opnameshapesr   arg_descriptionss       rP   format_test_name_suffixr  e  s=    ?*-ff*=?	))+SXX6F-G	HHrR   c                      e Zd Zd Zd Zy)ScalarShapec                     yr~   r   r   s    rP   __len__zScalarShape.__len__n  s    ArR   c                     t        d| d      )Nzindex z out of range.)
IndexError)r   is     rP   __getitem__zScalarShape.__getitem__o  s    *vaS-G"HHrR   N)r   r   r   r  r  r   rR   rP   r  r  m  s    HrR   r  c                      e Zd Zy)_NumpyScalarNr   r   r   r   rR   rP   r  r  p      rR   r  c                      e Zd Zy)_PythonScalarNr  r   rR   rP   r  r  q  r  rR   r  c           	         | t         k(  rD|t        j                  t        t        j                  d|      j                                     k(  S y)Nr   rY   T)PYTHON_SCALAR_SHAPEr]   rZ   typearrayitemr  rZ   s     rP   is_valid_shaper  w  s;    
!!BHHT"((1E":"?"?"ABCCC	rR   c                    t        |       t        t        fv r| S t        | t              ryt        j                  |       dk(  r| fS t        t        |             )z*Converts `shape` to a tuple of dimensions.r   r   )r  listrb  rj   r  r]   ndimry   )r  s    rP   _dims_of_shaper  }  sJ    	%[T5M!L%%	wwu~8O
DK
  rR   c                   |t         u r$t        j                  |      j                  |       S |t        u r#t        j
                  |       j                         S t        |      t        t        fv r%t        j                  |       t        |      k(  sJ | S t        j                  |      dk(  rt        j                  |       |fk(  sJ | S t        t        |            )zACasts `value` to the correct Python type for `shape` and `dtype`.r   )NUMPY_SCALAR_SHAPEr]   rZ   r  r  r^   r  r  rb  r  r  ry   )r   r  rZ   s      rP   _cast_to_shaper    s    
  88E?&&##::e!!##E{tUm#88E?eEl***L	wwu~88E?uh&&&L
DK
  rR   c                @    t        j                  |       j                  S rT   )r]   rZ   r   rY   s    rP   	dtype_strr    s    	%		rR   c                    t        | t        j                        rt        |       d|  dS t        | t              rt        |       } t        | |      S )N[])rj   r]   ndarrayr  r  rb  _format_shape_dtype_stringr  s     rP   r  r    sI    rzz"qq))%%LE	#E5	11rR   @   )maxsizec                4   | t         u rt        |      S | t        u rdt        |      z   S t        |       t        u r)dj                  d | D              }t        |       d| dS t        |       t        u rt        |       d|  dS t        t        |             )Npy,c              3  2   K   | ]  }t        |        y wrT   )r   )rZ  dims     rP   r[  z-_format_shape_dtype_string.<locals>.<genexpr>  s     2SC2r]  r  r  z,])r  r  r  r  rb  rA  r0  ry   )r  rZ   shapestrs      rP   r  r    s    
  U##)E"""E{exx2E22Hq
!,,E{cqr**
DK
  rR         ?c                    | S rT   r   rz   s    rP   ri   ri     s    Q rR   c                >    t        j                  t        j                        r	 fd}n fd}t        j                  t        j                        r |       d |       z  z   }n |       }t        t        j                   ||                  S )a  Produce random values given shape, dtype, scale, and post-processor.

  Args:
    rand: a function for producing random values of a given shape, e.g. a
      bound version of either np.RandomState.randn or np.RandomState.rand.
    shape: a shape value as a tuple of positive integers.
    dtype: a numpy dtype.
    scale: optional, a multiplicative scale for the random values (default 1).
    post: optional, a callable for post-processing the random values (default
      identity).

  Returns:
    An ndarray of the given shape and dtype using random values based on a call
    to rand but scaled, converted to the appropriate dtype, and post-processed.
  c            
     |    t        j                  t         t                     z        j	                         S rT   )r]   r^   absr  rb   rZ   randscaler  s   rP   ri   z_rand_dtype.<locals>.<lambda>  s/    

53t^E-B'C#DDELLUS rR   c                 j    t        j                   t               z        j                         S rT   )r]   r^   r  rb   r  s   rP   ri   z_rand_dtype.<locals>.<lambda>  s*    

54)>#??@GGN rR                 ?)rU   
issubdtyper]   unsignedintegercomplexfloatingr  r^   )r  r  rZ   r  postrvalss   ````   rP   _rand_dtyper    sr      r112SANAr1123D3D	

4:u5ue	DDrR   c                     d f fd	}|S )z:Random numbers that span the full range of available bits.c                    | S rT   r   rz   s    rP   ri   z rand_fullrange.<locals>.<lambda>  s    q rR   c                0   t        j                  |      }|j                  t        j                  t        |             z  }j                  dt        j                  t         j                        j                  |t         j                        } ||      j                  |      }| t        u r|t         j                  k(  r |j                  t         j                        }nL|t         j                  k(  r9t         j"                  j$                  s|j                  t         j&                        }|j)                  |       }rJt        j*                  |t         j,                        r&t         j.                  |t        j0                  |      <   t3        || |      S )Nr   )sizerZ   )r]   rZ   itemsizemathprodr  randintiinfor  r   viewr  r  rb   r  r  r   r  r   r	  reshaper  floatingnanisnanr  )r  rZ   r  r  r  rngstandardize_nanss        rP   genzrand_fullrange.<locals>.gen  s   HHUOE>>DIInU&;<<D;;q"((288,00t288;LD:??5!D## 
"))	{{288$BIIf&7&7&=&={{288$<<DBMM%=VVd288D>$u--rR   r   )r  r  r  s   `` rP   rand_fullranger    s    ( ." 
*rR   c                :    t        t        | j                  |      S )Nr  r
   r  randn)r  r  s     rP   rand_defaultr    s    	ciiu	55rR   c                B    d }t        t        | j                  d|      S )Nc                t    t        j                  | dk(  t        j                  d| j                        |       S )Nr   r   rY   )r]   wherer  rZ   rz   s    rP   ri   zrand_nonzero.<locals>.<lambda>  s&    288AFBHHQagg$>B rR      r  r  r  r  r  s     rP   rand_nonzeror"    s    	B$	ciiqt	<<rR   c                B    d }t        t        | j                  d|      S )Nc                    | dz   S )Nr   r   rz   s    rP   ri   zrand_positive.<locals>.<lambda>  s
    1q5 rR      r   r
   r  r  r!  s     rP   rand_positiver'    s    	$	chhad	;;rR   c                :    t        t        | j                  d      S )NgMbP?r  r  r  s    rP   
rand_smallr*    s    	ciit	44rR   c                H    fd}t        t        | j                  d|      S )Nc                @    | t        j                  | dkD         z   S r~   )r]   r  )r{   offsets    rP   ri   z rand_not_small.<locals>.<lambda>  s    1rxxAvw77 rR   g      @r   r  )r  r-  r  s    ` rP   rand_not_smallr.    s    	7$	ciir	==rR   c                :    t        t        | j                  d      S )Ngh㈵>r  r&  r)  s    rP   rand_small_positiver0    s    	chhd	33rR   c                X    k  sJ fd}t        t        | j                  |      S )Nc                    | z
  z  z   S rT   r   )r{   highlows    rP   ri   zrand_uniform.<locals>.<lambda>  s    1s
#c) rR   )r  r&  )r  r4  r3  r  s    `` rP   rand_uniformr5     s'    	t	)$	chhT	22rR   c                H      fd}t        t         j                  d|      S )Nc                    | j                         }t        |      dk(  r| S  j                  t        j                  |        dk  }t        j
                  ||d   |       S )Nr         ?)ravelr.  r  r]   r  r  )r{   x_ravelflipsr  s      rP   r  zrand_some_equal.<locals>.post  sS    ggiG
7|qhCHHbhhqk"S(E88E71:q))rR   g      Y@r   r  r!  s   ` rP   rand_some_equalr<    s    * 
ciit$	??rR   c                0     t                fdS )CReturn a random sampler that produces infinities in floating types.c                   t        j                  |t        j                        s	 | |      S t        j                  |t        j                        rkt        j
                  t        j                  d|            j                  } 	| |      t        j                  d|       	| |      z  z   }t        || |      S t        |       } 
j                  | dk  } 
j                  | dk  } | |      }t        j                  |t        j                  t        j                  |      |      }t        j                  |t        j                  t        j                   |      |      }t        t        j                  ||      | |      S The random sampler function.r   rY   r  皙?)rU   r  r]   r  r   realr  rZ   r  r  r  r  infr^   )r  rZ   
base_dtyper   dimsposinf_flipsneginf_flipsr  	base_randr  r  s           rP   r  zrand_some_inf.<locals>.rand  s/   eR[[1ue$$%!3!3477288AU34::j%$XXb% 4z#::;cC..% D388T?S(L388T?S(LUE"D88L"((266"?FD88L"((BFF7%"@$GD"**T7FFrR   r  r  rI  r  s   `@@rP   rand_some_infrL    s    3)G, 
+rR   c                0     t                fdS )z=Return a random sampler that produces nans in floating types.c                   t        j                  |t        j                        rkt        j                  t        j
                  d|            j                  } 
| |      t        j
                  d|       
| |      z  z   }t        || |      S t        j                  |t        j                        s	 	| |      S t        |       } j                  | }|dk  }|dk  } 	| |      }t        j                  |t        j
                  t        j                  |      |      }t        j                  |t        j
                  t        j                   |      |      }t        t        j                  ||      | |      S )rA  r   rY   r  rB  g?)rU   r  r]   r   rC  r  rZ   r  r  r  r  r  r  r^   )r  rZ   rE  r   rF  r  	nan_flipsneg_nan_flipsr  rI  r  r  s            rP   r  zrand_some_nan.<locals>.rand4  s(   %!3!3477288AU34::j%$XXb% 4z#::;cC..eR[[1ue$$% D$ACIHMUE"D88Irxxe<dCD88M288RVVG5#A4HD"**T7FFrR   rJ  rK  s   `@@rP   rand_some_nanrQ  0  s    3)G. 
+rR   c                0     t                fdS )r>  c                   t        j                  |t        j                        s	 	| |      S t        j                  |t        j                        rkt        j
                  t        j                  d|            j                  } 
| |      t        j                  d|       
| |      z  z   }t        || |      S t        |       } j                  | dk  } j                  | dk  } j                  | dk  } 	| |      }t        j                  |t        j                  t        j                  |      |      }t        j                  |t        j                  t        j                   |      |      }t        j                  |t        j                  t        j                  |      |      }t        t        j                  ||      | |      S r@  )rU   r  r]   r  r   rC  r  rZ   r  r  r  r  rD  r  r^   )r  rZ   rE  r   rF  rG  rH  rO  r  rI  r  r  s            rP   r  z#rand_some_inf_and_nan.<locals>.randS  sd   eR[[1ue$$%!3!3477288AU34::j%$XXb% 4z#::;cC..% D388T?S(L388T?S(L$#%IUE"D88L"((266"?FD88L"((BFF7%"@$GD88Irxxe<dCD"**T7FFrR   rJ  rK  s   `@@rP   rand_some_inf_and_nanrT  M  s    3)G0 
+rR   c                ,     t                fd}|S )z1Return a random sampler that produces some zeros.c                    t        |       } j                  | dk  } | |      }t        j                  |t        j                  d|      |      }t        t        j                  ||      | |      S )rA  r8  r   rY   )r  r  r]   r  r  r  r^   )r  rZ   rF  zerosr  rI  r  s        rP   r  zrand_some_zero.<locals>.randr  sd    % DCHHdOc!EUE"D88E288AU3T:D"**T7FFrR   rJ  )r  r  rI  s   ` @rP   rand_some_zerorX  n  s    3)G 
+rR   c                      fd}|S )Nc                d   t        j                  |t         j                        r|nt         j                  }dk(  rQOt        j                  |t         j                        r t        j                  |      j
                  nt        d      j                  | |      j                  |      S )Nr   zArand_int requires an explicit `high` value for non-integer types.)r3  r  rZ   )	r]   r  integerr  r  r   r   r  rb   )r  rZ   	gen_dtyper3  r4  r  s      rP   fnzrand_int.<locals>.fn  s    ubjj9rxxI
axDL	ubjj	)xx"" . / 	/;;sE&  ((.u6rR   r   )r  r4  r3  r]  s   ``` rP   rand_intr^    s    
6 
)rR   c                      fd}|S )Nc                    j                  t        j                  xs t        j                  |       |      | d      S )NrY   Fr  replace)choicer]   aranger
  r  )r  rZ   r3  r  s     rP   r]  zrand_unique_int.<locals>.fn  s9    ::bii 8		%(8F %  1 1rR   r   )r  r3  r]  s   `` rP   rand_unique_intre    s    1 
)rR   c                     d fd	}|S )zSample an array of given shape containing indices up to dim (exclusive),
  such that the indices are unique along the given axis.
  Optionally, convert some of the resulting indices to negative indices.c                X   t        j                  |d | ||d  dd  z         }t        |      D cg c]  }	j                  | ||   d       }}t	        j
                  |      j                  |||         }|j                  |d | ||d  dd  z   ||   fz         }t	        j                  |d|      }t        t        j                  |       }t	        j                  |||      dk  j                         sJ |r+	j                  ddg|j                        }||xx   | z  cc<   |S c c}w )Nr   Fra  r   )	minlengthT)r
  r  rangerc  r]   r  r  moveaxisr
   bincountapply_along_axisallr  )
r  r  axisallow_negative
batch_sizerL   idxr   maskr  s
            rP   r]  z*rand_indices_unique_along_axis.<locals>.fn  s.   5$<%,qr*::;J Z 
 
jj5;j6C  ((3-


E$K
8C
++eETlU45\!"%55tF
GC
++c2t
$C BKK3/EtS1Q6;;===ZZsyy1d	$i3iJs   D'Tr   )r  r]  s   ` rP   rand_indices_unique_along_axisrt    s    & 
)rR   c                      fd}|S )Nc           	     z    t        t        j                   j                  t	        |        dk  |      | |      S )Nr8  rY   )r  r]   r^   r  r  )r  rZ   r  s     rP   	generatorzrand_bool.<locals>.generator  s8    jj>%01C7uEU rR   r   )r  rw  s   ` rP   	rand_boolrx    s     
rR   c                    	  |         J # |$ r2}t        |      j                  |      sJ d| d| d       Y d }~y d }~ww xY w)Nr(  

)r   
startswith)thunkerr_typemsges       rP   check_raisesr    sM    7	G5	 7q6S!6Rs$se2#66!7s   	 A(=Ac                    	  |         J # |$ r6}t        j                  |t        |            sJ | d| d       Y d }~y d }~ww xY w)Nrz  r(  )r,  rI  r   )r|  r}  patternr  s       rP   check_raises_regexpr    sK    <	G5	 <88GSV$;4y&;;$<s   	 A,AAc              #     K   | j                   E d {    t        j                  |       D ]  }t        |      E d {     y 7 27 	wrT   )eqnsr   	subjaxprs	iter_eqns)jaxprsubjaxprs     rP   r  r    sB     ZZ..' #h"""# "s   A	A*A	AA	A	c                j    t        j                  |      | }t        |j                        D cg c].  }|j                  t
        j                  k(  r|j                  d   0 }}|D ]E  }d|  d| }t        |t              r|d   | k(  sJ |       |d   | k(  r3J |       || k(  r@J |        y c c}w )N	precisionzUnexpected precision:  != r   r   )
r   
make_jaxprr  r  	primitiver   dot_general_pparamsrj   rb  )expected_precisionr   rl   r  eqn
precisionsr  r~  s           rP   assert_dot_precisionr    s    
#..
t
$%3<U[[3I 7C==C$5$55 

;' 7* 7 2i"#5"6d9+
FC)U#q\//44/q\//44/,,1c1,27s   3B0c                     t        j                  t        |fi |      | }t        |j                        D cg c].  }|j
                  t        j                  k(  r|j                  d   0 }}|D ]  }d|  d| }| |k(  rJ |        y c c}w )Npreferred_element_typez#Unexpected preferred_element_type: r  )	r   r  r
   r  r  r  r   r  r  )	expectedr   rl   rm   r  r  pref_eltypespref_eltyper~  s	            rP   !assert_dot_preferred_element_typer    s    
0#..//
0$
7%BKEKKBX :3mms'8'88 **56 :, :! (k/zk]
KC{"'C'"(:s   3Bc               '     K   g d}t        t        j                  t        |      z        dz   }|D ]2  t	        |      D ]"  }d d| ft        fd| D              z    $ 4 y w)N)r   r  
   r   rL   c              3  .   K   | ]  } |        y wrT   r   )rZ  r  r  s     rP   r[  z"cases_from_gens.<locals>.<genexpr>  s     %@Cc$i%@   )r0  NUM_GENERATED_CASESr   r.  ri  rb  )genssizescases_per_sizer  r  s       @rP   cases_from_gensr    sw     
%*003u:=>B. Ad>" Aas^%@4%@ @@@AAs   A%A(c              #    K   t               }d}t        j                  d      fd}t        |      t        j
                  k  r|t        j
                  k  r|dz  }t         | |            }|sHt        |      dkD  rt        d      |d   }|d   |v rnd}|j                  |d          | t        |      t        j
                  k  r|t        j
                  k  ry y y y w)Nr   *   c                    t        | t        t        f      st        |       } | j                  t	        |                gS rT   )rj   r  rb  r  r.  )r{   r  s    rP   
choose_onez,named_cases_from_sampler.<locals>.choose_one  s5    a$'
q'ackk#a&!"##rR   r   z@Generator is expected to only return a single case when samplingtestcase_name)
setnprRandomStater.  r  r   _MAX_CASES_SAMPLING_RETRIESr  r  add)r  seenretriesr  casescaser  s         @rP   named_cases_from_samplerr    s     	$'#$ 
T(..	.	.44	4qLGZ!E
5zA~[\\8DO$GHHT/"#
J 
T(..	.	.44	4 
/	4 
/s   CC&"C&c                h    t         j                  j                  d      }|j                  | |d      S )Nr  Fra  )r]   randomr  rc  )nmr  s      rP   _choicer    s+    
		b!#	AAu	--rR   c            	     V   | D cg c]  }t        |       } }|j                         D cg c]  \  }}|t        |      f }}}t        j                  d | D              t        j                  d |D              z  }g }t	        |t        |t        j                              D ]v  }i }| D ]0  }	|j                  |	|t        |	      z            |t        |	      z  }2 |D ]'  \  }}||t        |      z     ||<   |t        |      z  }) |j                  |       x |S c c}w c c}}w )z%Non-decorator form of sample_product.c              3  2   K   | ]  }t        |        y wrT   r.  )rZ  as     rP   r[  z+sample_product_testcases.<locals>.<genexpr>  s     %1A%r]  c              3  8   K   | ]  \  }}t        |        y wrT   r  )rZ  rL   r   s      rP   r[  z+sample_product_testcases.<locals>.<genexpr>  s     1HTQ#a&1Hs   )r  r   r
  r  r  minr  r   r  r.  r   )
rl   kwargr   r   r  	testcasesr  testcaser  s
             rP   sample_product_testcasesr    s   #	$$s)	$$	$!#,ADG,",
ii%%%		1HR1H(HH!)1c!06678 aH ooaCF
m$CFla  1a#a&jMhqkCFla X 
 
%,s
   D D%c                 8    t        j                  t        | i | S )a<  Decorator that samples from a cartesian product of test cases.

  Similar to absltest.parameterized.product(), except that it samples from the
  cartesian product rather than returning the whole thing.

  Arguments:
    *args: each positional argument is a list of dictionaries. The entries
      in a dictionary correspond to name=value argument pairs; one dictionary
      will be chosen for each test case. This allows multiple parameters to be
      correlated.
    **kw: each keyword argument is a list of values. One value will be chosen
      for each test case.
  )r   
parametersr  )rl   r  s     rP   sample_productr    s      
	!	!#;T#HR#H	IIrR   c                       fd}|S )1Test case decorator for subclasses of JaxTestCasec                   t        j                  |       rt        | t              sJ d       i | _        | j
                  D ]'  }| j                  j                  |j                         ) | j                  j                         | S Nz9@with_config can only wrap JaxTestCase class definitions.)inspectisclass
issubclassJaxTestCase_default_thread_local_config	__bases__r  clsbkwdss     rP   	decoratorzwith_config.<locals>.decorator&  st    ??3JsK$@}B}}@')C$]] N	&&--a.L.LMN$$++D1JrR   r   r  r  s   ` rP   with_configr  $       
rR   c                       fd}|S )r  c                   t        j                  |       rt        | t              sJ d       i | _        | j
                  D ]'  }| j                  j                  |j                         ) | j                  j                         | S r  )r  r  r  r  _default_global_configr  r  r  s     rP   r  z%with_global_config.<locals>.decorator1  st    ??3JsK$@}B}}@!#C]] B	  ''(@(@AB%%d+JrR   r   r  s   ` rP   with_global_configr  /  r  rR   c                2     |rt         nt         fd}|S )zDecorator that promotes the arguments of `fun` to `jnp.result_type(*args)`.

  jnp and np have different type promotion semantics; this decorator allows
  tests make an np reference implementation act more like a jnp
  implementation.
  c                 N    t        |       \  }}t        | |       }  | i |S rT   )r8   r:   )rl   r  	flat_argstree_promoter   s       rP   wrapperz!promote_like_jnp.<locals>.wrapperC  s2    "4(OIt$) 45DrR   )r$   r#   )r   inexactr  r  s   `  @rP   promote_like_jnpr  ;  s     (/#N( 
.rR   c               +  h  K   i }	 | j                         D ]3  \  }}t        j                  |      ||<   t        j                  ||       5 d  |j                         D ]  \  }}t        j                  ||        y # |j                         D ]  \  }}t        j                  ||        w xY wwrT   )r   r   r  r  )r  original_configkeyr   s       rP   global_config_contextr  I  s     / jjl  
U#\\#.ocmmC  
%++-  
UmmC o++-  
UmmC s   B2A
A? /B2?0B//B2c               +     K   t               }| j                         D ],  \  }}|j                  t        j                  |   |             . 	 d  |j                          y # |j                          w xY wwrT   )r   r   enter_contextr   config_statesclose)r  stackconfig_namer   s       rP   thread_local_config_contextr  U  sa     
+% JJL Bk5	,,[9%@AB		KKMEKKMs   A
A7A" A7"A44A7c                      e Zd Zd Zy)
NotPresentc                     y)Nz<not present>r   r   s    rP   __repr__zNotPresent.__repr__`  s    rR   N)r   r   r   r  r   rR   rP   r  r  _  s    rR   r  c            
   #    K   t         j                  } t        j                  j                  j                         }d  t        j                  j                  }t         j                  }||k7  r|j                         |j                         z  D ci c]J  }||vs||vs||   ||   k7  r5||j                  |t                     |j                  |t                     fL }}t        d|       | |urt        d|  d|       y c c}w w)Nz9Test changed global config values. Differing values are: z>Test changed the compilation cache object: before test it was z, now it is )
r   _cacher   r   valuescopykeysr`   r  r   )starting_cachestarting_configending_configending_cacher   	differings         rP   assert_global_configs_unchangedr  d  s    $++.JJ%%**,/**##-")),%+002]5G5G5IIB.!=2H(+}Q/?? _((JL9=;L;LQPZP\;]^^ BI B TU^T_`
aa<'

H
,|n	6  (Bs   BDAD +Dc                  
    e Zd ZU dZi Zded<   dddddd	Zd
Zded<    fdZd# fdZ	d Z
d$dZddddddZdd
d
dddZdddZdd
d
ddddZd Zed        Zed
dd       Zed        Zdd
d
d
dd d!Z	 	 d%d"Z xZS )&r  zDBase class for JAX tests including numerical checks and boilerplate.zdict[str, Any]r  Tstrictraiseofferror)jax_enable_checksjax_numpy_dtype_promotionjax_numpy_rank_promotionjax_traceback_filteringjax_legacy_prng_keyNzExitStack | None_context_stackc                   t         |           | j                  t                      t	        j
                  t        j                  | j                  j                                     | _
        t               | _        | j                  | j                  j                         | j                  }|j                  t        di | j                          | j"                  j%                         D ]@  \  }}|j                  t'        j(                  j*                  j,                  |   |             B t.        j0                  rt2        j0                  dk  sJ d       |j                  t+        j4                  d             |j                  t+        j6                  d             |j                  t+        j8                  d             |j                  t+        j:                  d             |j                  t=        j>                               }|j                  t+        j@                  |             |jC                  tD        jF                         y y )Nr   z0Persistent compilation cache is not thread-safe.Tr   r   )$supersetUpr  r  r  r  zlibadler32_testMethodNameencode_rngr   r  
addCleanupr  r  r  r  r   r   r   r   r  &TEST_WITH_PERSISTENT_COMPILATION_CACHEr   r5   enable_compilation_cacheraise_persistent_cache_errors&persistent_cache_min_compile_time_secs%persistent_cache_min_entry_size_bytesr   TemporaryDirectorycompilation_cache_dircallbackr   reset_cache)r   r  r  r   tmp_dir	__class__s        rP   r  zJaxTestCase.setUp  s   	GMO689
 T-A-A-H-H-J KLDI $+DOOD''--.E	-L0K0KLM"??EEG MU#((//77DUKLM .33##q(\*\\(&99$?@&>>tDE&GGJK&FFqIJ##H$?$?$ABg&66w?@nn&223 4rR   c                N    t        j                         sJ t        |           y rT   )r   reset_trace_stater
  tearDown)r   r  s    rP   r  zJaxTestCase.tearDown  s     !!###	GrR   c                    | j                   S rT   )r  r   s    rP   r  zJaxTestCase.rng  s    99rR   c                    t        j                  |      r| j                  t        |      S | j	                  t
        |      S )zAssert warning or error, depending on deprecation state.

    For use with functions that call :func:`jax._src.deprecations.warn`.
    )r   is_acceleratedassertRaisesRegexr   assertWarnsRegexDeprecationWarning)r   deprecation_idmessages      rP   assertDeprecationWarnsOrRaisesz*JaxTestCase.assertDeprecationWarnsOrRaises  s9    
 "">2##J88""#5w??rR   r<   F)check_dtypesr   allow_object_dtypeverbosec                  |r| j                  ||       t        j                  |      }t        j                  |      }|s1|j                  t        k(  s|j                  t        k(  rt        d      t        j                  d      5  t        j                  j                  ||||       ddd       y# 1 sw Y   yxY w)z-Assert that x and y arrays are exactly equal.a  assertArraysEqual may be poorly behaved when np.asarray casts to dtype=object. If comparing PRNG keys, consider random_test.KeyArrayTest.assertKeysEqual. If comparing collections of arrays, consider using assertAllClose. To let this test proceed anyway, pass allow_object_dtype=True.ignore)over)r   r+  N)	assertDtypesMatchr]   r^   rZ   objectry   errstatetestingassert_array_equal)r   actualdesiredr)  r   r*  r+  s          rP   assertArraysEqualzJaxTestCase.assertArraysEqual  s     
VW-ZZFjj!GV\\V%;w}}PV?V	IJ J 
(	# 5jj##FGW,3 $ 55 5 5s   $B55B>r)  atolrtolr   c               b   | j                  |j                  |j                         t        t        t	        |      |      t        t	        |      |            }t        t        t	        |      |      t        t	        |      |            }t        |||||       |r| j                  ||       yy)zFAssert that actual and desired are close (up to numerical tolerances).)r8  r9  r   N)assertEqualr  r   r0   r(   r%   r/  )r   r4  r5  r)  r8  r9  r   s          rP   assertArraysAllClosez JaxTestCase.assertArraysAllClose  s     	V\\7==1y.	&/40PQDy.	&/40PQD67D'R
VW- rR   canonicalize_dtypesc               "   t         j                  j                  sQ|rO| j                  t	        j
                  t        |      d      t	        j
                  t        |      d             y | j                  t        |      t        |             y )NT)allow_extended_dtype)r   r  r   r;  rU   rW   r(   )r   r4  r5  r>  s       rP   r/  zJaxTestCase.assertDtypesMatch  sf    ""':
w11&.W[\11&/X\]_ vf~vg7rR   r)  r8  r9  r>  r   c          
        t        |t              r| j                  |t               | j                  t	        |j                               t	        |j                                      |j                         D ]   }| j                  ||   ||   |||||       " yt        |      rt        |d      sz| j                  t        |      xr t        |d              | j                  t        |      t        |             t        ||      D ]  \  }	}
| j                  |	|
|||||        yt        |d      st        j                  |      r| j                  t        |d      xs t        j                  |             |r| j                  |||       t        j                  |      }t        j                  |      }| j!                  ||d|||       y||k(  ryt#        t%        |      t%        |      f      )zPAssert that actual and desired, either arrays or nested tuples/lists, are close.rA  	__array__r=  Fr7  N)rj   r   assertIsInstancer;  r  r  assertAllCloser|   hasattr
assertTruer.  r  r]   isscalarr/  r^   r<  ry   r  )r   r4  r5  r)  r8  r9  r>  r   r   
actual_eltdesired_elts              rP   rE  zJaxTestCase.assertAllClose  s    &$
GT*
s6;;=)3w||~+>?{{} -!F1IwqzSW!%;N$+ 	 	-- 
V	WV[%A
ook'*P77K3P/PQ
s6{CL1%(%9 -
!*kJ,UY!%;N$+ 	 	-- 
	%V)<
oogg{3Kr{{77KL	vwDWXzz&!f

7#g
e$UY(/   1	7	tF|T']344rR   c                r   t        j                  |      }t        j                  |      }t        j                  d      }t        j                  |d|j                               }t        j                  |d|j                               }||k7  rt        d| d       | j                  ||d| d|        y)zGAsserts two strings are equal, after dedenting and stripping each line.z\s*\n\s*r(  zFound
z
Expecting
r~  N)textwrapdedentr,  compilerN   stripprintassertMultiLineEqual)r   r  whatignore_space_reexpected_clean
what_cleans         rP   assertMultiLineStrippedEqualz(JaxTestCase.assertMultiLineStrippedEqual  s    x(H??4 Djj-OVVOT8>>3CDNtzz|<J^#gdV2nj$+D6xj"I  KrR   c              #  f   K   t        j                         5  d  d d d        y # 1 sw Y   y xY wwrT   )r   raise_on_warningsr   s    rP   assertNoWarningszJaxTestCase.assertNoWarnings  s)     		,	,	.   s   1%	1.1rL  c             #    K   t        j                         5 }d  d d d        D ]4  }t        |j                  |      s||t	        |j                        vr4 y  | j                  d| d| d|        y # 1 sw Y   ]xY wwNzExpected warning not found z:'z', got )r   record_warningsrj   r'  r   fail)r   warningr~  wsws        rP   assertWarnszJaxTestCase.assertWarns  s     		*	*	,  		7+	SAII6 	II+G9Bse7  s   BA8AB8B=Bc              #  T  K   |t        j                  |      }t        j                         5 }d  d d d        D ]A  }t	        |j
                  |      s|%|j                  t        |j
                              sA y  | j                  d| d| d|        y # 1 sw Y   jxY wwr\  )	r,  rO  r   r]  rj   r'  searchr   r^  )r   r_  regexr`  ra  s        rP   r$  zJaxTestCase.assertWarnsRegex  s     

5!		*	*	,  		7+		5<<AII#? 	II+G9BugW  s   ,B(BA)B(B%!B()r)  r   r9  r8  check_cache_missesc                    |       } fd}	d | }
t        d |
      }t        d |
      } j                  ||       t        j                  j	                         j
                  } | }
|r[t        j                  dk  rH j                  |t        j                  j	                         j
                  dj                               t        j                  |	      }d || }d || } j                  ||
||xs ||xs |        j                  ||
||xs ||xs |        |       }d | }
d || } j                  ||
||xs ||xs |       y	)
zBHelper method for running JAX compilation and allclose assertions.c                 0    j                          |  S rT   )rG  )rl   r   python_should_be_executingr   s    rP   wrapped_funz1JaxTestCase._CompileAndCheck.<locals>.wrapped_fun2  s    
oo01$ZrR   Tc                ,    t        j                  |       S rT   )r]   r  rz   s    rP   ri   z.JaxTestCase._CompileAndCheck.<locals>.<lambda>9  s    rxx{ rR   c                R    t        j                  t        j                  |             S rT   )r]   r  r^   rz   s    rP   ri   z.JaxTestCase._CompileAndCheck.<locals>.<lambda>:  s    288BJJqM#: rR   r   z?Compilation detected during second call of {} in op-by-op mode.F)r)  r8  r9  N)r9   r;  r   r   r   r   r5   r   r  r   jitrE  )r   r   
args_makerr)  r   r9  r8  rf  rl   rj  
python_anspython_shapes	np_shapescache_missescfunmonitored_anscompiled_ansri  s   ``               @rP   _CompileAndCheckzJaxTestCase._CompileAndCheck-  s}    <D "&dJ2J?M:JGI]I.22==?FFLdJ.449

77BBDKK&+
 77;D!%$KM!&;Lz![St{s  <j|![St{s  < <D!%dJ!&;Lj|![St{s  <rR   c	                d     |       }	 ||	 }
 ||	 }| j                  |
|||xs ||xs ||       y )N)r)  r8  r9  r>  )rE  )r   numpy_reference_oplax_oprn  r)  r   r8  r9  r>  rl   lax_ans	numpy_anss               rP   _CheckAgainstNumpyzJaxTestCase._CheckAgainstNumpy\  sH     <DdmG"D)I![St{s,?  ArR   r   None)r&  r   r'  r   )TNNNT)r   r   r   rw  r  __annotations__r  r  r  r  r  r(  r6  r<  r/  rE  rW  r	   rZ  rb  r$  rv  r|  __classcell__)r  s   @rP   r  r  y  s    L+-.-!) '$"" &*.")48@ @DR+0$5* CGT $b
. GK 8 =AtRV)-r5<K   (, 
 
    ?C t-<` GK-1ArR   r  rm  c                    | S rT   r   )r{   rl   rm   s      rP   ri   ri   h  s    a rR   noopc                      e Zd Zd Zd Zy)BufferDonationTestCasec                B    | j                  |j                                y rT   )rG  
is_deletedr   r{   s     rP   assertDeletedz$BufferDonationTestCase.assertDeletedq  s    OOALLN#rR   c                B    | j                  |j                                y rT   )assertFalser  r  s     rP   assertNotDeletedz'BufferDonationTestCase.assertNotDeletedt  s    Q\\^$rR   N)r   r   r   r  r  r   rR   rP   r  r  p  s    $%rR   r  c              #    K   t        |       \  }}t        j                  |      }t        t	        j
                               }t        |      |k  rt        j                  d| d      t        j                  |d|       j                  |      }t        j                  j                  ||      5  d ddd       y# 1 sw Y   yxY ww)zDTest utility for setting up meshes given mesh data from `schedules`.Test requires z local devicesN)r6   r
  r  r  r   ra  r.  r  r  r]   r  r  shardingMesh)named_shape
axis_namesr  r  ra  mesh_devicess         rP   	with_meshr  ~  s      [)*e	5	$s((*+-$


nTF.A
BB-./77>,
||z2 
	
 
 
s   B/C1B?6	C?CCc                      fdS )Nc                 8      t        |d               | i |S )Nr   )r  )rl   rm   ro   s     rP   ri   z'with_mesh_from_kwargs.<locals>.<lambda>  s%    !=!:6&>!:1!=t!Nv!N rR   r   ro   s   `rP   with_mesh_from_kwargsr    s	    	NNrR   c                X     t        j                  d dD              t        |             S )Nc              3  0   K   | ]  \  }}}|||d   yw))r  r   axis_resourcesNr   )rZ  r   r   r  s       rP   r[  z(with_and_without_mesh.<locals>.<genexpr>  s%      ("dN DNK(s   ))r<   r   r   )r  ))r{   r%  ))r  r{   )r   named_parametersr  r  s    rP   with_and_without_meshr    s7    
	'	' ('( 

 Q
! !rR   c                t     't         j                  j                  ft              z  n fd}|S )Nc                      fd}|S )Nc                     t              }t        j                  j                  |      5   | i |d|icd d d        S # 1 sw Y   y xY w)N
axis_typesr   )create_meshr   r  use_mesh)rl   rm   r   r  r]  
iota_ordernamesr  s      rP   mesh_fnz6with_explicit_mesh.<locals>.decorator.<locals>.mesh_fn  sL    zjId<<  & .4-6--. . .s   AAr   )r]  r  r  r  r  r  s   ` rP   r  z%with_explicit_mesh.<locals>.decorator  s    . . NrR   )mesh_libAxisTypeExplicitr.  )r  r  r  r  r  s   ```` rP   with_explicit_meshr    s;    % ""++-E
:+5  
rR   c                   t        j                  |       }t        t        j                               |k  rt        j                  d| d      |rit        t        j                         d       }t        j                  |d |       j                  |       }t        j                  j                  |||      S t        j                  | ||      S )Nr  z global devices.c                    | j                   S rT   )id)rf  s    rP   ri   zcreate_mesh.<locals>.<lambda>  s
    !$$ rR   )r  r  )r
  r  r.  r   rG  r  r  sortedr]   r  r  r  r  	make_mesh)
mesh_shaper  r  r  r  rG  r  s          rP   r  r    s    	:	$$


nTF2BC
DDS[[]7G88GETN+33J?L<<\:*MM==ZJGGrR   c                  &    e Zd Z e       Zd Zd Zy)_cached_propertyc                4    || _         | j                  | _        y rT   )_methodnull_value)r   methods     rP   r   z_cached_property.__init__  s    DL))DKrR   c                v    | j                   | j                  u r| j                  |      | _         | j                   S rT   )r  r  r  )r   objr  s      rP   __get__z_cached_property.__get__  s,    {{diiLL%dk;;rR   N)r   r   r   r0  r  r   r  r   rR   rP   r  r    s    	$rR   r  c                      e Zd ZdZd Zed        Zed        Zed        Zed        Z	ed        Z
ed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zy)_LazyDtypeszA class that unifies lists of supported dtypes.

  These could be module-level constants, but device_under_test() is not always
  known at import time, so we need to define these lists lazily.
  c                L    t                t        |      fd|D              S )Nc              3  ,   K   | ]  }|v s|  y wrT   r   )rZ  rf  	supporteds     rP   r[  z(_LazyDtypes.supported.<locals>.<genexpr>  s     <aQ)^<s   	)r  r  )r   r   r  s     @rP   r  z_LazyDtypes.supported  s"     "I4<<6<<<rR   c           
     T   t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  g
}| j                  |      S rT   )rU   r  r  r  float8_e4m3fnuzr  float8_e5m2fnuzfloat8_e3m4float8_e4m3float8_e8m0fnufloat4_e2m1fnr  )r   float_dtypess     rP   custom_floatsz_LazyDtypes.custom_floats  sv       L >>,''rR   c                `    | j                  t        j                  t        j                  g      S rT   )r  r]   r  r  r   s    rP   r  z_LazyDtypes.floating  s    >>2::rzz233rR   c                    | j                  t        j                  t        j                  t        j
                  t        j                  g      S rT   )r  rU   r  r]   r  r  r  r   s    rP   all_floatingz_LazyDtypes.all_floating  s,    >>7++RZZRZZPQQrR   c                `    | j                  t        j                  t        j                  g      S rT   )r  r]   r	  r  r   s    rP   r[  z_LazyDtypes.integer  s    >>288RXX.//rR   c                    | j                  t        j                  t        j                  t        j                  t        j
                  g      S rT   )r  r]   r  r  r	  r  r   s    rP   all_integerz_LazyDtypes.all_integer  s*    >>277BHHbhhABBrR   c                `    | j                  t        j                  t        j                  g      S rT   )r  r]   r  r  r   s    rP   unsignedz_LazyDtypes.unsigned  s    >>299bii011rR   c                    | j                  t        j                  t        j                  t        j                  t        j
                  g      S rT   )r  r]   r  r  r  r  r   s    rP   all_unsignedz_LazyDtypes.all_unsigned  s*    >>288RYY		299EFFrR   c                `    | j                  t        j                  t        j                  g      S rT   )r  r]   r  r  r   s    rP   complexz_LazyDtypes.complex  s    >>2<<788rR   c                B    | j                  t        j                  g      S rT   )r  r]   r  r   s    rP   booleanz_LazyDtypes.boolean  s    >>288*%%rR   c                4    | j                   | j                  z   S rT   )r  r  r   s    rP   r  z_LazyDtypes.inexact  s    ==4<<''rR   c                4    | j                   | j                  z   S rT   )r  r  r   s    rP   all_inexactz_LazyDtypes.all_inexact  s    t||++rR   c                h    | j                   | j                  z   | j                  z   | j                  z   S rT   )r  r[  r  r  r   s    rP   numericz_LazyDtypes.numeric  s'    ==4<<'$--7$,,FFrR   c                    | j                   | j                  z   | j                  z   | j                  z   | j                  z   S rT   )r  r  r  r  r  r   s    rP   rm  z_LazyDtypes.all   s>     0 0043D3DDLL<<( )rR   N)r   r   r   rw  r  r  r  r  r  r[  r  r  r  r  r  r  r  r  rm  r   rR   rP   r  r    s   
= ( ( 4 4 R R 0 0 C C 2 2 G G 9 9 & & ( ( , , G G ) )rR   r  c                     t         fd D              rt        j                  d      S t        j                  d      S )zv
  Context manager to enable strict promotion if all dtypes match,
  and enable standard dtype promotion otherwise.
  c              3  .   K   | ]  }|d    k(    ywr   Nr   )rZ  rZ   r   s     rP   r[  z3strict_promotion_if_dtypes_match.<locals>.<genexpr>  s     0&)	0r  r  standard)rm  r   numpy_dtype_promotionr   s   `rP    strict_promotion_if_dtypes_matchr  	  s5    
 	000$$X..		"	":	..rR   z$([0-9]+(?:\.[0-9]+)*)(?:(rc|dev).*)?c                    t         j                  |       }|t        d|  d      t        d |j	                  d      j                  d      D              S )NzUnable to parse version ''c              3  2   K   | ]  }t        |        y wrT   rX  rY  s     rP   r[  z parse_version.<locals>.<genexpr>  s     5!s1v5r]  r   r>  )_version_regexrI  r   rb  rJ  r+  )r   r  s     rP   parse_versionr    sP    1!Y
015
66	5qwwqz//45	55rR   c                 4    t        t        j                        S rT   )r  r]   __version__r   rR   rP   numpy_versionr    s    	r~~	&&rR   )r  one_containingc                   |3| D cg c]'  }t        ddt        t         ||                  i|) }}n[| D ]T  j                  d      }|1dj	                  fdt        j                               D              }t        |      d<   V | }Zt        fd|D              }|s$J d ddj	                  d |D              z          |d	   d
d<   t        j                  g      S t        j                  | S c c}w )a  Decorator for named parameterized tests, with filtering support.

  Works like ``parameterized.named_parameters``, except that it sanitizes the test
  names so that we can use ``pytest -k`` and ``python test.py -k`` test filtering.
  This means, e.g., that many special characters are replaced with `_`.
  It also supports the ``one_containing`` arg to select one of the tests, while
  leaving the name unchanged, which is useful for IDEs to be able to easily
  pick up the enclosing test name.

  Usage:
     @jtu.parameterized_filterable(
       # one_containing="a_4",
       [dict(a=4, b=5),
        dict(a=5, b=4)])
     def test_my_test(self, *, a, b): ...

  Args:
    kwargs: Each entry is a set of kwargs to be passed to the test function.
    testcase_name: Optionally, a function to construct the testcase_name from
      one kwargs dict. If not given then ``kwargs`` may contain ``testcase_name`` and
      otherwise the test case name is constructed as ``str(kwarg)``.
      We sanitize the test names to work with -k test filters. See
      ``sanitize_test_name``.
    one_containing: If given, then leaves the test name unchanged, and use
      only one of the ``kwargs`` whose `testcase_name` includes ``one_containing``.
  r  rL   c              3  2   K   | ]  }| d |      yw)=Nr   )rZ  r   r  s     rP   r[  z+parameterized_filterable.<locals>.<genexpr>E  s'      !=%& %&3a1w !=s   c              3  0   K   | ]  }|d    v r|  ywr  Nr   )rZ  r  r  s     rP   r[  z+parameterized_filterable.<locals>.<genexpr>K  s%      ?B&"_*==  ?s   zNo testcase_name contains 'z"'. The testcase_name values are
  z
  c              3  &   K   | ]	  }|d      ywr  r   )rZ  r  s     rP   r[  z+parameterized_filterable.<locals>.<genexpr>P  s     J""_%Js   r   r<   r   )
r   rQ   r   r`   rA  r  r  rb  r   r  )rm   r  r  r  kwargs_with_testcase_namefiltereds     ``  rP   parameterized_filterabler    sC   B  !
 J+Cb0A,BCJrJ! !  >ff_-m		 !=*0*;!= =.}=b> !' ?"; ? ?H L#N#3 4) )kkJ0IJJKL8 
!BB))2$//))+DEE/!s   ,Dc              #     K   	 t        j                  |        d t        j                  |        y# t        j                  |        w xY ww)zFManages registering/unregistering an event duration listener callback.N)r   %register_event_duration_secs_listener/_unregister_event_duration_listener_by_callback)r  s    rP    register_event_duration_listenerr  W  s9     I44X>	>>xHJ>>xHs   A3 AA

Ac            
   +    K   | D ci c]#  }|t         j                  j                  |d      % }}t         j                  j                  | j	                         D ci c]  \  }}|	|| c}}       	 d | D cg c]"  }t         j                  j                  |d      $ }}t         j                  j                  |j	                         D ci c]  \  }}|	|| c}}       yc c}w c c}}w c c}w c c}}w # | D cg c]"  }t         j                  j                  |d      $ nc c}w }}t         j                  j                  |j	                         D ci c]  \  }}|	|| nc c}}w c}}       w xY ww)a  Context manager to temporarily set/unset one or more environment variables.

  Caution: setting environment variables is not thread-safe. If you use this
  utility, you must annotate your test using, e.g., @thread_unsafe_test() or
  @thread_unsafe_test_class().

  Examples:

    >>> import os
    >>> os.environ['my_var'] = 'original'

    >>> with set_env(my_var=None, other_var='some_value'):
    ...   print("my_var is set:", 'my_var' in os.environ)
    ...   print("other_var =", os.environ['other_var'])
    ...
    my_var is set: False
    other_var = some_value

    >>> os.environ['my_var']
    'original'
    >>> 'other_var' in os.environ
    False
  N)r   environpopr  r   )rm   r  originalr   r   rL   s         rP   set_envr  a  s%    2 9??c2::>>#t,,?(?**fllnFdaQTFGL	.45sT	"5A5JJ(8J1AMq!tJK @F 	6J /55sT	"55A5JJ(8J1AMq!tJJKsu   F(C,.F
C1
(C1
-F6D :F>'C7%.F
C<
C<
#FF'D/.4F"
E3-E32FFc                      t        j                   fdd      | \  }\  }} t        j                  d       ||      }||fS )Nc                 0    t        j                  g|  S rT   )r   vjp)rl   ro   s    rP   ri   z fwd_bwd_jaxprs.<locals>.<lambda>  s    CGGA%% rR   T)return_shapec                     | |      S rT   r   )resoutss     rP   ri   z fwd_bwd_jaxprs.<locals>.<lambda>  s
    s4y rR   )r   r  )ro   example_args	fwd_jaxpry_shape	res_shape	bwd_jaxprs   `     rP   fwd_bwd_jaxprsr
    sP    %:CNN%D%:;G%I!)!gy9cnn89)WM)	I	rR   c           	     .   t               dk\  rt        d      t        j                  | |d      } t        j                  ||d      }t        j                  | |      \  } }t        j
                  t        j                  | ddddf         |d         d   S )z;Implementation of numpy.vecdot for testing on numpy < 2.0.0)r%  r   r   z0should be calling vecdot directly on numpy 2.0.0r   .N).N).r   r   )r  r   r]   rj  broadcast_arraysmatmulconj)r{   yrn  s      rP   numpy_vecdotr    s    _	!
G
HHkk!T2!kk!T2!			Q	"$!Q	2771S$\?+Qy\	:9	EErR   c                  
 ||}t        j                  |       
t        j                         }|j	                  d      xs |j	                  d      }|rAt        j
                         dk(  r*t        j                  
j                  
j                        n
j                  
fd} ||      } ||      }|j                  ddd|z  z   f      j                  dd|z  z   d	      j                  |       }|j                  d      j                  |       }	d	|	j                  dd |	j                  dd|z  z   df      j                  dd|z  z   d
      }	||	z   S )a  Return a 2-D array of complex numbers that covers the complex plane
     with a grid of samples.

     The size of the grid is (3 + 2 * size_im) x (3 + 2 * size_re)
     that includes infinity points, extreme finite points, and the
     specified number of points from real and imaginary axis.

     For example:

     >>> print(complex_plane_sample(np.complex64, 0, 3))
     [[-inf          -infj   0.          -infj  inf          -infj]
      [-inf-3.4028235e+38j   0.-3.4028235e+38j  inf-3.4028235e+38j]
      [-inf-2.0000000e+00j   0.-2.0000000e+00j  inf-2.0000000e+00j]
      [-inf-1.1754944e-38j   0.-1.1754944e-38j  inf-1.1754944e-38j]
      [-inf+0.0000000e+00j   0.+0.0000000e+00j  inf+0.0000000e+00j]
      [-inf+1.1754944e-38j   0.+1.1754944e-38j  inf+1.1754944e-38j]
      [-inf+2.0000000e+00j   0.+2.0000000e+00j  inf+2.0000000e+00j]
      [-inf+3.4028235e+38j   0.+3.4028235e+38j  inf+3.4028235e+38j]
      [-inf          +infj   0.          +infj  inf          +infj]]

  NaarcharmDarwinc                   d}j                   |z  x}}j                  |z  }t        j                  dd| z  z   j                        }t        t              5  t        j                  ||| j                         }|d d d    }|||  dz
  d ||d| dz    d d d        | dkD  rj                  |d<   j                  |d<   | d	kD  r	 || <   	||  dz
  <   t        j                   |d	<   t        j                  |d<   |S # 1 sw Y   ixY w)
Ngry	O
@r  r%  rY   )categoryr   r   r   )maxexpminexpr]   rW  rZ   ignore_warningRuntimeWarninglogspacer  r   rD  )
r  prec_dps_ratiologminlogmaxlogtinyaxis_pointshalf_neg_line	half_linerV   smallests
           rP   make_axis_pointsz.complex_plane_sample.<locals>.make_axis_points  s   'Nll^33FVll^+G((1q4x<u{{;K		0 .{{67DLLm 2&&i"+k4%!)B -k!D1H. axyyk!n		k"oax#)k$'k4%!)ffWKNffKO. .s   ?DDr   r  r%  r   r   )r]   rV   r   machiner{  system	nextaftertinyr   r  repeatrb   r  rC  )rZ   size_resize_imr&  
is_arm_cpur%  real_axis_pointsimag_axis_points	real_part	imag_partrV   r$  s             @@rP   complex_plane_sampler2    s>   , _G
((5/%'!!'*Gg.@.@.G*4>8??CTX`C`R\\%**eii0fkfpfp(. &g.%g.&&AGO'<=DDQW_VWX__`ef)%%a(--e4))..Q[" 56==a!g+oqQ)	Y	rR   c                      e Zd ZdZ eddddd      Zej                         D  ci c]  \  }}||
 c}}} Z edd	
      Z edddd      Z	 edddd      Z
fdZd Zd Zd ZfdZxZS c c}}} w )vectorize_with_mpmathzLSame as numpy.vectorize but using mpmath backend for function evaluation.
  	complex32r  r  
complex256clongdouble)r  r  r  float128
longdouble   5   )r  r  iiii)r  r  r  r8        i   i @  c                   |j                  dd       }|t        d      |j                  dd      | _        |j                  dd      | _        || _        t               | _        t               | _        | j                  j                         D ]N  \  }}| j                  j                  j                         }||_        || j                  |<   || j                  |<   P t        | 8  |i | y )Nmpmathz3vectorize_with_mpmath: no mpmath argument specifiedextra_prec_multiplierr   
extra_prec)r  r   r@  rA  r?  r   contextscontexts_inv
float_precr   mpcloneprecr
  r   )r   rl   rm   r?  	fp_formatrG  ctxr  s          rP   r   zvectorize_with_mpmath.__init__  s    ZZ$'F~LMM!',CQ!GDjjq1DODKFDMD??002 )	4KKNN  "cch!$dmmI(d	) 
Gd%f%rR   c                8   t        |t        j                  t        j                  t        j                  f      r@t        |j                        }| j                  j                  ||      }| j                  |   S t        dt        |      j                   d      )Nzget mpmath context from z	 instance)rj   r]   r  r  r   r   rZ   map_complex_to_floatr`   rB  NotImplementedErrorr  r   )r   r{   rH  s      rP   get_contextz!vectorize_with_mpmath.get_context  su    !bjj"++r/A/ABCagg,i++//	9Ei]]9%%
 8a9I9I8J)T
UUrR   c                j   t        |t        j                        rVt        j                  t	        | j
                  |j                               t              j                  |j                        S t        |t        j                        r| j                  }| j                  |      }|j                  \  }}t        j                  |      r%|j                  |j                   j"                        S t        j$                  |      r%|j                  |j                   j&                        S t        j(                  |      r%|j                  |j                   j*                        S t        j,                  |      rt        j.                  |      \  }}t1        t        j2                  ||            }t1        ||z
        }	|j                  |j                   j5                  ||	||            }
|j-                  |
      sJ |
j6                         |
S t        |t        j8                        rg| j                  |j:                        | j                  |j<                        }}|j>                  jA                  |j6                  |j6                  f      S tC        dtE        |      jF                   d      )zKConvert numpy array/scalar to an array/instance of mpmath number type.
    rY   convert z instance to mpmath number type)$rj   r]   r  fromiterrB  nptompflattenr0  r  r  r  r?  rM  _prec_roundingisposinfmake_mpflibmpfinfisneginffninfr  fnanisfinitefrexpr0  ldexpfrom_man_exp_mpf_r   rC  imagcontextmake_mpcrL  r  r   )r   r{   r?  rI  rG  roundingmantissaexponentmanexpr  r,  ims                rP   rQ  zvectorize_with_mpmath.nptomp	  s    !RZZ [[T[[!))+6fEMMaggVV	Ar{{	#{{fQc))ndH	Q||FLL--..;;q>||FLL..//88A;||FLL--..;;q>XXa[("((8T*+(T/"LL223T8LM||A''	Ar))	*{{166"DKK$7"bZZ  "((BHH!566
a)9)9(::YZ
[[rR   c                   t        |t        j                        r|j                  j                  dk(  r|j                         }|d   }|j                  }| j                  |   }t        ||j                        rt        t        | j                  |         }n)t        ||j                        rt        t        |      }nd}|t        j                  t        | j                  |      |      j                  |j                         S t        || j"                  j$                  j&                        r|j                  }t        ||j                        r| j                  |   }t        t        | j                  |         } |       j                  d      j)                  t        t        |            }| j                  |j*                        |d<   | j                  |j,                        |d<   |j)                  |      d   S t        ||j                        r| j                  |   }t        t        |      }|j/                  |      r
 | j"                  j0                  j2                  g |j4                  |j6                   \  }}	}
}|dk\  sJ ||	|
||j4                  f       |
|z   | j8                  |   k  r|r|j:                   S |j:                  S |
|z   | j<                  |   kD  r|r|j>                  S |j@                  S  ||r|	 n|	      }	t        jB                  |	|
      }t        j.                  |      sJ |||j4                  |	f       |S |jE                  |      r |t        jF                        S |jI                  |      r: ||j4                  d   rt        j@                         S t        j@                        S tK        dtM        |       d      )z8Convert mpmath instance to numpy array/scalar type.
    Or   NrY   r   rO  z& instance to numpy floating point type)'rj   r]   r  rZ   ra   rR  ra  rC  mpcr  map_float_to_complexmpfrP  rB  mptonpr  r  r?  ctx_mp	mpnumericr  rC  r`  r[  rV  	normalizer_  rS  float_minexpzerofloat_maxexpninfrD  r]  r  r  isinfrL  r  )r   r{   x_flatr  rI  rH  rZ   r  signrf  rg  bcs               rP   rn  zvectorize_with_mpmath.mptonp$  s    !RZZ QWW\\S%8yy{fAYdLLc##C(i	D#''	"D55i@AdCGG$I&		{{3t{{F35AII!''RR	At{{))33	4IIc	Asww	%%c*	D55i@AGOOA##GB	$:;{{166"!{{166"!vve}Qa!%%c*	I&<<?:t{{00::YAGGYcFXFXY
$S"q
74c2qww7
72X)))44 $CHH92#((22X)))44#38800dsd,#hhsC !Q
5!Q!5
5(YYq\rvv
YYq\!''!*w9
9"&&9
9
a	1WX
YYrR   c                2   g }d }|D ]  }t        |t        j                  t        j                  t        j                  f      rJ|j                  | j                  |             || j                  |      }p|| j                  |      u rJ |j                  |        t        |j                  | j                  z        | j                  z   }|j                  |      5  t        
| 8  |i |}d d d        t        t              rg }|D ]  }	t        |	t        j                        r|	j                   j"                  dk(  s*t        |	| j$                  j&                  j(                        r| j+                  |	      }	|j                  |	        t        |      S t        |t        j                        r|j                   j"                  dk(  s*t        || j$                  j&                  j(                        r| j+                  |      S |S # 1 sw Y   xY w)Nrj  )rj   r]   r  r  r   r   rQ  rM  r0  rG  r@  rA  	extraprecr
  __call__rb  rZ   ra   r?  ro  rp  rn  )r   rl   rm   mp_argsra  r  rA  rn   lstr  r  s             rP   r|  zvectorize_with_mpmath.__call__Q  s   GG 	A

BKK1C1CD	Et{{1~&?$$Q''D,,Q//
//q W\\D$>$>>?$//QJ			:	& 4w3F3f4 &% c !2::&177<<3+>!T[[//99:kk!n!

1	
 3Z	FBJJ	'FLL,=,=,Dfdkk00::;[[  M!4 4s   !HH)r   r   r   rw  r   rl  r   rK  rD  rr  rt  r   rM  rQ  rn  r|  r  )rZ  r   r   r  s   000@rP   r4  r4    s     k;P\gs  AN  O+?+E+E+GHH41a!Q$H* 	, 	,&"V\6+ZZ q Is   A4r4  c                      e Zd ZdZg dZ edddddddd	d
	      Zd dZd Zd Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)!numpy_with_mpmathzNamespace of universal functions on numpy arrays that use mpmath
  backend for evaluation and return numpy arrays as outputs.
  )r  absolutesqrtrg  expm1exp2loglog1plog10log2sincostanarcsinarccosarctansinhcoshtanharcsinharccosharctanhsquarepositivenegative	conjugaterx  sincrq  absminlnasinacosatanasinhacoshatanh)	r  r  r  r  r  r  r  r  r  c                    || _         | j                  D ]V  }| j                  j                  ||      }t	        | |      rt        | |      }n|fd}t        | |t        ||||             X y )Nc                :     t        | j                  |      |       S rT   )r  ra  )r{   mp_names     rP   opz&numpy_with_mpmath.__init__.<locals>.op  s    ,G,Q/
/rR   )r?  r@  rA  )r?  	_provides	_mp_namesr`   rF  r  setattrr4  )r   r?  r@  rA  r   r  r  s          rP   r   znumpy_with_mpmath.__init__  sz    DK 
H""4.g	t	T4  " 	0 dD/6Yn  |F  G  H
HrR   c                    ||z  S rT   r   r  s     rP   r  znumpy_with_mpmath.square  s    q5LrR   c                    |S rT   r   r  s     rP   r  znumpy_with_mpmath.positive  s    HrR   c                    | S rT   r   r  s     rP   r  znumpy_with_mpmath.negative  s	    2IrR   c                   |j                   }t        ||j                        rV|j                  |j                        r;|j                  |j                  j                  |j                  j                  f      S |j                  |      S rT   )	ra  rj   rk  rv  r`  rb  rD  r_  r  r   r{   rI  s      rP   r  znumpy_with_mpmath.sqrt  s]    
))C!SWW 
166	||SWW]]AFFLL9::88A;rR   c                8    |j                   j                  |      S rT   )ra  r  r  s     rP   r  znumpy_with_mpmath.expm1  s    99??1rR   c                   |j                   }t        ||j                        r|j                  |j                        ry|j                  |j
                        r]|j                  }|j                  dkD  rC|j
                  dkD  r4|j                  |j                  j                  |dz  j                  f      S |j                  dkD  rD|j
                  dk  r5|j                  |j                  j                  | dz  j                  f      S |j                  dk  rG|j
                  dk  r8|j                  |j                   j                  d|z  dz  j                  f      S |j                  dk  rG|j
                  dkD  r8|j                  |j                   j                  d|z  dz  j                  f      S |j                  |      S )Nr      r  )
ra  rj   rk  rv  rC  r`  pirb  r_  r  )r   r{   rI  r  s       rP   r  znumpy_with_mpmath.log1p  sG   
))C!SWW 
166	syy0VV66A:!&&1*qvv||b1f^^<=
=66A:!&&1*qvv||rcAg__=>
>66A:!&&1*b10C0CDE
E66A:!&&1*R!0B0BCD
D99Q<rR   c                   |j                   }t        ||j                        rH|j                  |j                        r|j                  |j
                        s|j                  |j
                        r|j                  dkD  r;|j                  |j                  j                  |j                  j                  f      S |j                  |j                  j                  |j                   j                  f      S |j                  |j
                        rV|j                  |j                        r;|j                  |j                  j                  |j                  j                  f      S |j                  |      S r~   )ra  rj   rk  rv  r`  rC  r[  rb  rs  r_  oner  r  r  s      rP   r  znumpy_with_mpmath.tan  s    
))C!SWW 
166			!&& 1S\\!&&5I66A:sxx~~sww}}=>
>||SXX^^swwh-=-=>??	166	s||AFF3||SWW]]CGGMM:;;771:rR   c                   |j                   }t        ||j                        rH|j                  |j                        r|j                  |j
                        s|j                  |j
                        r|j                  dkD  r;|j                  |j                  j                  |j                  j                  f      S |j                  |j                  j                  |j                   j                  f      S |j                  |j
                        rV|j                  |j                        r;|j                  |j                  j                  |j                  j                  f      S |j                  |      S r~   )ra  rj   rk  rv  r`  rC  r[  rb  rs  r_  r  r  r  r  s      rP   r  znumpy_with_mpmath.tanh  s    
))C!SWW 
166			!&& 1S\\!&&5I66A:sxx~~sww}}=>
>||SXX^^swwh-=-=>??	166	s||AFF3||SWW]]CGGMM:;;88A;rR   c                f    |j                   j                  |      |j                   j                  z  S rT   )ra  r  ln2r  s     rP   r  znumpy_with_mpmath.log2  s!    99<<?QYY]]**rR   c                f    |j                   j                  |      |j                   j                  z  S rT   )ra  r  ln10r  s     rP   r  znumpy_with_mpmath.log10  s!    99<<?QYY^^++rR   c                f    |j                   j                  ||j                   j                  z        S rT   )ra  rg  r  r  s     rP   r  znumpy_with_mpmath.exp2  s"    99==QYY]]*++rR   c                   |j                   }t        ||j                        r;|j                  }|j                  }|j
                  }|j                  |j                        rs|j                  dk  rdnd}||z  |j                  |j                        rdndz  }|j                  dk  r| n|}|j                  |j                  |j                  f      S |j                  |j                        r1|j                  |j                  |j                  j                  f      S |j                  dkD  r.|j                  dk(  r|j                  |      j                         S |j                  |      S Nr   r   r   r  r%  )ra  rj   rk  r  rD  rs  rv  rC  r`  rb  r_  r  r  )	r   r{   rI  r  rD  rs  	sign_realrC  r`  s	            rP   r  znumpy_with_mpmath.arcsin  s   
))C!SWW
 66bGGcXXd	166	&&1*B!	2~cii&7Q?vvzts||TZZ45599QVV||TZZ677 
!!xx{$$&&88A;rR   c                (   |j                   }t        ||j                        r_|j                  }|j                  }|j
                  }|j                  |j                        rx|j                  |j                        r|j                  dkD  r|dz  nd|z  dz  }n|dz  }|j                  dk  r|n| }|j                  |j                  |j                  f      S |j                  |j                        r]|j                  }|j                  dk  rdnd}|j                  dkD  r|n|}|j                  |j                  | |z  j                  f      S |j                  dk(  r!|j                  dkD  r|j                  |       S |j                  |      S )Nr   r  r  r%  r   r   )ra  rj   rk  r  rD  rs  rv  r`  rC  rb  r_  r  )	r   r{   rI  r  rD  rs  rC  r`  	sign_imags	            rP   r  znumpy_with_mpmath.arccos  s@   
))C!SWW
 66bGGcXXd	166	99QVV66A:a1r6A:$a$ffqjssd||TZZ45599QVVgg&&1*B!	vvztr||TZZ9*s*:)A)ABCC
 
1!|88A;rR   c                   |j                   }t        ||j                        r<|j                  }|j                  }|j
                  }|j                  |j                        rs|j                  dk  rdnd}|j                  dk  r| n|}||z  |j                  |j                        rdndz  }|j                  |j                  |j                  f      S |j                  |j                        r1|j                  |j                  j                  |j                  f      S |j                  dk(  r/|j                  dk  r |j                  |       j                         S |j                  |      S r  )ra  rj   rk  r  rD  rs  rv  r`  rC  rb  r_  r  r  )	r   r{   rI  r  rD  rs  r  rC  r`  s	            rP   r  znumpy_with_mpmath.arcsinh#  s   
))C!SWW
 66bGGcXXd	166	&&1*B!	vvzts2~cii&7Q?||TZZ45599QVV||QVV\\4::677 
1"1((**99Q<rR   c                   |j                   }t        ||j                        r#|j                  }|j                  }|j
                  }|j                  |j                        r|j                  dk  rdnd}|j                  |j                        r|j                  dk  rdnd|z  |z  dz  n|j                  dk  r||z  n|}|j                  |j                  |j                  f      S |j                  |j                        rB|j                  dk  rdnd}||z  dz  }|j                  |j                  |j                  f      S |j                  |      S )Nr   r   r   r  r  r%  )ra  rj   rk  r  rD  rs  rv  rC  r`  rb  r_  r  )r   r{   rI  r  rD  rs  r  r`  s           rP   r  znumpy_with_mpmath.arccosh>  s   
))C!SWW 66bGGcXXd	166	&&1*B!	 YYqvv 
1Y
.
3a
7"#&&1*	B$ 	
 ||SYY

34499QVV&&1*B!	2~!||SYY

34499Q<rR   c                H   |j                   }t        ||j                        r|j                  }|j                  }|j                  |j                        s|j                  |j                        rd|j                  dk  r+|j                  | dz  j                  |j                  f      S |j                  |dz  j                  |j                  f      S |j                  dk(  r/|j                  dk  r |j                  |       j                         S |j                  |      S )Nr   r%  r   )ra  rj   rk  r  rs  rv  rC  r`  rb  r_  r  r  r   r{   rI  r  rs  s        rP   r  znumpy_with_mpmath.arctanU  s    
))C!SWW
 66bXXd	166	cii/66A:a

;<
<||b1f^^TZZ899 
1"!''))88A;rR   c                F   |j                   }t        ||j                        r|j                  }|j                  }|j                  |j                        s|j                  |j                        rd|j                  dk  r+|j                  |j                  | dz  j                  f      S |j                  |j                  |dz  j                  f      S |j                  dk(  r.|j                  dkD  r|j                  |      j                         S |j                  |      S )Nr   r%  r   )ra  rj   rk  r  rs  rv  rC  r`  rb  r_  r  r  r  s        rP   r  znumpy_with_mpmath.arctanhl  s    
))C!SWW
 66bXXd	166	cii/66A:tzzRC!G??;<
<||TZZ"q&899
 
1!yy|%%''99Q<rR   c                   d }|j                   }t        |      }t        ||j                        r ||||j                  |j                  |j                        \  }} ||||j
                  |j
                  |j
                        \  }	}
|j                  |j                  |	j                  f      |j                  |j                  |
j                  f      fS t        ||j                        r ||||||      S J )zhNormalize reference and value using precision defined by the
    difference of exact and reference.
    c           
     "   |j                   \  }}}}|j                   \  }	}
}}|j                   \  }}}}|j                   \  }}}}| j                  |      r"| j                  |      r| j                  |      s||fS t        ||||      }|||z
  z  }|
||z
  z  }|||z
  z  }|||z
  z  }|rt        |      dd  nd}|rt        |      dd  nd}|rt        |      dd  nd}|rt        |      dd  nd}t	        t        |      t        |      t        |      t        |            }d|t        |      z
  z  |z   }d|t        |      z
  z  |z   }d}t        ||      D ]  \  } }!| |!k7  r n|dz  } ||z
  }"||"z	  }#||"z	  }$|#r+| j                  ||#| t        t        |#            dz
  f      n|r| j                   n| j                  }%|$r+| j                  ||$| t        t        |$            dz
  f      n|r| j                   n| j                  }&|%|&fS )Nr%  r<   0r   r   )	r_  r[  r  binr   r.  r  rU  rs  )'rI  rO   r  r  r   sssmsesbcesemeeebcrsrmr,  rbcvsvmvevbcmesm_eem_erm_evm_esm_bem_brm_bvm_br  c1b0b1c0rm_mvm_mnrnvs'                                          rP   workerz+numpy_with_mpmath.normalize.<locals>.worker  s%   ob"b#ob"b#ob"b#ob"b#ll1o#,,q/cll1o!tr2r2b BG_dBG_dBG_dBG_d #SYqr]d"SYqr]d"SYqr]d"SYqr]d
c$iTCIs4y
9aAD	M"T)dAD	M"T)dbdO &"b8

a r6b RZdRZd AE3<<TB3CI(:;<XZCHH9`c`h`hb@D3<<TB3CI(:;<XZCHH9`c`h`hbVmrR   )	ra  r  rj   rk  rC  r`  rb  r_  rm  )r   exact	referencer   r  rI  r  rrrvirivs              rP   rq  znumpy_with_mpmath.normalize  s    *X --CJE%!c5%**innejjIfb"c5%**innejjIfb"\\288RXX./rxx>R1SSS	E377	#Cy%88QrR   N)r   r   )r   r   r   rw  r  r   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rq  r   rR   rP   r  r  r  s    ) 8&Wg	)H&$+,,6B6..,9rR   r  c                   	 ddl }g }t        |j                  d      r%|j                  |j                  j                         |j                  j                  dddd| d|       |j                  j                  d|j                  j                  d      dd	|j                  j                  |j                  j                  |j                  j                  |j                  j                  |j                  j                   |j                  j"                  f
       t$        j&                  }t)        j*                  d|       |j                  j                  |       y# t        t        f$ r Y yw xY w)a_  Sets up the hypothesis profiles.

  Sets up the hypothesis testing profiles, and selects the one specified by
  the ``JAX_HYPOTHESIS_PROFILE`` environment variable (or the
  ``--jax_hypothesis_profile`` configuration.

  Args:
    max_examples: the maximum number of hypothesis examples to try, when using
      the default "deterministic" profile.
  r   Ndiffering_executorsrJ   T)databasederandomizedeadlinemax_examples
print_blobsuppress_health_checkinteractiver   F)parentr  report_multiple_bugs	verbosityphaseszUsing hypothesis profile: %s)
hypothesisModuleNotFoundErrorr  rF  HealthCheckr   r  settingsregister_profileload_profile	Verbosityr+  Phaseexplicitreusegeneraterg  explainHYPOTHESIS_PROFILEr   logginginfo)r  hpsuppressed_checksprofiles       rP   setup_hypothesisr    s2     R^^23R^^??@++-   ++[[%%o6 $$ ((


((..
((


((//
((

   $$'	,,-w7++7#[ {	+ 
s   E E0/E0)rO   r   r   r   )rZ   r   r   r0  )rc   r   r   z
np.ndarrayrs  )rp   zCallable[..., Any]rq   rk   )r{   r   r   rk   )r   "int | float | ToleranceDict | Noner   r1   )r   r  r   r  r   r1   )r<   )r   r   r   r   r   r   r   r~  )r   r   r   z(Generator[Callable[[], str], None, None])r   z<Generator[Sequence[tuple[core.ClosedJaxpr, mlir.ir.Module]]])r   tuple[int, ...])r1  r0  r2  r0  r3  r0  )r9  r0  r:  r0  )rC  r   )r   r0  )r   r0  r   rk   )Nr<   )r   z
int | NonerQ  r   r   rk   )re  r   r   rk   )r|  zIterable[str]r   rk   )r  r0  )r  r   )r  r   )F)r  )g      $@)g        r  r  rT   )r  MeshSpecr   zGenerator[None, None, None])NF)FN)r   r   r   r  )rm   zSequence[dict[str, Any]]r  z&Callable[[dict[str, Any]], str] | Noner  z
str | None)r  N)   r}  )
__future__r   r   collections.abcr   r   r   r   
contextlibr   r	   r)  rt   r
   r  r
  r
  r   r   r,  r  r   rM  	threadingtypingr   r   r  r  absl.testingr   r   r   jax._srcr   r   r   r   r   r   r   rU   r   r   r   r   jax._src.typingr   r   r   r   r   r  jax._src.cloud_tpu_initr    jax._src.interpretersr!   jax._src.lib.mlir.dialectsr"   jax._src.numpy.utilr#   r$   jax._src.public_test_utilr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   jax._src.test_loaderr2   r3   r4   r5   jax._src.utilr6   jax.tree_utilr7   r8   r9   r:   numpyr]   numpy.randomr  r  string_flagr   int_flagr0  getenvr  r  	bool_flagbool_envSKIP_SLOW_TESTSr  r	  rO  rM   rQ   r[   rd   rv   r|   r   r   r   r   stdoutcapture_stdoutstderrcapture_stderrlocalr   r   r   test_event_listenerr   count_device_putcount_device_put_fast_path_hitcount_pjit_cpp_cache_misscount_jit_tracing_cache_misscount_aot_jit_cpp_cache_missr    count_jit_compilation_cache_misscount_jax_array_shard_arg_callsr   r   r   r   r   r   r   r   r  r   r$  r&  r6  r<  rE  rK  rM  rS  ri  rn  rp  rz  r  __test__r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  	lru_cacher  r  r  r  r"  r'  r*  r.  r0  r5  r<  rL  rQ  rT  rX  r^  re  rt  rx  r  r  r  r  r  r  r  cacher  r  r  r  r  r  r  r  r  r  TestCaser  rm  _PJIT_IMPLEMENTATION_name_NOOP_JIT_IMPLEMENTATIONJIT_IMPLEMENTATIONr  r  r  rb  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r2  	vectorizer4  r  r  r   rR   rP   <module>rB     s    #  C C 0       	  	 
       & 
   &   !  & #  & 0   % ; & * Fn n n n J U ? E   J J   FBP	 &fooibii)401*, 
 .fooibii0%89$  #&""FOO)51	/ *:)9)90FOO@%H
K*L & (V''BII&8'  "**56%?	I.2
,
,1>+
 #( #(L #**5#**5	'IOO 	' +,  F *    45 !-.B!C (6 +,?@ +,BC +,CD #/0I#J  "./A"B  C C 6 6 8 8 5 5 4 4 
 
>0==!?&
)	@ 	@
	  %  KF*!II I &; % &K &!^ #o 	!!$2 R ! !! +-; E6,6=
<
5>
43	@<:B"27<#
2(A4 . ."J"		 	  	    
  (kA-(( kAZ ww "  7 !'    
%[ % #11 c3h 

 

O!		H
 
I) I)X 
/ CD6'
 =A!%9F$9F99F 9Fv I I L L@F>B[BLL [|I IX
:$rR   