o
    Z۷i                     @   s   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 d dlm	Z	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZ d dlmZ d dlmZmZ d	ZG d
d de	Zdd ZG dd de
e	ZG dd de	eZdS )    N)types)TestCaseMemoryLeakMixin)_get_proper_funcnext_uint32next_uint64next_double)MT19937	Generator)TypingError)run_in_new_process_cachingSerialMixini   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestHelperFuncsc                 C   s   dd }dd }|  t||tjd  d |  t||tjd  d | t}t||tj W d    n1 s;w   Y  | dt	|j
 | t}t||tj W d    n1 s`w   Y  | dt	|j
 d S )	Nc                   S      dS )N     r   r   r   S/home/ubuntu/vllm_env/lib/python3.10/site-packages/numba/tests/test_np_randomgen.pytest_32bit_func      zBTestHelperFuncs.test_proper_func_provider.<locals>.test_32bit_funcc                   S   r   )N@   r   r   r   r   r   test_64bit_func   r   zBTestHelperFuncs.test_proper_func_provider.<locals>.test_64bit_funcr   r   r   z1Argument dtype is not one of the expected type(s))assertEqualr   npfloat64float32assertRaisesr   int32assertInstr	exceptionr   )selfr   r   raisesr   r   r   test_proper_func_provider   s<   

z)TestHelperFuncs.test_proper_func_providerc                 C   s   t jd}dd }tjdd|}| t}|| W d    n1 s&w   Y  d}| t	|t
|jd uddt
|j   d S )	N   c                 S   s   | j ddS )N)r   )locnormalxr   r   r   <lambda>6       z2TestHelperFuncs.test_check_types.<locals>.<lambda>TcachezArgument loc is not one of the expected type\(s\): \[<class 'numba.core.types.*.Float'>, <class 'numba.core.types.*.Integer'>, <class 'int'>, <class 'float'>\]z0Expected pattern not found in exception message.z Found )r   randomdefault_rngnumbanjitr   r   
assertTrueresearchr   r    )r!   rngpy_func
numba_funcr"   expected_patternr   r   r   test_check_types4   s   
z TestHelperFuncs.test_check_typesc              
   C   s  t jd}dd }t |}t |}dd }t |}t t jjt t jjt jft t j	jt t j	jt j	ft t j
jt t j
jt j
ft t jjt t jjt jft t jjt t jjt jft t jjt t jjt jfg}|D ]\}}}	| j|||	d} | t}
|||d ||	 W d    n1 sw   Y  | dt|
j | t}
||||d |	 W d    n1 sw   Y  | dt|
j | t}
||||d |	 W d    n1 sw   Y  | dt|
j W d    n	1 sw   Y  q~t t jjt t jjt j}}}	| t}
|||d ||	 W d    n	1 s?w   Y  | dt|
j t t jjt t jjt j}}}	| t}
||||d |	 W d    n	1 szw   Y  | dt|
j | t}
||||d |	 W d    n	1 sw   Y  | dt|
j | t}
||d	d
t j W d    n	1 sw   Y  | dt|
j d S )Nr$   c                 S      | j |||ddS )NTlowhighdtypeendpointintegersr)   r<   r=   r>   r   r   r   r*   J      z9TestHelperFuncs.test_integers_arg_check.<locals>.<lambda>c                 S   r:   )NFr;   r@   rB   r   r   r   r*   O   rC   r<   r=   r>   zlow is out of boundszhigh is out of bounds   i   d   z*low is greater than high in given interval)r   r.   r/   r0   r1   iinfouint8minmaxint8uint16int16uint32r   subTestr   
ValueErrorr   r   r    uint64int64)r!   r5   r6   r7   numba_func_lownumba_func_endpoint_falsecasesr<   r=   r>   r"   r   r   r   test_integers_arg_checkH   s   	

z'TestHelperFuncs.test_integers_arg_checkN)__name__
__module____qualname__r#   r9   rW   r   r   r   r   r      s    r   c                  C   sN   t jd} t jd}dd }tjdd|}t |d|| s%J d S )Nr$   c                 S   
   |  dS N
   r.   r(   r   r   r   r*         
 z(test_generator_caching.<locals>.<lambda>Tr,   r]   )r   r.   r/   r0   r1   allclose)nb_rngnp_rngr6   r7   r   r   r   test_generator_caching   s
   rc   c                   @   s  e Zd Z			dbddZdcddZdd	 Zd
d Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!dBdC Z"dDdE Z#dFdG Z$dHdI Z%dJdK Z&dLdM Z'dNdO Z(dPdQ Z)dRdS Z*dTdU Z+dVdW Z,dXdY Z-dZd[ Z.d\d] Z/d^d_ Z0d`da Z1dS )dTestRandomGeneratorsN   c                 C   s   t |}|d u rd}|d u rtjj|d}tjj|d}nt||}t||}||||}	||||}
t|	tjrEt	|	j
tjsJt|	trUtjj|
|	||d ntj|	|
 |jjd }|jjd }|D ]}| || ||  qjd S )Nr$   seed)maxulpr>   state)r0   r1   r   r.   r/   r   r6   
