
    Vpf              	         d Z ddlmZ ddlmZm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ZeZ G d dej                  Zddddddej        ddddZd Zdddej        ddddZdS )zESee primitives_test docstring for how the Jax2TfLimitations are used.    )annotations)CallableSequenceN)Any)lax)numpy)configdtypes)	test_util)test_harnessesc                  |    e Zd ZdZdZdZddddedddd	d	d

dh fdZdidZ	 	 	 djdk fd!Ze	dld$            Z
h d%Ze	d&             Ze	dmd(            Ze	dmd)            Ze	dmd*            Ze	dnd+            Ze	dnd,            Ze	dnd-            Ze	dnd.            Ze	dnd/            Ze	dnd0            Ze	dnd1            Ze	dnd2            Ze	dnd3            Ze	dnd4            Ze	dnd5            Ze	dnd6            Ze	dnd7            Ze	dnd8            Ze	d9             Ze	d:             Ze	d;             Z e	dnd<            Z!e	dnd=            Z"e	dnd>            Z#e	dnd?            Z$e	dnd@            Z%e	dndA            Z&e	dndB            Z'e	dndC            Z(e	dndD            Z)e	dndE            Z*e	dF             Z+e	dndG            Z,e	dndH            Z-e	dndI            Z.e	dndJ            Z/e	dndK            Z0e	dndL            Z1e	dndM            Z2e	dndN            Z3e	dndO            Z4e	dndP            Z5e	dndQ            Z6e	dndR            Z7e	dndS            Z8e	dndT            Z9e	dndU            Z:e	dndV            Z;e	dndW            Z<e	dndX            Z=e	dndY            Z>e	dndZ            Z?e	d[             Z@e	d\             ZAe	d]             ZBe	d^             ZCe	d_             ZDe	d`             ZEe	dnda            ZFe	dndb            ZGe	dc             ZHe	dd             ZIe	de             ZJe	dndf            ZKe	dndg            ZL xZMS )oJax2TfLimitationzeSpecific primitive limitations for jax2tf.

  See the primitive_test module docstring for details.
        cpugputpu TeagergraphcompiledFN)
devicesr   enabledmodesnative_serializationskip_tf_runexpect_tf_errorskip_comparisoncustom_asserttoldescriptionstrr   str | Sequence[str]r   Sequence[DType]r   boolr    r"   Callable | Nonec       
        *   t                                          ||||           t          |t                    r|f}t	          d |D                       s
J d            || _        || _        || _        || _        |
| _	        || _
        |	| _        dS )a6  See the test_harnesses.Limitation common arguments.

    Args :
      modes: one of "eager", "graph", "compiled"
      for_native_serialization: A bitmask with some of {FOR_NATIVE, FOR_NON_NATIVE}
        to specify how the limitation applies to native and non-native lowering.
      skip_tf_run: if set will skip the TF execution. Use this sparingly,
        prefer `expect_tf_error`. Use only when the test cannot recover from
        the TF error.
      expect_tf_error: if set, then expect a TF error in the given mode when
        executing the result of jax2tf conversion. If not set, then the
        limitation must have a custom_assert or non-default tol.
      skip_comparison: skips the numeric comparison.
      tol: a tolerance to use for both atol and rtol. We will use the maximum
        tolerance over all the applicable limitations, irrespective of their
        order.
      custom_assert: if given, then execute as
        `custom_assert(tst, result_jax, result_tf, args=args, tol=tol, err_msg)`
        , where `tst` is the current TestCase instance, and args are the input
        arguments that the harness created. The `tol` is the maximum tolerance
        based on the applicable limitations. `err_msg` is passed to NumPy
        assert methods.
        `result_tf` is already converted to NumPy arrays.
    )r   r   r   c              3     K   | ]}|d v V  	dS )r   Nr   ).0ms     p/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/experimental/jax2tf/tests/jax2tf_limitations.py	<genexpr>z,Jax2TfLimitation.__init__.<locals>.<genexpr>W   s(      BBqq22BBBBBB    zInvalid modes: {modes}N)super__init__
isinstancer%   allr   r   r    r   r"   r#   r!   )selfr$   r   r   r   r   r   r   r    r!   r"   r#   	__class__s               r.   r2   zJax2TfLimitation.__init__,   s    N 
GGWVW  F F F% heBBEBBBBB\\D\\\\DJ 4D*D"D&DDH*Dr0   limitationsSequence[Jax2TfLimitation]returnJax2TfLimitation | Nonec                J    d}|D ]}|j         ||j         |j         k    r|}|S )zEPick the tolerance limitation that establishes the maximum tolerance.Nr#   )r5   r7   max_tol_limls       r.   get_max_tolerance_limitationz-Jax2TfLimitation.get_max_tolerance_limitation`   s@     K  	
	!%+/"9"9+r0   dtypeDType | Nonedevice
str | Nonemodec                    t           j        j        rt          j        nt          j        }|du s	|| j        v o,| j        |z  o"t                      	                    ||          S )zCChecks if this limitation is enabled for dtype and device and mode.N)rB   r@   )
r	   #jax2tf_default_native_serializationvaluer   
FOR_NATIVEFOR_NON_NATIVEr   r   r1   filter)r5   r@   rB   rD   native_serialization_maskr6   s        r.   rJ   zJax2TfLimitation.filtero   sn     5;	-##,  T\/TTZ/ 7&)BB7GGNN&N668r0   harnesstest_harnesses.Harnessc                    t          | |j        d           }|j        | j        v r|J d|j         d            g S |J d|j         d             ||          }t          |t          t
          f          sJ |S )NzHarness group 'zy' is both in 'harness_groups_no_limitations' and has a custom Jax2TfLimitation.classmethod defined (see module docstring)z' must be either part of 'harness_groups_no_limitations' or must have a custom Jax2TfLimitation.classmethod defined (see module docstring))getattr
