a
    
d                     @   s   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 sv0    Y  | dt	|j
 | t}t||tj W d    n1 s0    Y  | dt	|j
 d S )	Nc                   S   s   dS )N     r   r   r   f/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/numba/tests/test_np_randomgen.pytest_32bit_func   s    zBTestHelperFuncs.test_proper_func_provider.<locals>.test_32bit_funcc                   S   s   dS )N@   r   r   r   r   r   test_64bit_func   s    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   s8    

,,z)TestHelperFuncs.test_proper_func_providerc                 C   sl   t jd}dd }tjdd|}| t}|| W d    n1 sL0    Y  | dt|j	 d S )N   c                 S   s   | j ddS )N)r   )locnormalxr   r   r   <lambda>5       z2TestHelperFuncs.test_check_types.<locals>.<lambda>TcachezArgument loc is not one of the expected type(s): [<class 'numba.core.types.scalars.Float'>, <class 'numba.core.types.scalars.Integer'>, <class 'int'>, <class 'float'>])
r   randomdefault_rngnumbanjitr   r   r   r   r   )r   rngpy_func
numba_funcr    r   r   r   test_check_types3   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 sP0    Y  | dt|
j | t"}
||||d |	 W d    n1 s0    Y  | dt|
j | t"}
||||d |	 W d    n1 s0    Y  | dt|
j W d    q1 s"0    Y  qt t jjt t jjt j  }}}	| t"}
|||d ||	 W d    n1 s0    Y  | dt|
j t t jjt t jjt j  }}}	| t"}
||||d |	 W d    n1 s0    Y  | dt|
j | t"}
||||d |	 W d    n1 sN0    Y  | dt|
j | t }
||d	d
t j W d    n1 s0    Y  | dt|
j d S )Nr"   c                 S   s   | j |||ddS )NTlowhighdtypeendpointintegersr'   r5   r6   r7   r   r   r   r(   C   s    z9TestHelperFuncs.test_integers_arg_check.<locals>.<lambda>c                 S   s   | j |||ddS )NFr4   r9   r;   r   r   r   r(   H   s    r5   r6   r7   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-   r.   r/   Ziinfouint8minmaxint8uint16int16uint32r   subTestr   
ValueErrorr   r   r   uint64int64)r   r0   r1   r2   Znumba_func_lowZnumba_func_endpoint_falsecasesr5   r6   r7   r    r   r   r   test_integers_arg_checkA   s~    	222&
2
220z'TestHelperFuncs.test_integers_arg_checkN)__name__
__module____qualname__r!   r3   rL   r   r   r   r   r      s   r   c                  C   sN   t jd} t jd}dd }tjdd|}t |d|| sJJ d S )Nr"   c                 S   s
   |  dS N
   r,   r&   r   r   r   r(      r)   z(test_generator_caching.<locals>.<lambda>Tr*   rQ   )r   r,   r-   r.   r/   Zallclose)nb_rngnp_rngr1   r2   r   r   r   test_generator_caching   s
    rU   c                   @   sp  e Zd Zd\ddZd]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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S )^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rt	|	j
tjst|	trtjj|
|	||d ntj|	|
 | d }| d }|D ]}| || ||  qd S )Nr"   seed)Zmaxulpr7   state)r.   r/   r   r,   r-   r   r1   
isinstanceZndarrayZ
issubdtyper7   ZfloatingfloatZtestingZassert_array_max_ulpZassert_equal__getstate__assertPreciseEqual)r   Zdistribution_funcZbitgen_typerY   	test_size
test_dtypeulp_precnumba_rng_instancenumpy_rng_instance	numba_res	numpy_resZnumba_gen_stateZnumpy_gen_stateZ
_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 )NrX   c                    s
    | j S N)bit_generatorr&   bitgen_funcr   r   r(      r)   z?TestRandomGenerators._test_bitgen_func_parity.<locals>.<lambda>)