isinstancendarray
issubdtyper>   floatingfloattestingassert_array_max_ulpassert_equalbit_generatorri   assertPreciseEqual)r!   distribution_funcbitgen_typerg   	test_size
test_dtypeulp_precnumba_rng_instancenumpy_rng_instance	numba_res	numpy_resnumba_gen_statenumpy_gen_state
_state_keyr   r   r   check_numpy_parity   s<   


z'TestRandomGenerators.check_numpy_parityr$   c           
         sb   t jj|d}t jj|d}t|jj|}||jjj}t fdd}||}	| 	|	| d S )Nrf   c                    s
    | j S N)rr   r(   bitgen_funcr   r   r*      r_   z?TestRandomGenerators._test_bitgen_func_parity.<locals>.<lambda>)
r   r.   r/   getattrrr   ctypesri   r0   r1   rs   )
r!   	func_namer   rg   ry   rz   
numpy_funcr|   r7   r{   r   r   r   _test_bitgen_func_parity   s   z-TestRandomGenerators._test_bitgen_func_parityc              	   C   s   t j }t|D ]>\}}| }|| ||< |g| }t|}	| t}
|	|  W d    n1 s5w   Y  | 	d| dt
|
j q	d S )Nz	Argument z$ is not one of the expected type(s):)r   r.   r/   	enumeratecopyr0   r1   r   r   r   r   r    )r!   	dist_funcarg_list
valid_argsinvalid_argsr5   idx_arg	curr_argsnb_dist_funcr"   r   r   r   _check_invalid_types   s   




z)TestRandomGenerators._check_invalid_typesc                 C   sD   t j }tdd }| ||| | t|t|| d S )Nc                 S      | S r   r   r(   r   r   r   r*          zATestRandomGenerators.test_npgen_boxing_unboxing.<locals>.<lambda>)r   r.   r/   r0   r1   r   id)r!   rng_instancer7   r   r   r   test_npgen_boxing_unboxing   s   
z/TestRandomGenerators.test_npgen_boxing_unboxingc                 C   sp   t j }tdd }tdd }||}t  t|}~|| t  t|}| 	||d  d S )Nc                 S      |   S r   r^   r(   r   r   r   r*          zATestRandomGenerators.test_npgen_boxing_refcount.<locals>.<lambda>c                 S   r   r   r   r(   r   r   r   r*      r   r$   )
r   r.   r/   r0   r1   gccollectsysgetrefcountr   )r!   r   no_boxdo_boxyref_1ref_2r   r   r   test_npgen_boxing_refcount   s   


z/TestRandomGenerators.test_npgen_boxing_refcountc              	   C   sd   g d}t ttg}t||D ]!\}}| j||d | || W d    n1 s*w   Y  qd S )Nr   )_func
_func_name)r   r   r	   ziprP   r   )r!   
func_namesfuncsr   r   r   r   r   test_bitgen_funcs   s   
z&TestRandomGenerators.test_bitgen_funcsc                 C   s  g d}t jt jt jt jt jt jt jt jg}d t	g}dd }| 
  | j|d d dd W d    n1 s6w   Y  dd }|D ].}|D ])}|D ]$}| j