group_nameharness_groups_no_limitationsr3   listtuple)clsrL   group_methodr7   s       r.   limitations_for_harnessz(Jax2TfLimitation.limitations_for_harness}   s     3 2D99LS>>>!!IG. I I I "!! i%%IG. I I I &%% !L))kdE]33333r0   >K   eqgegtleltneorabsaddandcosexplogmulnegnotpadrevsinsubxorceilconjcoshimagiotarealsignsinhsqrtatan2clampfloorrsqrtslicecummaxcummingatherreducetie_inadd_anycomplexreshapesqueezelogisticselect_n	broadcast	is_finite	reduce_or	transpose
device_put
reduce_and
reduce_sum
shift_left
zeros_likeconcatenatereduce_proddynamic_slicestop_gradientrandom_randintrandom_uniformiota_2x32_shapebroadcast_in_dimpopulation_countreduce_precisionreduce_window_maxreduce_window_minreduce_window_mulrandom_categoricalshift_right_logicalbitcast_convert_typeconvert_element_typedynamic_update_sliceselect_and_scatter_addshift_right_arithmeticc                ^    fd}t          dt          j        t          j        g|          S )Nc               V    |\  }|                      | |          |||           d S )Natolrtolerr_msgassertAllClose)tst
result_jax	result_tfargsr#   r   operand
np_inverses          r.   r"   zIJax2TfLimitation.helper_get_trig_custom_limitation.<locals>.custom_assert   sK    hg	
::i((sg  O O O O Or0   z.May return different but still correct results)r$   r   r"   custom_numericnp	complex64
complex128)rT   r   r"   s    ` r.   !helper_get_trig_custom_limitationz2Jax2TfLimitation.helper_get_trig_custom_limitation   sL    O O O O O
 Dbm,#% % % %r0   handessc                     t                      gS Ncustom_random_keys_outputrT   r   s     r.   random_seedzJax2TfLimitation.random_seed       %''((r0   c                     t                      gS r   r   r   s     r.   random_splitzJax2TfLimitation.random_split   r   r0   c                     t                      gS r   r   r   s     r.   random_fold_inzJax2TfLimitation.random_fold_in   r   r0   c           	         t          t          j        gddd          t          t          j        gddd          t          t          j        gdddt          j                  gS )	Nr   r   -C6?r   r   r   r#   r   vIh%<=r   MbP?)r   r   r#   r   r   )r   r   r   r   r   rI   rT   rL   s     r.   acoszJax2TfLimitation.acos   s     	L>"0		2 	2 	2
 	M?"0		2 	2 	2
 	L>0!1!@	B 	B 	B r0   c                   t          t          j        gdd          t          t          j        gdd          t	          dt          j        t          j        gdddd	t          j        
          |                     t          j                  gS )Nr   r   r   r   r#   r   -q=z|TF2XLA impl for Acosh doesn't properly handle large complex types, native serialization more closely matches numpy numerics.r   FT)r   r   r   r    r!   r   )r   r   r   r   r   rI   r   rn   r   s     r.   acoshzJax2TfLimitation.acosh   s     	r|n6K	! 	! 	!r}o~5QQQIL"-0)! !1!@		
 		
 		
 	--bg66 r0   c           	        t          j                    d }t          fdt          j        t
          j        t
          j        t
          j        fD             dd          t          dt
          j        gdd          t          fdt          j        t
          j        t
          j        t
          j        fD             dd	|
          gS )Nc                   ~~|\  }}|\  }}	|\  fd}
|                       |
|          |           |                       |
|	          |           d S )Nc                    j         dk    r|          S j         dk    r:t          j        j        d                                       d          | f         S J )Nr   r   r   )r   )ndimr   arangeshaper   )indicesr   s    r.   operand_valueszLJax2TfLimitation.approx_top_k.<locals>.custom_assert.<locals>.operand_values   s\    <1!
!\Q7=#344<<WEEwNO
O
,r0   r   )r   r   r   r   r#   r   
jax_valuesjax_indices	tf_values
tf_indicesr   r   s              @r.   r"   z4Jax2TfLimitation.approx_top_k.<locals>.custom_assert   s    
w *j+'ihg     
44jAAA	
33Y?????r0   c                    g | ]}|v |	S r   r   r,   tsupported_dtypess     r.   
<listcomp>z1Jax2TfLimitation.approx_top_k.<locals>.<listcomp>   .     . . .!,,, ,,,r0   r   )r   r   r   r   r   z&compilation not supported for float64.r   c                    g | ]}|v |	S r   r   r   s     r.   r   z1Jax2TfLimitation.approx_top_k.<locals>.<listcomp>  r   r0   r   r   )r   r   r   r"   )jtur   missing_tf_kerneljnpbfloat16r   float16float32float64r   r   )rT   rL   r"   r   s      @r.   approx_top_kzJax2TfLimitation.approx_top_k   s    +--@ @ @" 	. . . .bj"*bjQ . . ."$		& 	& 	&
 	4J<"		! 	! 	!
 	. . . .bj"*bjQ . . ."$'	) 	) 	)* *r0   c           
     x    t          dt          j        j        ddddd|j        v o|j        d                    gS )	NzBdifferent results when the input contains NaN and enable_xla=Falser   r   FTnan_
enable_xlar   r   r   r    r!   r   )r   r   r   all_inexactnameparamsr   s     r.   argmaxzJax2TfLimitation.argmax	  sS     	P:))0! w|+PGN<4P0P	S 	S 	S	 	r0   c                ,    |                      |          S r   )r   r   s     r.   argminzJax2TfLimitation.argmin  s    ::gr0   c                    t          t          j        gddd          t          t          j        gddd          t          t          j        gddd          |                     t          j                  gS )Nr   r   r   r   )r   r   g-C6*?r   )r   r   r   r   r   ri   r   s     r.   asinzJax2TfLimitation.asin  s~     	r|nn$;	= 	= 	=r|nn$;	= 	= 	=r}o~5;	= 	= 	=--bf55 r0   c                   t          t          j        gdd          t          t          j        gdd          t          t          j        t          j        gdddt          j                  t          t          j        gdd	d
t          j        t          j        z            |                     t          j                  gS )Nr   r   r   r   r   r   r   r   r   r#   r   r   )r   r   r   r   )	r   r   r   r   r   rI   rH   r   rs   r   s     r.   asinhzJax2TfLimitation.asinh&  s     	r|n6K	! 	! 	!r}o~5QQQr|R];4*,<,K		M 	M 	M
 	r}ox; ,<,GJZJi,i	k 	k 	k 	--bg66 r0   c                    t          t          j        gdd          t          t          j        gdd          t          t          j        gdd          |                     t          j                  gS )Nr   h㈵>r   r   r   r   )r   r   r   r   r   tanr   s     r.   atanzJax2TfLimitation.atan8  sc     	r|nn$OOOr|nu4HHHr}o~5QQQ--bf55	 r0   c                    t          t          j        gd          t          t          j        gd          t          t          j        gdd          |                     t          j                  gS )N+=r   r#   r   r   r   r   )r   r   r   r   r   r   tanhr   s     r.   atanhzJax2TfLimitation.atanhA  s_     	rzl666r|n$777r}o~5QQQ--bg66	 r0   c                >    t          t          j        gdd          gS Nr   r   r   r   r   r   r   s     r.   