r   r,   r-   getattrrh   ctypesrZ   r.   r/   r^   )
r   	func_namerj   rY   rb   rc   Z
numpy_funcre   r2   rd   r   ri   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 sj0    Y  | 	d| dt
|
j qd S )Nz	Argument z$ is not one of the expected type(s):)r   r,   r-   	enumeratecopyr.   r/   r   r   r   r   r   )r   	dist_funcarg_list
valid_argsZinvalid_argsr0   idxZ_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   | S rg   r   r&   r   r   r   r(      r)   zATestRandomGenerators.test_npgen_boxing_unboxing.<locals>.<lambda>)r   r,   r-   r.   r/   r   id)r   rng_instancer2   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   |   S rg   rR   r&   r   r   r   r(      r)   zATestRandomGenerators.test_npgen_boxing_refcount.<locals>.<lambda>c                 S   s   | S rg   r   r&   r   r   r   r(      r)   r"   )
r   r,   r-   r.   r/   gcZcollectsysgetrefcountr   )r   ry   Zno_boxZdo_boxyZref_1Z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 ]B\}}| j||d | || W d    q1 sT0    Y  qd S )Nr   )_func
_func_name)r   r   r	   ziprG   rn   )r   Z
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 sl0    Y  dd }|D ]\}|D ]R}|D ]H}| j
|||d$ | ||d ||d W d    q1 s0    Y  qqqg d}d t	g}dd }|D ]V}|D ]L}| j
||d	& | ||d |t jd W d    n1 sD0    Y  qqd
d }| 
   | j|d d d W d    n1 s0    Y  dd }| |g ddddt jdgdddt jdg d S )NNr   )r?   rQ         c                 S   s   |  ddS Nr   r?   r9   r'   sizer7   r   r   r   r(     r)   z4TestRandomGenerators.test_integers.<locals>.<lambda>r   r_   r`   ra   c                 S   s   | j dd||dS )NrW   rQ   r   r7   r9   r   r   r   r   r(     s    _size_dtype_bitgenc                 S   s   | j dd|tjdS )NFTr   )r:   r   bool_r   r   r   r   r(     s    r   r   c                 S   s   |  tdtdS r   )r:   r   r@   rJ   r   r   r   r   r(      s    r_   r`   c                 S   s   | j |||||dS )Nr5   r6   r   r7   r8   r9   )r'   r5   r6   r   r7   r8   r   r   r   r(   &  s    
r   r"   rW   r"   Tr'   r&   )r   rJ   r   rE   rC   rI   rF   rD   r@   r
   rG   rf   r   rw   r   r   
test_sizesZtest_dtypesbitgen_typesrq   r   r   r   r   r   r   test_integers   sT    
$(
*
&z"TestRandomGenerators.test_integersc              (      s  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g&}d}|D ]`\ }| j	 |d2  fdd}| 
|d d ||d W d    n1 s0    Y  qd S )NrW      r?   r   l   l    l    l   l   ll    l    iii  i  i  rQ   i  i  i            i)r=      r<   c                    s   | j  ||dS Nr   r9   r   r6   r5   r   r   r(   d  s    z:TestRandomGenerators.test_integers_cases.<locals>.<lambda>)r   rI   rJ   rF   r   rD   rE   r@   rC   rG   rf   )r   rK   r   r7   rq   r   r   r   test_integers_cases/  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 sR0    Y  dd }|D ]Z}|D ]P}|D ]F}| j|||d" | ||d || W d    qx1 s0    Y  qxqpqhdd }| |dd	gd
t jgddg d S )Nr   c                 S   s   |   S rg   rR   r   r   r   r   r(   o  r)   z2TestRandomGenerators.test_random.<locals>.<lambda>r   c                 S   s   | j ||dS r   rR   r   r   r   r   r(   t  r)   r   c                 S   s   | j ||dS r   rR   r   r   r   r   r(   }  s    r   r7   r   r&   g        r   r   r   r
   rG   rf   rw   r   r   r   r   test_randomi  s,    