|||d | ||d ||d W d    n1 shw   Y  qIqEqAg d}d t	g}dd }|D ])}|D ]$}| j
||d	 | ||d |t jd W d    n1 sw   Y  qq~d
d }| 
  | j|d d d W d    n1 sw   Y  dd }| |g ddddt jdgdddt jdg d S )NNr   )rG   r]         c                 S   s   |  ddS Nr   rG   r@   r)   sizer>   r   r   r   r*   
  r+   z4TestRandomGenerators.test_integers.<locals>.<lambda>r   rv   rw   rx   c                 S   s   | j dd||dS )Nre   r]   r   r>   r@   r   r   r   r   r*     rC   _size_dtype_bitgenc                 S   s   | j dd|tjdS )NFTr   )rA   r   bool_r   r   r   r   r*     s   r   r   c                 S   s   |  tdtdS r   )rA   r   rI   rS   r   r   r   r   r*   '  s   rv   rw   c                 S   s   | j |||||dS )Nr<   r=   r   r>   r?   r@   )r)   r<   r=   r   r>   r?   r   r   r   r*   -  s   
r   r$   re   r$   Tr)   r(   )r   rS   r   rN   rL   rR   rO   rM   rI   r
   rP   r   r   r   r   r!   
test_sizestest_dtypesbitgen_typesr   r   r   r   r   r   r   test_integers  sf   


z"TestRandomGenerators.test_integersc              
      s8  g ddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfdd	t jfd
d	t jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jfddt jf}d}|D ]/\ }| j	 |d  fdd}| 
|d d ||d W d    n	1 sw   Y  qd S )Nre      rG   r   l   l    l    l   l   ll    l    iii  i  i  r]   i  i  i            i)rE      rD   c                    s   | j  ||dS Nr   r@   r   r=   r<   r   r   r*   k  rC   z:TestRandomGenerators.test_integers_cases.<locals>.<lambda>)r   rR   rS   rO   r   rM   rN   rI   rL   rP   r   )r!   rV   r   r>   r   r   r   r   test_integers_cases6  s   






	



















 
!
"
#
%
&
'
(
*
+
,
-
.0z(TestRandomGenerators.test_integers_casesc                 C   s   g d}t jt jg}d tg}dd }|   | j|d d d W d    n1 s)w   Y  dd }|D ]-}|D ](}|D ]#}| j|||d | ||d || W d    n1 sZw   Y  q<q8q4dd }| |dd	gd
t jgddg d S )Nr   c                 S   r   r   r^   r   r   r   r   r*   v  r   z2TestRandomGenerators.test_random.<locals>.<lambda>r   c                 S      | j ||dS r   r^   r   r   r   r   r*   {      r   c                 S   r   r   r^   r   r   r   r   r*        r   r>   r   r(   g        r   r   r   r
   rP   r   r   r   r   r   r   test_randomp  s6   
z TestRandomGenerators.test_randomc                 C   s   g d}t jt jg}d tg}dd }|   | j|d d d W d    n1 s)w   Y  dd }|D ]-}|D ](}|D ]#}| j|||d | ||d || W d    n1 sZw   Y  q<q8q4dd }| |dd	gd
t jgddg d S )Nr   c                 S   r   r   standard_normalr   r   r   r   r*     r   z;TestRandomGenerators.test_standard_normal.<locals>.<lambda>r   c                 S   r   r   r   r   r   r   r   r*     r   r   c                 S   r   r   r   r   r   r   r   r*     r   r   r>   r   r(   r   r   r   r   r   r   test_standard_normal  s6   
z)TestRandomGenerators.test_standard_normalc                 C   s   g d}t jt jg}d tg}dd }|   | j|d d d W d    n1 s)w   Y  dd }|D ]-}|D ](}|D ]#}| j|||d | ||d || W d    n1 sZw   Y  q<q8q4dd }| |g dd	d
t jgg d d S )Nr   c                 S   r   r   standard_exponentialr   r   r   r   r*     r   z@TestRandomGenerators.test_standard_exponential.<locals>.<lambda>r   c                 S   r   r   r   r   r   r   r   r*     r   r   c                 S      | j |||dS )Nmethodr   r>   r   )r)   r   r   r>   r   r   r   r*        r   zigr   )r   r(   r   r   r   r   r   r   test_standard_exponential  s6   
z.TestRandomGenerators.test_standard_exponentialc                 C   s   g d}t jt jg}d tg}dd }|D ]-}|D ](}|D ]#}| j|||d | ||d || W d    n1 s:w   Y  qqqd S )Nr   c                 S   s   | j ||ddS )Ninv)r   r>   r   r   r   r   r   r   r*     r   zDTestRandomGenerators.test_standard_exponential_inv.<locals>.<lambda>r   )r   r   r   r
   rP   r   r   r   r   r   test_standard_exponential_inv  s$   z2TestRandomGenerators.test_standard_exponential_invc                 C   s   g d}t jt jg}d tg}dd }|D ].}|D ])}|D ]$}| j|||d | ||d ||t W d    n1 s;w   Y  qqqdd }| |g dddt jgg d	 d S )