bessel_i0ezJax2TfLimitation.bessel_i0eJ  .     	O$"$	& 	& 	& r0   c                ,    |                      |          S r   )r
  r   s     r.   
bessel_i1ezJax2TfLimitation.bessel_i1eS      >>'"""r0   c                >    t          t          j        gdd          gS )Nr   r   r   )r   r   r   r   s     r.   cbrtzJax2TfLimitation.cbrtW  s$     	rzlUFFF r0   c           
     n   d }t          t          j        t          j        gddd          t          t          j        t          j        gddd          t          t          j        t          j        gddd          t          t          j        gdd	dt          j
        
          t          |dd          gS )Nc               \    |                      t          j        |          |||           d S )Nr   r   )r   r   tril)r   r   r   r#   r   _s         r.   r"   z0Jax2TfLimitation.cholesky.<locals>.custom_assert`  sC     

(:

	W  F F F F Fr0   {Gz?r   r   )r   r#   r   r   gư>g?-C6
?r   )r   r#   r   r   r   zMay return different values in the strictly upper triangular part of the result. This does not matter for correctness, because this part of the matrix is not considered in the result.r"   r$   r   )r   r   r   r   r   r   r   r   r   r   rH   rT   rL   r"   s      r.   choleskyzJax2TfLimitation.cholesky]  s    F F F 	J-"0		2 	2 	2
 	J."0		2 	2 	2
 	ORZ0"0		2 	2 	2
 	O$0!1!<	> 	> 	> 	'S 1	2 	2 	21   r0   c                   |j         d         }t          dt          j        t          j        t          j        gg dd|d uo/|t          j        t          j        t          j	        t          j
        fv d          t          t          j	        gddd	          t          t          j	        gd
ddt          j        t          j        z            t          dd|j         d          d          gS )Npreferred_element_typezJNon-deterministic NaN for conv_general_dilated with preferred_element_typer   r   Tr   r   r   r   r!   r   r   r   r   r   r#   r   r   r   z1higher numeric inaccuracy when `enable_xla=False`r   {Gzt?)r$   r   r   r#   )r   r   r   int32r   int16int64r   r   r   r   r   rH   rI   rT   rL   prefer_elems      r.   conv_general_dilatedz%Jax2TfLimitation.conv_general_dilated  s    .!9:K
VIrx (''.d* Y"s|RZRZ&XX		  		  		  	rzlE;	! 	! 	! 	rzlE;,<,GJZJi,i	k 	k 	k 	#V;$+N<$@ @	! 	! 	!) r0   c                l    t          t          j        t          j        t          j        fddd          gS Nr   r         ?r  )r   r   r   r   r   r   r   s     r.   cumlogsumexpzJax2TfLimitation.cumlogsumexp  s9     	Jbj9)0		
 	
 	
 r0   c                V    t          t          j        t          j        fddd          gS r'  r   r   r   r   r   r   s     r.   cumprodzJax2TfLimitation.cumprod  5     	J-)0		
 	
 	
 r0   c                V    t          t          j        t          j        fddd          gS r'  r+  r   s     r.   cumsumzJax2TfLimitation.cumsum  r-  r0   c                    t          dt          j        gddd          t          t          j        gdd          t          d	          gS )
Nz!TODO: large numerical discrepancyr   FTr   r   r    r!   r  r   r   r<   )r   r   r   r   r   s     r.   custom_linear_solvez$Jax2TfLimitation.custom_linear_solve  sY     	/J<! 	" 	" 	" 	rzlEtDDD4   	 	r0   c                   |j         fd}t          t          j        gdd          t	          t
          j        gd          t	          t
          j        gddgd	
          t	          t          j        g|d          gS )Nc                  |\  }|dk    |dk    z  }t          j        |          }|                     t          j        |f 	t           j                            ||         |           |                     t          j        |f 	t           j                            ||         |           |                     ||          ||          |||           d S )N              r   r   )r   count_nonzeror   fullnaninf)
r   r   r   r   r#   r   argspecial_casesnr_special_casesr@   s
            r.   r"   z/Jax2TfLimitation.digamma.<locals>.custom_assert  s    dcbySCZ0m)-88	
'#%uuRV}}
5
5
]
#     

'#%uuRV}}
5
5
M
"    
 

m^
$
]N
#      r0   r   r   r   r   r  r   r   r   r   z^May return different results at singularity points 0 and -1.JAX returns nan and TF returns infr   r"   r$   )r@   r   r   r   r   r   r   r   rT   rL   r"   r@   s      @r.   digammazJax2TfLimitation.digamma  s    ME    , 	O$"$	& 	& 	& 	rzl666rzlUENMMMO$'5		7 	7 	7 r0   c                    t          dt          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j	        g	d|j
        v           gS )N@TF integer division fails if divisor contains 0; JAX returns NaNsingularity)r   r   )r   r   uint8int8uint16uint32uint64r!  r   r"  r   r   s     r.   divzJax2TfLimitation.div  sZ     	N"'29biBG"(BH
 #gl2	5 	5 	5	 	r0   c                   |j         d         }t          t          j        g          t	          dt
          j        t          j        t          j        t          j	        gdd|d ud          t	          dg d	|o.t          j
        |j
                  t          j
        |          k     d
          t	          dg d	|j
        |j         d         k    oY|j
        t          j        t          j        t          j        fv p/|j         d         t          j        t          j        t          j        fv d
          t	          dg d	|j         d          o|j
        t          j        t          j        t          j        fv p|j         d         t          j        t          j        t          j        fv pq|j
        |j         d         ft          j        t
          j        ft          j        t          j        ft          j        t          j        ft          j        t          j        ffv dd          t	          ddg|j
        |j         d         k    oC|j
        t          j	        t          j        fv p$|j         d         t          j	        t          j        fv dd          t+          t          j        gdgdd          t+          t          j        gdgdd|j         d         o|j
        |j         d         k              gS )Nr  r
   zVNon-deterministic NaN for dot_general with preferred_element_type on GPU (b/189287598)r   r   Tr  zPLarge tolerances when upcasting with preferred_element_type on CPU (b/241740367)r   )r   r   r!   zQErrors when lhs_dtype != rhs_dtype for non-native serialization with 64-bit types	rhs_dtypez^Errors for non-native serialization with enable_xla=False for certain input dtype combinationsr   )r   r   r!   r   zYCrash when lhs_dtype != rhs_dtype for non-native serialization on TPU for complex numbersr   r   r  r   )r   r   r#   r   r   )r   r   r   bool_r   r   r   r   r   r   r@   r"  rI  r   r!  rH  rG  r   rF  rE  r   r   r#  s      r.   dot_generalzJax2TfLimitation.dot_general
  s   .!9:K"(---dbj"*bl 0 , 	" 	" 	" 	^)))SBHW]$;$;bh{>S>S$S 		" 	" 	" 	_)))]gn[&AA Xm")RZ'HH Wn[1bh	2:5VV 	" 	" 	" h%%%^L11 
-BHbi#CC 	.-"(BIry1QQ	 ='."=>Z.Xrz*Wbj)Wbh'	C    " 	gG]gn[&AA Tmbm'DD Sn[1blBM5RR 	 	 	 	rzlUG;	= 	= 	= 	rxj5't; '| < !M '1L L	O 	O 	Ou> >r0   c                    |j         d         |j         d         |j        fd}t          ddd          t          do	          t          |d
          gS )Ncompute_left_eigenvectorscompute_right_eigenvectorsc                   |\  }|j         d         fd fdfd} fd}|d         |d         }
}	t          j        t          t          |j         d d                    D ]H}|	|         |
|         }}t	                    D ]&} |||         |            |||         |           'Ir |||
|d                    r ||
|dz                       d S d S )	Nr   c                    t           j                            | d          }|dz   t          j                  j        z  z  S )Nr   axisr   )r   linalgnormr   finfoeps)xrY  r@   inner_dimensions     r.   rY  z9Jax2TfLimitation.eig.<locals>.custom_assert.<locals>.normY  s<    y~~ah~//!+sy/?/?/CCDDr0   c                                         t          j         t          j        | |          |dd d d f         |z  z
            dk                          d S )N.d   )