$(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 sR0    Y  dd }|D ]Z}|D ]P}|D ]F}| j|||d" | ||d || W d    qx1 s0    Y  qxqpqhdd }| |dd	gd
t jgddg d S )Nr   c                 S   s   |   S rg   Zstandard_normalr   r   r   r   r(     r)   z;TestRandomGenerators.test_standard_normal.<locals>.<lambda>r   c                 S   s   | j ||dS r   r   r   r   r   r   r(     s    r   c                 S   s   | j ||dS r   r   r   r   r   r   r(     s    r   r7   r   r&   r   r   r   r   r   r   test_standard_normal  s,    
$(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 sR0    Y  dd }|D ]Z}|D ]P}|D ]F}| j|||d" | ||d || W d    qx1 s0    Y  qxqpqhdd }| |g dd	d
t jgg d d S )Nr   c                 S   s   |   S rg   Zstandard_exponentialr   r   r   r   r(     r)   z@TestRandomGenerators.test_standard_exponential.<locals>.<lambda>r   c                 S   s   | j ||dS r   r   r   r   r   r   r(     s    r   c                 S   s   | j |||dS )Nmethodr   r7   r   )r'   r   r   r7   r   r   r   r(     s    r   Zzigr   )r   r&   r   r   r   r   r   r   test_standard_exponential  s,    
$(z.TestRandomGenerators.test_standard_exponentialc                 C   s   g d}t jt jg}d tg}dd }|D ]Z}|D ]P}|D ]F}| j|||d" | ||d || W d    q81 st0    Y  q8q0q(d S )Nr   c                 S   s   | j ||ddS )Ninv)r   r7   r   r   r   r   r   r   r(     s    zDTestRandomGenerators.test_standard_exponential_inv.<locals>.<lambda>r   )r   r   r   r
   rG   rf   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 ]R}|D ]H}| j|||d$ | ||d ||t W d    q81 sv0    Y  q8q0q(dd }| |g dddt jgg d	 d S )
Nr   c                 S   s   | j d||dS )N      @shaper   r7   Zstandard_gammar   r   r   r   r(     s    z:TestRandomGenerators.test_standard_gamma.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr   r   )r'   r   r   r7   r   r   r   r(     s    r   r   r   )r'   r&   r   )r   r   r   r
   rG   rf   adjusted_ulp_precrw   r   r   r   r   test_standard_gamma  s$    (z(TestRandomGenerators.test_standard_gammac                 C   s   g d}d t g}dd }|  " | j|d d td W d    n1 sH0    Y  dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    qf1 s0    Y  qfq^dd }| |g dg d	g d
 d S )Nr   c                 S   s   |   S rg   r$   r   r   r   r   r(     r)   z2TestRandomGenerators.test_normal.<locals>.<lambda>r   c                 S   s   | j dd|dS )N      ?r   r#   scaler   r$   r   r   r   r   r(     r)   r   c                 S   s   | j |||dS Nr   r$   r'   r#   r   r   r   r   r   r(     s    r   r   r   r   r'   r'   r&   r
   rG   rf   r   rw   r   r   r   rq   r   r   r   r   r   test_normal  s(    
$&z TestRandomGenerators.test_normalc                 C   s   g d}d t g}dd }|  " | j|d d td W d    n1 sH0    Y  dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    qf1 s0    Y  qfq^dd }| |g dg d	g d
 d S )Nr   c                 S   s   |   S rg   uniformr   r   r   r   r(     r)   z3TestRandomGenerators.test_uniform.<locals>.<lambda>r   c                 S   s   | j dd|dS )Nr   r   r5   r6   r   r   r   r   r   r   r(     r)   r   c                 S   s   | j |||dS )Nr   r   )r'   r5   r6   r   r   r   r   r(   	  s    r   r   r   r   r   r   r   r   test_uniform  s(    
$&z!TestRandomGenerators.test_uniformc              
   C   s   g d}d t g}dd }|    | j|d d d W d    n1 sF0    Y  dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    qd1 s0    Y  qdq\dd }| |dd	gd
dgddg d S )Nr   c                 S   s   |   S rg   Zexponentialr   r   r   r   r(     r)   z7TestRandomGenerators.test_exponential.<locals>.<lambda>r   c                 S   s   | j d|dS Nr   r   r   r   r   r   r   r   r(     r)   r   c                 S   s   | j ||dS Nr   r   r'   r   r   r   r   r   r(   !  s    r   r   r   r   r'   r&   r
   rG   rf   rw   r   r   r   r   test_exponential  s$    