Nr   c                 S   s   | j d||dS )N      @shaper   r>   standard_gammar   r   r   r   r*     r   z:TestRandomGenerators.test_standard_gamma.<locals>.<lambda>r   c                 S   r   )Nr   r   )r)   r   r   r>   r   r   r   r*     r   r   r   r   )r)   r(   r   )r   r   r   r
   rP   r   adjusted_ulp_precr   r   r   r   r   test_standard_gamma  s,   z(TestRandomGenerators.test_standard_gammac                 C      g d}d t g}dd }|   | j|d d td W d    n1 s$w   Y  dd }|D ](}|D ]#}| j||d | ||d |d t W d    n1 sQw   Y  q3q/dd }| |g dg d	g d
 d S )Nr   c                 S   r   r   r&   r   r   r   r   r*     r   z2TestRandomGenerators.test_normal.<locals>.<lambda>r   c                 S      | j dd|dS )N      ?r   r%   scaler   r&   r   r   r   r   r*         r   c                 S   r   Nr   r&   r)   r%   r   r   r   r   r   r*     r   r   r   r   r   r)   r)   r(   r
   rP   r   r   r   r!   r   r   r   r   r   r   r   r   test_normal  0   
z TestRandomGenerators.test_normalc                 C   r   )Nr   c                 S   r   r   uniformr   r   r   r   r*     r   z3TestRandomGenerators.test_uniform.<locals>.<lambda>r   c                 S   r   )Nr   r   r<   r=   r   r   r   r   r   r   r*   	  r   r   c                 S   r   )Nr   r   )r)   r<   r=   r   r   r   r   r*     r   r   r   r   r   r   r   r   r   test_uniform  r   z!TestRandomGenerators.test_uniformc              
   C      g d}d t g}dd }|   | j|d d d W d    n1 s#w   Y  dd }|D ]'}|D ]"}| j||d | ||d |d  W d    n1 sOw   Y  q2q.dd }| |dd	gd
dgddg d S )Nr   c                 S   r   r   exponentialr   r   r   r   r*     r   z7TestRandomGenerators.test_exponential.<locals>.<lambda>r   c                 S      | j d|dS Nr   r   r   r   r   r   r   r   r*   "  r   r   c                 S   r   Nr   r   r)   r   r   r   r   r   r*   (  r   r   r   r   r   r)   r(   r
   rP   r   r   r   r   r   r   test_exponential  s,   
z%TestRandomGenerators.test_exponentialc                 C      g d}d t g}dd }|D ](}|D ]#}| j||d | ||d |d t W d    n1 s0w   Y  qqdd }| |g dg dg d d S )	Nr   c                 S   r   )Nr   r   r   r   r   gammar   r   r   r   r*   4  s    z1TestRandomGenerators.test_gamma.<locals>.<lambda>r   c                 S   r   )Nr  r  )r)   r   r   r   r   r   r   r*   <  r   r  r   r   r   r   r   r   r   r   r   
test_gamma-  s"   zTestRandomGenerators.test_gammac                 C   r   )	Nr   c                 S   r   )Nr   g      @abr   betar   r   r   r   r*   H  r   z0TestRandomGenerators.test_beta.<locals>.<lambda>r   c                 S   r   )Nr  r	  )r)   r  r  r   r   r   r   r*   P  r   r  r  r   r   r   r   r   r   	test_betaA  "   zTestRandomGenerators.test_betac                 C   r   )	Nr   c                 S   r   )NrE   r   dfnumdfdenr   fr   r   r   r   r*   [  r   z-TestRandomGenerators.test_f.<locals>.<lambda>r   c                 S   r   )Nr  r  )r)   r  r  r   r   r   r   r*   c  r   r  )re   r$   r   r   r   r   r   r   r   test_fT  "   zTestRandomGenerators.test_fc                 C      g d}d t g}dd }|D ](}|D ]#}| j||d | ||d |d t W d    n1 s0w   Y  qqdd }| |ddgdd	gd
dg d S )Nr   c                 S   r   NrE   dfr   	chisquarer   r   r   r   r*   o  r   z5TestRandomGenerators.test_chisquare.<locals>.<lambda>r   c                 S   r   Nr  r  r)   r  r   r   r   r   r*   w  r   r  r   rE   r   r)   r(   r   r   r   r   r   test_chisquareh  r  z#TestRandomGenerators.test_chisquarec              
   C   s   g d}d t g}dd }|   | j|d d d W d    n1 s#w   Y  dd }|D ]'}|D ]"}| j||d | ||d |d  W d    n1 sOw   Y  q2q.dd }| |dgd	gd