assertTruer   r4   matmul)awvrrY  r   s      r.   check_right_eigenvectorszMJax2TfLimitation.eig.<locals>.custom_assert.<locals>.check_right_eigenvectors]  sh    F44	!R((1S$\?R+??@@3FGG	I 	I 	I 	I 	Ir0   c           
        t          | j                  }t          j        |                     t          t          |dz
                      |dz
  |dz
  gz                       }t          j        |          } |||           d S )Nr   r   )lenr   r   rm   r   rR   range)rb  rc  vlrankaHwCre  s         r.   check_left_eigenvectorszLJax2TfLimitation.eig.<locals>.custom_assert.<locals>.check_left_eigenvectorsa  sw    17||Xakk$uTAX"7"74!8TAX:N"NOOPPXa[[  R,,,,,r0   c                   d }t           j        t           j        fv rd}nt           j        t           j        fv rd}t          t          || z
                      }                    |t          j        d|j	                  |           d S )Nr   r   r5  r  )
r   r   r   r   r   minr^   r   arrayr@   
eigenvalueeigenvalues_arrayr#   closest_diffr@   r   r   s       r.   check_eigenvalue_is_in_arrayzQJax2TfLimitation.eig.<locals>.custom_assert.<locals>.check_eigenvalue_is_in_arrayg  s    RZ...##rz2=111#30:=>>??HR+,,	 	 	 	 	 	 	r0   r   rU  r   r   	itertoolsproductmaprh  )r   r   r   r   r#   r   r   rm  ru  	all_w_jaxall_w_tfidxw_jaxw_tfire  r]  rY  rP  rQ  r@   s   `    `         @@@r.   r"   z+Jax2TfLimitation.eig.<locals>.custom_assertS  s   hgb)oE E E E E EI I I I I I- - - - -       'qM9Q<i"Cw}SbS/A$B$BC 7 7#nhsmt'' 	7 	7A
&
&uQx
6
6
6
&
&tAw
6
6
6
6	7 
# A9Q<@@@	# K  (!*1/H+H!I	K 	K 	K 	K 	KK Kr0   zfunction not compilabler   r   )r   r   zzTF Conversion of eig is not implemented when both compute_left_eigenvectors and compute_right_eigenvectors are set to True)r   May return the eigenvalues and eigenvectors in a potentially different order. The eigenvectors may also be different, but equally valid.r"   r$   )r   r@   r   r   )rT   rL   r"   rP  rQ  r@   s      @@@r.   eigzJax2TfLimitation.eigM  s     '/J K!(0L!MME-K -K -K -K -K -K -Kb 	%Z	H 	H 	H I.M3M	P 	P 	P 	'A	C 	C 	C r0   c                    |j         fd}t          t          j        gd|j        d         dk              t          dt          j        gddd	          t          |d
d          gS )Nc               f    |\  }|j         d         } fd} fd}	|\  }
}|\  }}t          j        t          t          |j         d d                    D ]H}||         ||         }}t	          |          D ]&} |	||         |            |	||         |           'I ||||           d S )Nr   c                n   d}t           j        k    rd}nBt           j        k    rd}n/t          j        t           j        fv rd}nt           j        k    rd}                    t          j        | |          |dd d d f         |z  z
  t          j	        | j
        |j                  |d           d S )	NgؗҜ<gh㈵>r  r   .r@   F)r   check_dtypesr   )r   r   r   r   r   r   r   r   ra  zerosr   r@   )rb  rc  rd  r#   r@   r   r   s       r.   re  zNJax2TfLimitation.eigh.<locals>.custom_assert.<locals>.check_right_eigenvectors  s     BJ##bj  ##v555##bm###IaqdAAA33HQWBH--- 	 	 	 	 	 	r0   c                4   d }t           j        t          j        t          j        fv rd}nt          j        t          j        fv rd}t          t          || z
                      }	                    |t          j
        d|j                  |           d S )Nr   r   r5  r  )r   r   r   r   r   r   r   ro  r^   r   rp  r@   rq  s       r.   ru  zRJax2TfLimitation.eigh.<locals>.custom_assert.<locals>.check_eigenvalue_is_in_array  s    V_bj",???##rz2=111#30:=>>??HR+,,	 	 	 	 	 	 	r0   rU  rv  )r   r   r   r   r#   r   r   r]  re  ru  r  rz  	all_vr_tfr{  r|  r}  r~  r  r@   s   `    `            r.   r"   z,Jax2TfLimitation.eigh.<locals>.custom_assert  s   hgb)o      (        la%i"Cw}SbS/A$B$BC 7 7#nhsmt'' 	7 	7A
&
&uQx
6
6
6
&
&tAw
6
6
6
6	7 w)<<<<<r0   r   r   )r   r   )r   r   r   zTODO: numeric discrepanciesFTr1  r  r   r  )	r@   r   r   r   r   r   r   r   r   r@  s      @r.   eighzJax2TfLimitation.eigh  s    ME.= .= .= .= .=b 	O$^G,6	
 	
 	

 	)J<! 	" 	" 	" 	'A 1	2 	2 	2 r0   c                    g S r   r   r   s     r.   erfzJax2TfLimitation.erf      Ir0   c                    g S r   r   r   s     r.   erfczJax2TfLimitation.erfc  r  r0   c                    d }t          t          j        t          j        gdd          t          t          j        t          j        gd          t          t          j        t          j        g|d          gS )	Nc               x    |\  }|dk     |dk    z  }|                      ||          ||          |||           d S )Nr6        ?r   r   )r   r   r   r   r#   r   r<  r=  s           r.   r"   z/Jax2TfLimitation.erf_inv.<locals>.custom_assert  sa    dc SyS2X.m	