$&z%TestRandomGenerators.test_exponentialc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |g dg dg d d S )	Nr   c                 S   s   | j dd|dS )Nr   r   r   r   r   gammar   r   r   r   r(   -  s   z1TestRandomGenerators.test_gamma.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr   r   )r'   r   r   r   r   r   r   r(   5  s    r   r   r   r   r   r   r   r   r   r   
test_gamma&  s    &zTestRandomGenerators.test_gammac                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |g dg dg d d S )	Nr   c                 S   s   | j dd|dS )Nr   g      @abr   betar   r   r   r   r(   A  r)   z0TestRandomGenerators.test_beta.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr   r   )r'   r   r   r   r   r   r   r(   I  r)   r   r   r   r   r   r   r   r   	test_beta:  s    &zTestRandomGenerators.test_betac                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |g dg dg d d S )	Nr   c                 S   s   | j dd|dS )Nr=   r   dfnumdfdenr   fr   r   r   r   r(   T  r)   z-TestRandomGenerators.test_f.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr   r   )r'   r   r   r   r   r   r   r(   \  s    r   )rW   r"   r   r   r   r   r   r   r   test_fM  s    &zTestRandomGenerators.test_fc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS Nr=   dfr   Z	chisquarer   r   r   r   r(   h  r)   z5TestRandomGenerators.test_chisquare.<locals>.<lambda>r   c                 S   s   | j ||dS Nr   r   r'   r   r   r   r   r   r(   p  s    r   r   r=   r   r'   r&   r   r   r   r   r   test_chisquarea  s    &z#TestRandomGenerators.test_chisquarec              
   C   s   g d}d t g}dd }|    | j|d d d W d    n1 sF0    Y  dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    qd1 s0    Y  qdq\dd }| |dgd	gd
g d S )Nr   c                 S   s   |   S rg   Zstandard_cauchyr   r   r   r   r(   }  r)   z;TestRandomGenerators.test_standard_cauchy.<locals>.<lambda>r   c                 S   s   | j |dS Nr   r   r   r   r   r   r(     r)   r   c                 S   s   | j |dS r   r   )r'   r   r   r   r   r(     r)   r   r   r&   r   r   r   r   r   test_standard_cauchyu  s$    
$&
z)TestRandomGenerators.test_standard_cauchyc              
   C   s   g d}d t g}dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    q$1 s^0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS N      ?r   r   Zparetor   r   r   r   r(     r)   z2TestRandomGenerators.test_pareto.<locals>.<lambda>r   c                 S   s   | j ||dS Nr   r   r'   r   r   r   r   r   r(     r)   r   r   r"   r   r'   r&   r   r   r   r   r   test_pareto  s    &z TestRandomGenerators.test_paretoc              
   C   s   g d}d t g}dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    q$1 s^0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS r   Zweibullr   r   r   r   r(     r)   z3TestRandomGenerators.test_weibull.<locals>.<lambda>r   c                 S   s   | j ||dS r   r   r   r   r   r   r(     r)   r   r   r"   r   r'   r&   r   r   r   r   r   test_weibull  s    &z!TestRandomGenerators.test_weibullc              
   C   s   g d}d t g}dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    q$1 s^0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS )N      ?r   powerr   r   r   r   r(     r)   z1TestRandomGenerators.test_power.<locals>.<lambda>r   c                 S   s   | j ||dS r   r   r   r   r   r   r(     r)   r   r   r   r   r'   r&   r   r   r   r   r   