g d S )Nr   c                 S   r   r   standard_cauchyr   r   r   r   r*     r   z;TestRandomGenerators.test_standard_cauchy.<locals>.<lambda>r   c                 S      | j |dS Nr   r  r   r   r   r   r*     r+   r   c                 S   r  r   r  )r)   r   r   r   r   r*     r+   r   r   r(   r   r   r   r   r   test_standard_cauchy|  s,   

z)TestRandomGenerators.test_standard_cauchyc              
   C      g d}d t g}dd }|D ]'}|D ]"}| j||d | ||d |d  W d    n1 s/w   Y  qqdd }| |ddgdd	gd
dg d S )Nr   c                 S   r   N      ?r  r   paretor   r   r   r   r*     r   z2TestRandomGenerators.test_pareto.<locals>.<lambda>r   c                 S   r   Nr&  r'  r)   r  r   r   r   r   r*     r   r  r   r$   r   r)   r(   r   r   r   r   r   test_pareto      z TestRandomGenerators.test_paretoc              
   C   r#  )Nr   c                 S   r   r$  weibullr   r   r   r   r*     r   z3TestRandomGenerators.test_weibull.<locals>.<lambda>r   c                 S   r   r)  r-  r*  r   r   r   r*     r   r  r   r$   r   r)   r(   r   r   r   r   r   test_weibull  r,  z!TestRandomGenerators.test_weibullc              
   C   r#  )Nr   c                 S   r   )N      ?r&  powerr   r   r   r   r*     r   z1TestRandomGenerators.test_power.<locals>.<lambda>r   c                 S   r   r)  r1  r*  r   r   r   r*     r   r  r   r0  r   r)   r(   r   r   r   r   r   