m^
$
]N
#      r0   r   r   r   r   r  zrMay return different results at undefined points (< -1 or > 1): JAX returns `NaN` and TF returns `+inf` or `-inf`.r?  )r   r   r   r   r   r   r   r   r  s      r.   erf_invzJax2TfLimitation.erf_inv  s       	ORZ0"$	& 	& 	& 	rz2:6DAAAJ
+'F		H 	H 	H r0   c                <    t          t          j        gd          gS )Nr   r  )r   r   r   r   s     r.   expm1zJax2TfLimitation.expm1  s    2:,D999::r0   c                   t          ddt          j        gd          t          ddt          j        gdt	          |j        d                   dv           t          d	d
t           j                  t          dd
t           j        d          gS )NzTF function not compilablebler   r   )r   r   r   z0TF function not compilableble for IFFT and IRFFTfft_type)zFftType.IFFTzFftType.IRFFT)r   r   r   r   r   r   )r#   r   r   r   r   )r#   r   r   r   )	r   r   r   r   r%   r   r   rI   rH   r   s     r.   fftzJax2TfLimitation.fft  s     	+"J<		 	 	
 	>"M?
344 9J J	L 	L 	L 	4'E,<,K	M 	M 	M4'E,<,G'	) 	) 	)! r0   c                    d }t          t          j        t          j        gdd          t          t          j        t          j        gdd          t          t          j        t          j        g|          gS )Nc                   t          j        |          t          j        |          z   t          j        |          z   t          j        |          z   }|                     ||          ||          ||           d S )N)r   r   )r   isnanisinfr   )r   r   r   r   r#   r   masks          r.   r"   z6Jax2TfLimitation._pow_test_util.<locals>.custom_assert  s    
 (:

)!4!4
4rx
7K7K
K
(9

  

dU
Yu-C  J J J J Jr0   r   r   r   r  )r   r"   )r   r   r   r   r   r   r  s      r.   _pow_test_utilzJax2TfLimitation._pow_test_util  s    J J J 	J-~	 	 	 	J."	 	 	 	L"-0'	
 	
 	
 r0   c                    j         fd}t          t          j        t          j        gdd          t          |d          gS )Nc                  |\  }}|dk    |dk    z  }t          j        |          }	|                     t          j        |	ft           j        
          ||                    |                     t          j        |	fd
          ||                    j        t           j        k    rd}|                     ||          ||          |||           d S )Nr5  r  r   r   )r   r8  r   r9  r:  r@   r   )r   r   r   r   r#   r   arg1arg2r=  r>  r@   rL   s             r.   r"   z.Jax2TfLimitation.igamma.<locals>.custom_assert:  s    jdDrzdbj1m)-88	
'#%rvU
;
;
;
]
#% % % 

'#%r
7
7
7
M
"$ $ $ 
"*	$	$	
m^
$
]N
#      r0   r   r   r   zMay return different results at undefined points (both arguments 0). JAX returns `NaN` and TF returns 0 or JAX returns 1 and TF returns `NaN`r  )r@   r   r   r   r   r   r   r@  s    ` @r.   igammazJax2TfLimitation.igamma5  su    ME     , 	ORZ0"$	& 	& 	& 	'5	7 	7 	7 r0   c                    |j         fd}t          t          j        t          j        gdd          t          t          j        gd          t          dd	          t          |dd
          gS )Nc                  |\  }}|dk    |dk    z  }t          j        |          }	|                     t          j        |	fd
          ||         |           |                     t          j        |	ft           j        
          ||         |           |                     ||          ||          |||           d S )Nr5  r   r  r  r7  r   )r   r8  r   r9  r:  )r   r   r   r   r#   r   r  r  r=  r>  r@   s             r.   r"   z/Jax2TfLimitation.igammac.<locals>.custom_asserta  s    jdDrzdai0m)-88	
'#%r
7
7
7
]
#     

'#%rvU
;
;
;
M
"    
 

m^
$
]N
#      r0   r   r   r   g&.>r  r   r   r   r#   zMay return different results at undefined points (both arguments less or equal 0). JAX returns `NaN` and TF returns 0 or JAX returns 1 and TF returns `NaN`)r"   r   r$   )r@   r   r   r   r   r   r   r   r@  s      @r.   igammaczJax2TfLimitation.igammac\  s    ME    . 	ORZ0"$	& 	& 	& 	rzl555u$///'"5		7 	7 	7 r0   c                    |j         d         }t          dt          j        t          j        gdddd          t          dt          j        t          j        t          j        t          j	        t          j        t          j        t          j
        t          j        t          j        g	t          |          d	k    ddd
          t          t          j        gd          gt!          |                     |                    z   S )NyzDifferent overflow behavior. r   Fr   T)r   r   r    r   r!   z1Different overflow behavior for large exponents. 
   )r   r   r    r   r!   g{Gz?r  )r   r   r   r   r   r   rF  r!  r   r"  r   r   r   r^   r   r   rR   r  )rT   rL   r  s      r.   integer_powzJax2TfLimitation.integer_pow  s    sA 	+J-!$ 	" 	" 	" 	?28RXrz3<
BL"- VVb[!$ 		" 		" 		" 	v/T:::)* 	S(())+* *r0   c                ,    |                      |          S r   )r  r   s     r.   powzJax2TfLimitation.pow  s    g&&&r0   c                    t          t          j        gdd          t          t          j        gd          t          t          j        gd          gS )Nr   r   r   gdy=r  r   )r   r   r   r   r   r   r   r   s     r.   lgammazJax2TfLimitation.lgamma  sX     	O$"$	& 	& 	& 	rzl666rzl555 r0   c                    t          t          j        gd          t          t          j        gd          t          t          j        gd          gS )Ngt =r  g|=r   )r   r   r   r   r   r   s     r.   log1pzJax2TfLimitation.log1p  sJ     	r}o5999rzl666rzl555 r0   c           
     |   |j         fd}t          t          j        t          j        gdd          t          t          j        t          j        gdd          t          t          j        t          j        gdd	          t          t          j        t          j        gd