test_power  s    &zTestRandomGenerators.test_powerc                 C   s   g d}d t g}dd }|  " | j|d d td W d    n1 sH0    Y  dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    qf1 s0    Y  qfq^dd }| |g dg d	g d
 d S )Nr   c                 S   s   |   S rg   Zlaplacer   r   r   r   r(     r)   z3TestRandomGenerators.test_laplace.<locals>.<lambda>r   c                 S   s   | j dd|dS Nr   r   r   r   r   r   r   r   r(     s    r   c                 S   s   | j |||dS r   r   r   r   r   r   r(     s    r   r   r   r   r   r   r   r   r   r   test_laplace  s(    
$&z!TestRandomGenerators.test_laplacec                 C   s   g d}d t g}dd }|  " | j|d d td W d    n1 sH0    Y  dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    qf1 s0    Y  qfq^dd }| |g dg d	g d
 d S )Nr   c                 S   s   |   S rg   Zlogisticr   r   r   r   r(     r)   z4TestRandomGenerators.test_logistic.<locals>.<lambda>r   c                 S   s   | j dd|dS r   r   r   r   r   r   r(     s    r   c                 S   s   | j |||dS r   r   r   r   r   r   r(     s    r   r   r   r   r   r   r   r   test_logistic  s(    
$&z"TestRandomGenerators.test_logisticc                 C   s   g d}d t g}dd }|  " | j|d d td W d    n1 sH0    Y  dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    qf1 s0    Y  qfq^dd }| |g dg d	g d
 d S )Nr   c                 S   s   |   S rg   Z	lognormalr   r   r   r   r(     r)   z5TestRandomGenerators.test_lognormal.<locals>.<lambda>r   c                 S   s   | j dd|dS )Nr   r   meansigmar   r   r   r   r   r   r(   	  s    r   c                 S   s   | j |||dS )Nr   r   )r'   r   r   r   r   r   r   r(     s    r   r   r   r   r   r   r   r   test_lognormal  s(    
$&z#TestRandomGenerators.test_lognormalc              
   C   s   g d}d t g}dd }|    | j|d d d W d    n1 sF0    Y  dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    qd1 s0    Y  qdq\dd }| |dd	gd
dgddg d S )Nr   c                 S   s   |   S rg   Zrayleighr   r   r   r   r(     r)   z4TestRandomGenerators.test_rayleigh.<locals>.<lambda>r   c                 S   s   | j d|dS r   r   r   r   r   r   r(   $  r)   r   c                 S   s   | j ||dS r   r   r   r   r   r   r(   +  r)   r   r   r   r   r'   r&   r   r   r   r   r   test_rayleigh  s$    
$&z"TestRandomGenerators.test_rayleighc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS r   Z
standard_tr   r   r   r   r(   6  r)   z6TestRandomGenerators.test_standard_t.<locals>.<lambda>r   c                 S   s   | j ||dS r   r   r   r   r   r   r(   >  r)   r   r   r=   r   r'   r&   r   r   r   r   r   test_standard_t/  s    &z$TestRandomGenerators.test_standard_tc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |g dg dg d d S )	Nr   c                 S   s   | j dd|dS )Nr   r   r   r   r   Zwaldr   r   r   r   r(   I  r)   z0TestRandomGenerators.test_wald.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr  r  )r'   r   r   r   r   r   r   r(   Q  s    r  r   r   r   r   r   r   r   	test_waldB  s    &zTestRandomGenerators.test_waldc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS )Nr   pr   Z	geometricr   r   r   r   r(   ]  r)   z5TestRandomGenerators.test_geometric.<locals>.<lambda>r   c                 S   s   | j ||dS Nr  r  r'   r  r   r   r   r   r(   e  r)   r  r   r   r   r'   r&   r   r   r   r   r   test_geometricV  s    &z#TestRandomGenerators.test_geometricc              
   C   s   g d}d t g}dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    q$1 s^0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS )Nr   r   Zzipfr   r   r   r   r(   p  r)   z0TestRandomGenerators.test_zipf.<locals>.<lambda>r   c                 S   s   | j ||dS r   r
  r   r   r   r   r(   w  r)   r   r   r"   r   r'   r&   r   r   r   r   r   	test_zipfi  s    &zTestRandomGenerators.test_zipfc              
   C   s   g d}d t g}dd }|D ]N}|D ]D}| j||d" | ||d |d  W d    q$1 s^0    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   rW   leftmoderightr   