test_power  r,  zTestRandomGenerators.test_powerc                 C   r   )Nr   c                 S   r   r   laplacer   r   r   r   r*     r   z3TestRandomGenerators.test_laplace.<locals>.<lambda>r   c                 S   r   Nr%  r   r   r4  r   r   r   r   r*     r   r   c                 S   r   r   r4  r   r   r   r   r*     r   r   r%  r   r   r   r   r   r   r   r   test_laplace  0   
z!TestRandomGenerators.test_laplacec                 C   r   )Nr   c                 S   r   r   logisticr   r   r   r   r*     r   z4TestRandomGenerators.test_logistic.<locals>.<lambda>r   c                 S   r   r6  r:  r   r   r   r   r*     r   r   c                 S   r   r   r:  r   r   r   r   r*     r   r   r7  r   r   r   r   r   r   test_logistic  r9  z"TestRandomGenerators.test_logisticc                 C   r   )Nr   c                 S   r   r   	lognormalr   r   r   r   r*   
  r   z5TestRandomGenerators.test_lognormal.<locals>.<lambda>r   c                 S   r   )Nr   r   meansigmar   r=  r   r   r   r   r*     r   r   c                 S   r   )Nr?  r=  )r)   r@  rA  r   r   r   r   r*     r   r?  r7  r   r   r   r   r   r   test_lognormal  r9  z#TestRandomGenerators.test_lognormalc              
   C   r   )Nr   c                 S   r   r   rayleighr   r   r   r   r*   &  r   z4TestRandomGenerators.test_rayleigh.<locals>.<lambda>r   c                 S   r   r   rC  r   r   r   r   r*   +  r   r   c                 S   r   r   rC  r   r   r   r   r*   2  r   r   r   r   r   r)   r(   r   r   r   r   r   test_rayleigh  s,   
z"TestRandomGenerators.test_rayleighc                 C   r  )Nr   c                 S   r   r  
standard_tr   r   r   r   r*   =  r   z6TestRandomGenerators.test_standard_t.<locals>.<lambda>r   c                 S   r   r  rF  r  r   r   r   r*   E  r   r  r   rE   r   r)   r(   r   r   r   r   r   test_standard_t6  r  z$TestRandomGenerators.test_standard_tc                 C   r   )	Nr   c                 S   r   )Nr   r   r@  r   r   waldr   r   r   r   r*   P  r   z0TestRandomGenerators.test_wald.<locals>.<lambda>r   c                 S   r   )NrI  rJ  )r)   r@  r   r   r   r   r   r*   X  r   rI  r7  r   r   r   r   r   r   	test_waldI  r  zTestRandomGenerators.test_waldc                 C   r  )Nr   c                 S   r   )Nr0  pr   	geometricr   r   r   r   r*   d  r   z5TestRandomGenerators.test_geometric.<locals>.<lambda>r   c                 S   r   NrM  rO  r)   rN  r   r   r   r   r*   l  r   rN  r   r0  r   r)   r(   r   r   r   r   r   test_geometric]  r  z#TestRandomGenerators.test_geometricc              
   C   r#  )Nr   c                 S   r   )Nr   r&  zipfr   r   r   r   r*   w  r   z0TestRandomGenerators.test_zipf.<locals>.<lambda>r   c                 S   r   r)  rT  r*  r   r   r   r*   ~  r   r  r   r$   r   r)   r(   r   r   r   r   r   	test_zipfp  r,  zTestRandomGenerators.test_zipfc              
   C   s   g d}d t g}dd }|D ]'}|D ]"}| j||d | ||d |d  W d    n1 s/w   Y  qqdd }| |g dg dg d d S )	Nr   c                 S   s   | j ddd|dS )Nr   r   re   leftmoderightr   