d	          t          |ddd          gS )Nc               Z   |\  |\  }}}j         d d         j         d         j         d         c}	fd}
t          |	          }t          j        |d          dd d d |f         t          j        |          z   }t          j        |          dd |d d f         } |
|          }|                     t          j        	                    |          |           | 
                    t          j        |          t          j        ||          |||           d S )NrU  r   c                    g }t          j        t          t          j        d d                    D ]!| fdt                    D             z  }"t          j        t          j        |          g           }|S )Nr   c                0    g | ]}|         k    rd ndS )r   r   r   )r,   cr|  perms     r.   r   z`Jax2TfLimitation.lu.<locals>.custom_assert.<locals>._make_permutation_matrix.<locals>.<listcomp>  s)    BBBA!tCy..QQaBBBr0   r  )rw  rx  ry  rh  r   r   r   rp  )r  resultr|  
batch_dimsr@   r-   r   s   ` @r.   _make_permutation_matrixzLJax2TfLimitation.lu.<locals>.custom_assert.<locals>._make_permutation_matrix  s    $c%ss1C&D&DE 	C 	CC
BBBBBqBBB
B&&BHV5999;NZ;N;NA;NOOr0   .r  r   )r   ro  r   r  eyetriuassertArraysEqualr   rX  lu_pivots_to_permutationr   ra  )r   r   r   r   r#   r   lupivotsr  nr  kr>   up_matr  r-   r   r@   s                  @@@r.   r"   z*Jax2TfLimitation.lu.<locals>.custom_assert  sc   hg"b&$="%j]2b 1da        a))a
(2r

32A2:
&AU)C)C)C
Ca
(2,,sBQBz
"a&&t,,e	
*
-
-fa
8
8$@ @ @	
*UG
$
$
*Q

      r0   r   g?r   r   r   r   r   )r   r   r#   r   r  zTMay return different, but also correct, results when the decomposition is not uniquer   )r"   r$   r   r   )r@   r   r   r   r   r   r   r@  s      @r.   r  zJax2TfLimitation.lu  s    ME    8 	J-u#	G 	G 	GJ-~	 	 	 	J.$	 	 	 	J.z	O 	O 	O';"0	2 	2 	2 r0   c                ~    d }t          |ddt          j                  t          |dddt          j                  gS )Nc                z    t          j        |          }|                     ||          ||          |           d S Nr7  r   r  r   r   r   r   r   r  r  s         r.   r"   z+Jax2TfLimitation.max.<locals>.custom_assert  @    Xj!!d	TE*Ite,<gNNNNNr0   May return different values when one of the values is NaN. JAX always returns NaN, while TF returns the value NaN is compared with.r   r"   r$   r   r   r   TF and JAX use different values of the compiler flag xla_cpu_enable_fast_min_max compiler flag and therefore have different behavior of NaN propagation through min/max.r"   r   r$   r   r   r   r   rI   rH   r  s      r.   maxzJax2TfLimitation.max  t    O O O
 	'[ 1!1!@	B 	B 	B 	'I 1!1!<		> 		> 		> r0   c                ~    d }t          |ddt          j                  t          |dddt          j                  gS )Nc               z    t          j        |          }|                     ||          ||          |           d S r  r  r  s         r.   r"   z+Jax2TfLimitation.min.<locals>.custom_assert  r  r0   r  r   r  r   r  r  r  r  s      r.   ro  zJax2TfLimitation.min	  r  r0   c                P    t          t          j        t          j        g          gS Nr
   )r   r   r   r   r   r   s     r.   	nextafterzJax2TfLimitation.nextafter'  s    bj&/%BCCCDDr0   c                    t          t          j        t          j        gddd          t          t          j        t          j        gddd          t          t          j        gd          gS )Nr   r   r   r  r   r   r   r   )	r   r   r   r   r   r   r   r   r   r   s     r.   qrzJax2TfLimitation.qr+  s}     	J."0		 	 	
 	J-"0		 	 	
 	O$	
 	
 	
 r0   c                &    t          dd          gS )Nr   r   r  r   r   s     r.   random_gammazJax2TfLimitation.random_gammaD  s    5d33344r0   c                P    t          t          j        t          j        g          gS r  )r   r   r   r   r   s     r.   
reduce_maxzJax2TfLimitation.reduce_maxH  s!     blBM%BCCCDDr0   c                ,    |                      |          S r   )r  r   s     r.   
reduce_minzJax2TfLimitation.reduce_minN  r  r0   c                   t          dt          j        gdddd|j        d          d          t          dt          j        t          j        t          j        gd	ddd
|j        d                    t          dt          j        gdd          t          dt          j        gdd          t          dt          j        gdd          gS )Nz=Small deviations on GPU for large inputs and enable_xla=Falser   r   Fr   giUMu>)r   r   r   r    r!   r   r#   z,Large deviations on TPU for enable_xla=Falser   Tr   r   r   )r   r   r   r#   r   r  r(  )r   r   r   r   r   r   r   r   r   s     r.   reduce_window_addz"Jax2TfLimitation.reduce_window_addR  s     	KJ<0!!|44	 	 	 	:ORZ<0! |44	6 	6 	6 UBJ<:F F F^RZL:F F F^V_4E:F F F- r0   c                    t          t          j        gd          t          t          j        t
          j        g          gS )Nr  r  r
   )r   r   r   r   r   r   r   r   s     r.   regularized_incomplete_betaz,Jax2TfLimitation.regularized_incomplete_betan  s9     	rzl666"*fo!>??? r0   c                H   t          dt          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j        t          j	        g	dd|j
        v           t          dt          j        gddd|j
        v           gS )	NrC  TrD  )r   r!   r   z>TF division of inf by inf returns inf while in JAX returns nanr   singularity_inf_by_inf)r   r   r!   r   )r   r   rE  rF  rG  rH  rI  r!  r   r"  r   r   r   s     r.   remzJax2TfLimitation.remu  s     	N"'29biBG"(BH !"gl2	5 	5 	5 	L
  -=	@ 	@ 	@ r0   c                    g S r   r   r   s     r.   rng_bit_generatorz"Jax2TfLimitation.rng_bit_generator  r  r0   c                >    t          t          j        gdd          gS r  r	  r   s     r.   roundzJax2TfLimitation.round  r  r0   c           
         t          dt          j        j        ddddd|j        v o|j        d                    t          dt          j        gd	|j        d          
          gS )Nz@out-of-bounds scatters are not supported in graph and eager moder   r   Tmodes_out_of_boundsr   r   r   r  )r   r   r#   r   )	r   r   r   r   r   r   r   r   r   r   s     r.   scatterzJax2TfLimitation.scatter  s     	N:))$  *gl:_7>R^C_?_	b 	b 	b 9ZLd").">>A A A r0   c                ,    |                      |          S r   r  r   s     r.   scatter_addzJax2TfLimitation.scatter_add      ;;wr0   c                ,    |                      |          S r   r  r   s     r.   scatter_mulzJax2TfLimitation.scatter_mul  r  r0   c                ,    |                      |          S r   r  r   s     r.   scatter_maxzJax2TfLimitation.scatter_max  r  r0   c                ,    |                      |          S r   r  r   s     r.   scatter_minzJax2TfLimitation.scatter_min  r  r0   c                >    t          dt          j        gd          gS )Nzjax2tf unimplemented for 64-bit inputs because the current implementation relies on packing two values into a single value. This can be fixed by using a variadic XlaReduceWindow, when availabler   r  )r   r   r   r   s     r.   select_and_gather_addz&Jax2TfLimitation.select_and_gather_add  s2     	H "$!/	1 	1 	1 r0   c                f    t          dd|j        d         dk    o|j        d          dd          gS )	Nz'TODO: TF non-stable multiple-array sortr   
num_arraysr   	is_stableFT)r   r   r    r!   )r   r   r   s     r.   sortzJax2TfLimitation.sort  sM     	5^L1A5 5 44! 	" 	" 	"	 	r0   c                   |j         d         fd}t          dt          j        t          j        gdd          t          dt          j        gdd	d
          t          t          j        gd          t          t          j        t          j        gdd          t          dt          j
        t          j        gdd	          t          dt          j        t          j        gdd	          t          dd|dd	d
k              t          ddt          j
        t          j        g|dd	           t          ddt          j
        t          j        t          j        t          j        g|dd	d
k              g	S )N
compute_uvc                   d  fd} fd}d }d }	r |||           |d         |d         }}
                      |
||||            ||||           |d         j        d         }|d	         j        d
         }|d         j        d
         } ||d         ||          }t          j        |d         j                  j        }|d         d         d         }||z  |z  }|dd |f         }|d	         dd |f         }|d	         dd |f         } |	|||           t          j        |d         dd |d d f         d
d                                          }t          j        |d         dd |d d f         d
d                                          } |	|||           d S                       |||||           d S )Nc                    | \  }}}|dd |j         d         f         }|dd |j         d         d d f         }|dd d d f         }t          j        ||z  |t          j        j                  S )N.r   	precision)r   r   ra  r   	PrecisionHIGHEST)r  sr  vUVSs          r.   reconstruct_operandzHJax2TfLimitation.svd.<locals>.custom_assert.<locals>.reconstruct_operand  sz     1ac<AGBK< c<AGBK<"#c4lOz!a%cm.CDDDDr0   c                d    d | D             }d |D             }                     ||           d S )Nc                    g | ]	}|j         
S r   r   r,   r  s     r.   r   zWJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_shapes.<locals>.<listcomp>  s    777vfl777r0   c                    g | ]	}|j         
S r   r  r  s     r.   r   zWJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_shapes.<locals>.<listcomp>  s    555fV\555r0   )assertEqual)r_jaxr_tf
shapes_jax	shapes_tfr   s       r.   compare_shapeszCJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_shapes  sC    77777
55555	
I.....r0   c                    |           } |          }t           j                            ||z
  d          }|t           j                            |d          z  }t          j        |          }	                    ||           d S )NrT  rV  )r   rX  rY  amax
assertLess)
r  r  r#   operand_jax
operand_tf
error_normbackward_errormax_backward_errorr  r   s
           r.   compare_reconstructed_operandzRJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_reconstructed_operand  s    ))%00((..
Z__[:%=3; % = =
$*//+H/EEF Xn55)3/////r0   c                <   ||k    rt           j        nd}t          j        | d|          }t          j        | dd d df         dt           j                  dd d df         }t          j        t          j        |          t          j        |                    }|S )Nr   r   )rW  append.)r   r;  r   diffminimumr^   )r  r-   r  forward_appendantforward_diffbackward_diffabsolute_gaps          r.   compute_absolute_gapzIJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compute_absolute_gap  s    &'1ffBFF!x3DEEEc44R4iLr"&2 2 225ttt)={37<#8#8#&7=#9#9; ;r0   c               J   t          j        t          j        ||           dd          }t          j        |t          j        |                    }| |z  } d } || |          t          j         || |            |||          z            z  }t          j        |dd          }t          j        |          }| j        t          j	        t          j
        fv rd}n!| j        t          j        t          j        fv rd	}t          j                            |||z             d S )
NrU  T)keepdimsc                    t          j        t          j        d|                                 |t          j        j                  d          }t          j        |          S )Nz...ij,...ij->...ijr  rU  rV  )r   sumeinsumrm   r   r  r  rq   )rb  boutputs      r.   dot_column_wisezfJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_singular_vectors.<locals>.dot_column_wise  sZ    73:&:AFFHHa030EG G G "$ $ $& &!!
!r0   r5  r  )ro  r  g     @g    eA)r   r.  divider^   rt   cliparccosr@   r   r   r   r   r   testingassert_array_less)	r\  r  error_boundsum_of_ratiosphasesr2  cos_angular_diffangular_diffslack_factors	            r.   compare_singular_vectorszMJax2TfLimitation.svd.<locals>.custom_assert.<locals>.compare_singular_vectors  s6    
1a 0 0"tDDDM37=+A+ABB	V
	" 	" 	" OAq!!H__Q**__Q-B-BBCCD 	 8$4#3GGGz"233 7rz2<000,,WR]333,

$$\%1K%?	A 	A 	A 	A 	Ar0   r   r   r   r   rU  r   ).r   ).N.)r8  )r   r   r   rZ  r@   r[  swapaxesrm   )r   r  r  r   r#   r   r  r!  r*  r>  s_jaxs_tfrj  r-   r  r)  epsilonsigma_largestupperbound_singular_vectorsu_jaxu_tfv_jaxv_tfr  r  s   `                      @r.   r"   z+Jax2TfLimitation.svd.<locals>.custom_assert  s   E E E/ / / / /0 0 0 0 0 0"  'A 'A 'AR 
 ,Mud### AhQt5$SsGLLL 	&%eT3777 Qx~b!
 !HN2!HN2++E!Ha;;)E!HN++/q&)95&-&=&L#&A#uu*&M# aete$AwsETEz"  -H	J 	J 	J 	J U1Xc5D5!!!m4b"==BBDD|DGC$M2B;;@@BB  -H	J 	J 	J 	J 	J 	J 	5$SsGLLLLLr0   zRfunction not compilable. Implemented using `tf.linalg.svd` and `tf.linalg.adjoint`r   r   r   zLarge numerical discrepancyr   r   T)r   r   r   r!   r  )r   r   )r   r   r   r   )r#   r   r   r   z4custom numeric comparison when compute_uv on CPU/GPU)r#   r$   r"   r   r   r   r   z1custom numeric comparison when !compute_uv on TPU)r#   r$   r   r"   r   r   r   r  z0custom numeric comparison when compute_uv on TPU)r   r   r   r   r   r   r   r   r   r   r   r   )rT   rL   r"   r  s      @r.   svdzJax2TfLimitation.svd  s    -JHM HM HM HM HMX 	`L"-0"		! 	! 	!
 	)J<0 	" 	" 	" 	&/!2EBBB",!> 5"'	) 	) 	) 	J-"0		2 	2 	2 	J."0		2 	2 	2
 	N'"04'	* 	* 	* 	KJ-'0"N	$ 	$ 	$ 	JJ