triangularr   r   r   r   r(     s    z6TestRandomGenerators.test_triangular.<locals>.<lambda>r   c                 S   s   | j ||||dS )Nr  r  )r'   r  r  r  r   r   r   r   r(     s    r  )r   r   rW   r   r'   r'   r'   r&   r   r   r   r   r   test_triangular{  s    &z$TestRandomGenerators.test_triangularc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |ddgdd	gd
dg d S )Nr   c                 S   s   | j d|dS )Nr   lamr   Zpoissonr   r   r   r   r(     r)   z3TestRandomGenerators.test_poisson.<locals>.<lambda>r   c                 S   s   | j ||dS )Nr  r  )r'   r  r   r   r   r   r(     r)   r  r   r   r   r'   r&   r   r   r   r   r   test_poisson  s    &z!TestRandomGenerators.test_poissonc                 C   s   g d}d t g}dd }|D ]P}|D ]F}| j||d$ | ||d |d t W d    q$1 s`0    Y  q$qdd }| |g dg dg d d S )	Nr   c                 S   s   | j dd|dS )Nr"   g?nr  r   Znegative_binomialr   r   r   r   r(     s    z=TestRandomGenerators.test_negative_binomial.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr  r  )r'   r  r  r   r   r   r   r(     s    r  )r"   r   r   r   r   r   r   r   r   test_negative_binomial  s    &z+TestRandomGenerators.test_negative_binomialc              
      s   dg}d t g}g d}t|||D ]Z\}} | j|| d0  fdd}| ||d |d d W d    q$1 st0    Y  q$d S )Nr   )r   r"   r=   r   r   _axisc                    s   | j |d}| j| d |S )Nr   axis)r,   shuffler'   r   r7   arrr  r   r   rq     s    z4TestRandomGenerators.test_shuffle.<locals>.dist_funcr   )r
   	itertoolsproductrG   rf   )r   r   r   axesr   r   rq   r   r#  r   test_shuffle  s    z!TestRandomGenerators.test_shufflec                 C   sN   t g }t g }dd }t|}dd }| || ||| | d S )Nc                 S   s   |  | |S rg   r   r'   r"  r   r   r   rq     s    
z:TestRandomGenerators.test_shuffle_empty.<locals>.dist_funcc                   S   s   t jdS Nr"   r   r,   r-   r   r   r   r   r(     r)   z9TestRandomGenerators.test_shuffle_empty.<locals>.<lambda>r   arrayr.   r/   r^   r   r   r   rq   Znb_funcr0   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~0    Y  | 
d	t|j d S )
Nc                 S   s   | j ||d |S Nr  r(  r'   r"  r  r   r   r   rq     s    z:TestRandomGenerators.test_shuffle_check.<locals>.dist_funcr'   r  r      rW   r   r"   r=   )Axis is out of bounds for the given arraydisable_leak_checkrw   r   r-  r,   r-   r   
IndexErrorr.   r/   r   r   r   r   rq   r0   r    r   r   r   test_shuffle_check  s    :z'TestRandomGenerators.test_shuffle_checkc              
   C   s   dg}d t g}g d}t|||D ]V\}}}| j|||d, dd }| ||d |d d W d    q$1 sp0    Y  q$tdd }tj	 }|jd	d
}	|	
 }
|||	 | |	|
 d S )Nr   )r   r"   r=   r  c                 S   s   | j |d}| j|ddS )Nr   r"   r  )r,   permutationr!  r   r   r   rq     s    z8TestRandomGenerators.test_permutation.<locals>.dist_funcr   c                 S   s
   |  |S rg   r<  )r0   r"  r   r   r   r(     r)   z7TestRandomGenerators.test_permutation.<locals>.<lambda>)rQ   r   r   )r
   r$  r%  rG   rf   r.   r/   r   r,   r-   rp   r^   )r   r   r   r&  r   r   r  rq   r0   r"  Z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~0    Y  | 
d	t|j | t,}t	||tg dd
 W d    n1 s0    Y  | 
d	t|j d S )Nc                 S   s   | j ||dS r0  r=  r1  r   r   r   rq     s    zBTestRandomGenerators.test_permutation_exception.<locals>.dist_funcr'   r  r2  r   r"   r=   r4  r;  r5  r8  r   r   r   test_permutation_exception  s$    ::z/TestRandomGenerators.test_permutation_exceptionc                 C   sN   t g }t g }dd }t|}dd }| || ||| | d S )Nc                 S   s
   |  |S rg   r=  r)  r   r   r   rq      s    z>TestRandomGenerators.test_permutation_empty.<locals>.dist_funcc                   S   s   t jdS 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   sj  g d}d t g}dd }t||D ]H\}}| j||d" | ||d |d  W d    q$1 sb0    Y  q$dd }g d}| |g d|g d tj }|g| }t	
|}| t(}	| }
d	|
d
< ||
  W d    n1 s0    Y  | dt|	j | t(}	| }
d|
d< ||
  W d    n1 sB0    Y  | dt|	j |   d S )Nr   c                 S   s   | j dd|dS N      @g      4@r   Znoncentral_chisquarer   r   r   r   r(   /  s    z@TestRandomGenerators.test_noncentral_chisquare.<locals>.<lambda>r   c                 S   s   | j |||dS )Nr   noncr   rC  )r'   r   rE  r   r   r   r   r(   6  s    )rB  r   r   rD  r   r   r"   zdf <= 0r:  r=   nonc < 0)r
   r$  r%  rG   rf   rw   r   r,   r-   r.   r/   r   rH   rp   r   r   r   r6  r   r   r   rq   r   r   rs   r0   rv   r    ru   r   r   r   test_noncentral_chisquare(  s6    $


&(z.TestRandomGenerators.test_noncentral_chisquarec              
   C   s  g d}d t g}dd }t||D ]J\}}| j||d$ | ||d |d t W d    q$1 sd0    Y  q$dd }g d}| |g d|g d tj	 }|g| }t
|}| t(}	| }
d	|
d
< ||
  W d    n1 s0    Y  | dt|	j | t(}	| }
d	|
d< ||
  W d    n1 sD0    Y  | dt|	j | t(}	| }
d|
d< ||
  W d    n1 s0    Y  | dt|	j |   d S )Nr   c                 S   s   | j ddd|dS rA  Znoncentral_fr   r   r   r   r(   V  s    z8TestRandomGenerators.test_noncentral_f.<locals>.<lambda>r   c                 S   s   | j ||||dS )Nr   r   rE  r   rI  )r'   r   r   rE  r   r   r   r   r(   ^  s    )rB  r   rB  r   rJ  r  r   r"   z
dfnum <= 0r=   z
dfden <= 0r:  r   rF  )r
   r$  r%  rG   rf   r   rw   r   r,   r-   r.   r/   r   rH   rp   r   r   r   r6  rG  r   r   r   test_noncentral_fO  sB    $


&((z&TestRandomGenerators.test_noncentral_fc              	   C   s(  g d}d t g}dd }t||D ]H\}}| j||d" | ||d |d  W d    q$1 sb0    Y  q$dd }ddg}| |dd	g|d
dg tjd}|g| }t	
|}ddtjfD ]X}	| t(}
| }|	|d< ||  W d    n1 s0    Y  | dt|
j q|   d S )Nr   c                 S   s   | j d|dS )N333333?r   Z	logseriesr   r   r   r   r(     s    z5TestRandomGenerators.test_logseries.<locals>.<lambda>r   c                 S   s   | j ||dS r  rM  r  r   r   r   r(     s    rL  r   r  r   r'   r&   r"   gzp < 0, p >= 1 or p is NaN)r
   r$  r%  rG   rf   rw   r   r,   r-   r.   r/   nanr   rH   rp   r   r   r   r6  )r   r   r   rq   r   r   rs   r0   rv   _pr    ru   r   r   r   test_logseries}  s.    $

&z#TestRandomGenerators.test_logseries)NNNNrW   )r"   )/rM   rN   rO   rf   rn   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r'  r/  r9  r>  r?  r@  rH  rK  rP  r   r   r   r   rV      s^      
(
3:'.rV   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   s
   |  dS rP   rR   r&   r   r   r   r(     r)   z=TestGeneratorCaching.test_randomgen_caching.<locals>.<lambda>Tr*   rQ   exitcoder   )	r   r,   r-   r.   r/   r^   r   rU   r   )r   rS   rT   r2   resr   r   r   test_randomgen_caching  s    z+TestGeneratorCaching.test_randomgen_cachingN)rM   rN   rO   rT  r   r   r   r   rQ    s   rQ  )r.   numpyr   r|   r$  r{   r   Znumba.tests.supportr   r   Z!numba.np.random.generator_methodsr   Znumba.np.random.generator_corer   r   r	   Znumpy.randomr
   r   Znumba.core.errorsr   r   r   r   r   rU   rV   rQ  r   r   r   r   <module>   s0   {        