triangularr   r   r   r   r*     rC   z6TestRandomGenerators.test_triangular.<locals>.<lambda>r   c                 S      | j ||||dS )NrW  r[  )r)   rX  rY  rZ  r   r   r   r   r*     rC   rW  )r   r   re   r   r)   r)   r)   r(   r   r   r   r   r   test_triangular  s    z$TestRandomGenerators.test_triangularc                 C   r  )Nr   c                 S   r   )Nr   lamr   poissonr   r   r   r   r*     r   z3TestRandomGenerators.test_poisson.<locals>.<lambda>r   c                 S   r   )Nr`  rb  )r)   ra  r   r   r   r   r*     r   ra  r   r   r   r)   r(   r   r   r   r   r   test_poisson  r  z!TestRandomGenerators.test_poissonc                 C   r   )	Nr   c                 S   r   Nr$   皙?nrN  r   negative_binomialr   r   r   r   r*     r   z=TestRandomGenerators.test_negative_binomial.<locals>.<lambda>r   c                 S   r   Nrg  ri  r)   rh  rN  r   r   r   r   r*     r   rg  r$   r0  r   r   r   r   r   r   r   test_negative_binomial  "   z+TestRandomGenerators.test_negative_binomialc              
      s   dg}d t g}g d}t|||D ]-\}} | j|| d  fdd}| ||d |d d W d    n1 s:w   Y  qd S )Nr   )r   r$   rE   r   r   _axisc                    s   | j |d}| j| d |S )Nr!  axis)r.   shuffler)   r   r>   arrrq  r   r   r     s   z4TestRandomGenerators.test_shuffle.<locals>.dist_funcr   )r
   	itertoolsproductrP   r   )r!   r   r   axesr   r   r   r   rw  r   test_shuffle  s    z!TestRandomGenerators.test_shufflec                 C   N   t g }t g }dd }t|}dd }| || ||| | d S )Nc                 S   s   |  | |S r   rt  r)   rv  r   r   r   r     s   
z:TestRandomGenerators.test_shuffle_empty.<locals>.dist_funcc                   S      t jdS Nr$   r   r.   r/   r   r   r   r   r*     r+   z9TestRandomGenerators.test_shuffle_empty.<locals>.<lambda>r   arrayr0   r1   rs   r!   r  r  r   nb_funcr5   r   r   r   test_shuffle_empty  s   


 z'TestRandomGenerators.test_shuffle_emptyc                 C   s   |    dd }| |ddgtg ddgddg tjd}| t}t	||tg dd W d    n1 s?w   Y  | 
d	t|j d S )
Nc                 S   s   | j ||d |S Nrr  r}  r)   rv  rs  r   r   r   r     s   z:TestRandomGenerators.test_shuffle_check.<locals>.dist_funcr)   rs  r      re   r   r$   rE   )Axis is out of bounds for the given arraydisable_leak_checkr   r   r  r.   r/   r   
IndexErrorr0   r1   r   r   r    r!   r   r5   r"   r   r   r   test_shuffle_check  s   z'TestRandomGenerators.test_shuffle_checkc              
   C   s   dg}d t g}g d}t|||D ]+\}}}| j|||d dd }| ||d |d d W d    n1 s8w   Y  qtdd }tj	 }|jd	d
}	|	
 }
|||	 | |	|
 d S )Nr   )r   r$   rE   rp  c                 S   s   | j |d}| j|ddS )Nr!  r$   rr  )r.   permutationru  r   r   r   r     s   z8TestRandomGenerators.test_permutation.<locals>.dist_funcr   c                 S   
   |  |S r   r  )r5   rv  r   r   r   r*     r_   z7TestRandomGenerators.test_permutation.<locals>.<lambda>)r]   r   r!  )r
   rx  ry  rP   r   r0   r1   r   r.   r/   r   rs   )r!   r   r   rz  r   r   rq  r   r5   rv  arr_cpyr   r   r   test_permutation  s*   	

z%TestRandomGenerators.test_permutationc                 C   s   |    dd }| |ddgtg ddgddg tjd}| t}t	||tg dd W d    n1 s?w   Y  | 
d	t|j | t}t	||tg dd
 W d    n1 skw   Y  | 
d	t|j d S )Nc                 S   r   r  r  r  r   r   r   r     r   zBTestRandomGenerators.test_permutation_exception.<locals>.dist_funcr)   rs  r  r   r$   rE   r  r  r  r  r   r   r   test_permutation_exception  s(   z/TestRandomGenerators.test_permutation_exceptionc                 C   r|  )Nc                 S   r  r   r  r~  r   r   r   r   '  s   
z>TestRandomGenerators.test_permutation_empty.<locals>.dist_funcc                   S   r  r  r  r   r   r   r   r*   +  r+   z=TestRandomGenerators.test_permutation_empty.<locals>.<lambda>r  r  r   r   r   test_permutation_empty#  s   


 z+TestRandomGenerators.test_permutation_emptyc              	   C   sh  g d}d t g}dd }t||D ]$\}}| j||d | ||d |d  W d    n1 s1w   Y  qdd }g d}| |g d|g d tj }|g| }t	
|}| t}	| }
d	|
d
< ||
  W d    n1 svw   Y  | dt|	j | t}	| }
d|
d< ||
  W d    n1 sw   Y  | dt|	j |   d S )Nr   c                 S   r   N      @g      4@r!  noncentral_chisquarer   r   r   r   r*   6  r   z@TestRandomGenerators.test_noncentral_chisquare.<locals>.<lambda>r   c                 S   r   )Nr  noncr   r  )r)   r  r  r   r   r   r   r*   =  r   )r  r   r   r  r   r   r$   zdf <= 0r  rE   nonc < 0)r
   rx  ry  rP   r   r   r   r.   r/   r0   r1   r   rQ   r   r   r   r    r  r!   r   r   r   r   r   r   r5   r   r"   r   r   r   r   test_noncentral_chisquare/  s>   




z.TestRandomGenerators.test_noncentral_chisquarec              
   C   s  g d}d t g}dd }t||D ]%\}}| j||d | ||d |d t W d    n1 s2w   Y  qdd }g d}| |g d|g d tj	 }|g| }t
|}| t}	| }
d	|
d
< ||
  W d    n1 sww   Y  | dt|	j | t}	| }
d	|
d< ||
  W d    n1 sw   Y  | dt|	j | t}	| }
d|
d< ||
  W d    n1 sw   Y  | dt|	j |   d S )Nr   c                 S   s   | j ddd|dS r  noncentral_fr   r   r   r   r*   ]  rC   z8TestRandomGenerators.test_noncentral_f.<locals>.<lambda>r   c                 S   r]  )Nr  r  r  r   r  )r)   r  r  r  r   r   r   r   r*   e  rC   )r  r   r  r   r  r^  r   r$   z
dfnum <= 0rE   z
dfden <= 0r  r   r  )r
   rx  ry  rP   r   r   r   r   r.   r/   r0   r1   r   rQ   r   r   r   r    r  r  r   r   r   test_noncentral_fV  sL   





z&TestRandomGenerators.test_noncentral_fc              	   C   s(  g d}d t g}dd }t||D ]$\}}| j||d | ||d |d  W d    n1 s1w   Y  qdd }ddg}| |dd	g|d
dg tjd}|g| }t	
|}ddtjfD ],}	| t}
| }|	|d< ||  W d    n1 sw   Y  | dt|
j qa|   d S )Nr   c                 S   r   )N333333?r!  	logseriesr   r   r   r   r*     r   z5TestRandomGenerators.test_logseries.<locals>.<lambda>r   c                 S   r   rQ  r  rR  r   r   r   r*     r   r  r   rN  r   r)   r(   r$   gzp < 0, p >= 1 or p is NaN)r
   rx  ry  rP   r   r   r   r.   r/   r0   r1   nanr   rQ   r   r   r   r    r  )r!   r   r   r   r   r   r   r5   r   _pr"   r   r   r   r   test_logseries  s4   


z#TestRandomGenerators.test_logseriesc                 C   r   )	Nr   c                 S   r   re  binomialr   r   r   r   r*     r   z4TestRandomGenerators.test_binomial.<locals>.<lambda>r   c                 S   r   rk  r  rl  r   r   r   r*     r   rg  rm  r   r   r   r   r   r   test_binomial  ro  z"TestRandomGenerators.test_binomialc              
      sn   g d}d }|D ],\ | j  d  fdd}| |d d |d d W d    n1 s/w   Y  qd S )N))r$   rf  )2   ?)rG   g?)rG   r  rh  rN  c                    s   | j  |dS r   r  r   r  r   r   r*     r   z:TestRandomGenerators.test_binomial_cases.<locals>.<lambda>r   )rP   r   )r!   rV   r   r   r   r  r   test_binomial_cases  s   z(TestRandomGenerators.test_binomial_casesc                 C   s   |  d* tjd}tjd}tjdd }||}||}| || W d    n1 s2w   Y  |  d+ tjd}tjd}tjdd }||}||}| || W d    d S 1 sjw   Y  d S )Nzinfinite loop issue #9493r   c                 S      |  dddS )Ni  rf  rG   r  genr   r   r   foo     z?TestRandomGenerators.test_binomial_specific_issues.<locals>.fooz,issue with midrange value branch #9493/#9734c                 S   r  )Ni-  rf  rG   r  r  r   r   r   r    r  )rP   r   r.   r/   r0   jitr6   rs   )r!   gen1gen2r  gotexpectedr   r   r   test_binomial_specific_issues  s$   



"z2TestRandomGenerators.test_binomial_specific_issues)NNNNre   r   )2rX   rY   rZ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"  r+  r/  r3  r8  r<  rB  rE  rH  rL  rS  rV  r_  rd  rn  r{  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   rd      sf    

(3:'."rd   c                   @   s   e Zd Zdd ZdS )TestGeneratorCachingc                 C   sr   t jd}t jd}tjdd dd}| |d|| | |d|| tt}| |d d d S )	Nr$   c                 S   r[   r\   r^   r(   r   r   r   r*     r_   z=TestGeneratorCaching.test_randomgen_caching.<locals>.<lambda>Tr,   r]   exitcoder   )	r   r.   r/   r0   r1   rs   r   rc   r   )r!   ra   rb   r7   resr   r   r   test_randomgen_caching  s   z+TestGeneratorCaching.test_randomgen_cachingN)rX   rY   rZ   r  r   r   r   r   r    s    r  )r0   numpyr   r   rx  r   r3   r   numba.tests.supportr   r   !numba.np.random.generator_methodsr   numba.np.random.generator_corer   r   r	   numpy.randomr
   r   numba.core.errorsr   r   r   r   r   rc   rd   r  r   r   r   r   <module>   s6             T