BL"-H'04'	* 	* 	*W3 3r0   c                    t          t          j        gdd          t          t          j        gdd          t          t          j        gdd          gS )Nr   r   r   r   r   r   r   r   s     r.   r   zJax2TfLimitation.tan  sP     	r|neFFFr|nn$OOOr}o~5QQQ r0   c                r    t          t          j        gd          t          t          j        gd          gS )NgHz>r  r   )r   r   r   r   r   s     r.   r  zJax2TfLimitation.tanh  s6     	r}o4888r|n$777 r0   c                    d }t          t          j        t          j        t          j        t          j        g|d          gS )Nc                  t          |          t          |          k    sJ |d         |d         }}t          j        ||k              r0t          ||          D ]\  }}|                     |||           d S t          j        |          t          j        |          z  }	t          j        |          t          j        |          z  }
|                     ||	          ||
          |           d S )Nr   r7  )rg  r   r4   zipr  r  r  )r   r   r   r   r  first_arr_jaxfirst_arr_tfarr_jaxarr_tfmask_jaxmask_tfs              r.   r"   z-Jax2TfLimitation.top_k.<locals>.custom_assert  s   __I....$.qM9Q<\m	-	.	. O":y99 	B 	BOGV




A
A
A
A	B 	B 8M**RXm-D-DD(<((28L+A+AA8)$lG8&<g 	 	O 	O 	O 	O 	Or0   zoProduces different results when the array contains `inf` and `NaN` (they are sorted differently in TF vs. XLA).r?  )r   r   r   r   r   r   r   r  s      r.   top_kzJax2TfLimitation.top_k  sR    O O O 	JRZH'@		B 	B 	B r0   c                    t          t          j        gdd          t          t          j        gdd          t          t          j        gdd          gS )N)r   r   r   r   r  r   )r   r#   r   )r   r   r   r   r   r   r   r   s     r.   triangular_solvez!Jax2TfLimitation.triangular_solve  sn     	O$"$	& 	& 	& 	J<"$	& 	& 	& 	rzl;	= 	= 	= r0   c                    g S r   r   r   s     r.   tridiagonal_solvez"Jax2TfLimitation.tridiagonal_solve  r  r0   )r$   r%   r   r&   r   r'   r   r(   r    r(   r"   r)   )r7   r8   r9   r:   )NNN)r@   rA   rB   rC   rD   rC   r9   r(   )rL   rM   r9   r8   )r   rM   )rL   rM   )N__name__
__module____qualname____doc__rH   rI   r2   r?   rJ   classmethodrV   rQ   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r  r%  r)  r,  r/  r2  rA  rJ  rN  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ro  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rI  r   r  rU  rW  rY  __classcell__)r6   s   @r.   r   r   "   s         *. &; "*)"'+
2+ 2+ 2+ 2+ 2+ 2+ 2+ 2+h   " !	8 8 8 8 8 8 8    ;&# # #$ 
% 
% ;
% ) ) ) ;) ) ) ) ;) ) ) ) ;)    ;(    ;$ "* "* "* ;"*H 
 
 
 ;
    ; 	 	 	 ;	    ;"    ;    ;    ; # # # ;#    ;
 ( ( ( ;(T    ;8   ;   ;   ; 
 
 
 ;
 ' ' ' ;'R 
 
 
 ;
 @ @ @ ;@D @ @ @ ;@D E E E ;EN    ;    ;    ;< ; ; ; ;;   ;,    ;4 $ $ $ ;$L ( ( ( ;(T * * * ;*2 ' ' ' ;'    ;    ; 0 0 0 ;0d    ;:    ;: E E E ;E    ;0 5 5 5 ;5 E E E ;E
 # # # ;#    ;6    ;    ;*    ;    ;   ;     ;      ;      ;      ;    ; 
 
 
 ;
 E E E ;EN   ;   ;   ;0    ;    ;    r0   r   zcustom numeric comparisonr   r   r   Tr$   r   r   r   r"   r   r   r#   r9   c                2    t          | d|||||||	  	        S )NF)r    r   r   r   r"   r   r   r#   r   r`  s           r.   r   r     s6     
!/
	
 	
 	
 	r0   c                 ,    d } t          dd|           S )Nc               R    d }|                       ||          ||||           d S )Nc                    t           j                            | j        t           j        j                  r$t           j        j                            |           S | S r   )jaxr   
issubdtyper@   prng_key_srcprngrandom_unwrap)keyss    r.   unwrap_keyszEcustom_random_keys_output.<locals>.custom_assert.<locals>.unwrap_keys  s@    			tz3:+>	?	? x}**4000r0   r   r   )r   r   r   r   r#   r   rm  s          r.   r"   z0custom_random_keys_output.<locals>.custom_assert  sO       {{:..	c7  < < < < <r0   z8Returns JAX key arrays, so compare underlying base arrayr   )r$   r   r"   r  )r"   s    r.   r   r     s3    	< 	< 	< 
L*!
# 
# 
# #r0   zop not defined for dtyper   )r$   r   r   r   r   c                ,    t          | |||||          S )N)r   r   r   r   r   rb  )r$   r   r   r   r   r   s         r.   r   r     s)     
&'/
1 
1 
1 1r0   )r9   r   )r]  
__future__r   collections.abcr   r   rw  typingr   rf  r   r   r   jax._srcr	   r   r   r   jax._src.internal_test_utilr   r   DType
Limitationr   rI   r   r   r   r   r0   r.   <module>rv     s   L K " " " " " " . . . . . . . .           



                         % % % % % % 6 6 6 6 6 6    s s s s s~0 s s sn- ,
 ")8     4# # #& +
(!+:
1 
1 
1 
1 
1 
1 
1 
1r0   