U
    9%e                     @   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 5 Q R X | dt	|j
 | t}t||tj W 5 Q R X | dt	|j
 d S )	Nc                   S   s   dS )N     r   r   r   \/var/www/html/Darija-Ai-API/env/lib/python3.8/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   sX   t jd}dd }tjdd|}| t}|| W 5 Q R X | 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 5 Q R X | dt|
j | t}
||||d |	 W 5 Q R X | dt|
j | t}
||||d |	 W 5 Q R X | dt|
j W 5 Q R X qt t jjt t jjt j  }}}	| t}
|||d ||	 W 5 Q R X | dt|
j t t jjt t jjt j  }}}	| t}
||||d |	 W 5 Q R X | dt|
j | t}
||||d |	 W 5 Q R X | dt|
j | t}
||d	d
t j W 5 Q R X | dt|
j d S )Nr!   c                 S   s   | j |||ddS )NTlowhighdtypeendpointintegersr&   r4   r5   r6   r   r   r   r'   C   s    z9TestHelperFuncs.test_integers_arg_check.<locals>.<lambda>c                 S   s   | j |||ddS )NFr3   r8   r:   r   r   r   r'   H   s    r4   r5   r6   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   r/   r0   r1   Znumba_func_lowZnumba_func_endpoint_falsecasesr4   r5   r6   r   r   r   r   test_integers_arg_checkA   s    	 
 
z'TestHelperFuncs.test_integers_arg_checkN)__name__
__module____qualname__r    r2   rK   r   r   r   r   r      s   r   c                  C   sN   t jd} t jd}dd }tjdd|}t |d|| sJtd S )Nr!   c                 S   s
   |  dS N
   r+   r%   r   r   r   r'      r(   z(test_generator_caching.<locals>.<lambda>Tr)   rP   )r   r+   r,   r-   r.   ZallcloseAssertionError)nb_rngnp_rngr0   r1   r   r   r   test_generator_caching   s
    rU   c                   @   s  e Zd Zd`ddZdad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S )bTestRandomGeneratorsN   c                 C   s   t |}|d krd}|d k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maxulpr6   state)r-   r.   r   r+   r,   r
   r0   
isinstanceZndarrayZ
issubdtyper6   Zfloatingfloat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,   getattrri   ctypesrZ   r-   r.   r_   )
r   	func_namerk   rY   rc   rd   Z
numpy_funcrf   r1   re   r   rj   r   _test_bitgen_func_parity   s    z-TestRandomGenerators._test_bitgen_func_parityc              
   C   s   t j }t|D ]h\}}| }|| ||< |g| }t|}	| t}
|	|  W 5 Q R X | 	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_argsr/   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 rh   r   r%   r   r   r   r'      r(   zATestRandomGenerators.test_npgen_boxing_unboxing.<locals>.<lambda>)r   r+   r,   r-   r.   r   id)r   rng_instancer1   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 rh   rQ   r%   r   r   r   r'      r(   zATestRandomGenerators.test_npgen_boxing_refcount.<locals>.<lambda>c                 S   s   | S rh   r   r%   r   r   r   r'      r(   r!   )
r   r+   r,   r-   r.   gcZcollectsysgetrefcountr   )r   rz   Zno_boxZdo_boxyZref_1Zref_2r   r   r   test_npgen_boxing_refcount   s    


z/TestRandomGenerators.test_npgen_boxing_refcountc              
   C   sR   dddg}t ttg}t||D ].\}}| j||d | || W 5 Q R X qd S )Nr   r   r   )_func
_func_name)r   r   r   ziprF   ro   )r   Z
func_namesfuncsr   r   r   r   r   test_bitgen_funcs   s
    

z&TestRandomGenerators.test_bitgen_funcsc                 C   s  d dddg}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 5 Q R X dd }|D ]H}|D ]>}|D ]4}| j
|||d	 | ||d ||d W 5 Q R X qqzqrd dddg}d t	g}d
d }|D ]>}|D ]4}| j
||d | ||d |t jd W 5 Q R X qqdd }| 
  | j|d d d W 5 Q R X dd }| |dddddgdddt jdgdddt jdg d S )Nr   r>   rP         c                 S   s   |  ddS Nr   r>   r8   r&   sizer6   r   r   r   r'     r(   z4TestRandomGenerators.test_integers.<locals>.<lambda>r   r`   ra   rb   c                 S   s   | j dd||dS )NrW   rP   r   r6   r8   r   r   r   r   r'     s    _size_dtype_bitgenc                 S   s   | j dd|tjdS )NFTr   )r9   r   bool_r   r   r   r   r'     s    r   r   c                 S   s   |  tdtdS r   )r9   r   r?   rI   r   r   r   r   r'      s    r`   ra   c                 S   s   | j |||||dS )N)r4   r5   r   r6   r7   r8   )r&   r4   r5   r   r6   r7   r   r   r   r'   &  s    
 r4   r5   r   r6   r7   r!   rW   r!   Tr&   r%   )r   rI   r   rD   rB   rH   rE   rC   r?   r	   rF   rg   r   rx   r   r   
test_sizesZtest_dtypesbitgen_typesrr   r   r   r   r   r   r   test_integers   sh       
       
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\ }| j	 |d(  fdd}| 
|d d ||d W 5 Q R X qd S )NrW      r>   r   l   l    l    l   l   ll    l    iii  i  i  rP   i  i  i            i)r<      r;   c                    s   | j  ||dS Nr   r8   r   r5   r4   r   r   r'   d  s    z:TestRandomGenerators.test_integers_cases.<locals>.<lambda>)r   rH   rI   rE   r   rC   rD   r?   rB   rF   rg   )r   rJ   r   r6   rr   r   r   r   test_integers_cases/  sb    





































0   z(TestRandomGenerators.test_integers_casesc                 C   s   d dddg}t jt jg}d tg}dd }|   | j|d d d W 5 Q R X dd }|D ]F}|D ]<}|D ]2}| j|||d | ||d || W 5 Q R X qhq`qXd	d }| |d
dgdt jgddg d S )Nr   r   r   c                 S   s   |   S rh   rQ   r   r   r   r   r'   o  r(   z2TestRandomGenerators.test_random.<locals>.<lambda>r   c                 S   s   | j ||dS r   rQ   r   r   r   r   r'   t  r(   r   c                 S   s   | j ||dS r   rQ   r   r   r   r   r'   }  s    r   r6   r   r%   g        r   r   r   r	   rF   rg   rx   r   r   r   r   test_randomi  s2    
   z TestRandomGenerators.test_randomc                 C   s   d dddg}t jt jg}d tg}dd }|   | j|d d d W 5 Q R X dd }|D ]F}|D ]<}|D ]2}| j|||d | ||d || W 5 Q R X qhq`qXd	d }| |d
dgdt jgddg d S )Nr   r   r   c                 S   s   |   S rh   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   r6   r   r%   r   r   r   r   r   r   test_standard_normal  s2    
   z)TestRandomGenerators.test_standard_normalc                 C   s   d dddg}t jt jg}d tg}dd }|   | j|d d d W 5 Q R X dd }|D ]F}|D ]<}|D ]2}| j|||d | ||d || W 5 Q R X qhq`qXd	d }| |d
ddgddt jgdddg d S )Nr   r   r   c                 S   s   |   S rh   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   r6   r   )r&   r   r   r6   r   r   r   r'     s    r   r   r6   zigr   r   r%   r   r   r   r   r   test_standard_exponential  s2    
  
 z.TestRandomGenerators.test_standard_exponentialc                 C   sx   d dddg}t jt jg}d tg}dd }|D ]F}|D ]<}|D ]2}| j|||d | ||d || W 5 Q R X q<q4q,d S )Nr   r   r   c                 S   s   | j ||ddS )Ninv)r   r6   r   r   r   r   r   r   r'     s    zDTestRandomGenerators.test_standard_exponential_inv.<locals>.<lambda>r   )r   r   r   r	   rF   rg   r   r   r   r   test_standard_exponential_inv  s      z2TestRandomGenerators.test_standard_exponential_invc                 C   s   d dddg}t jt jg}d tg}dd }|D ]H}|D ]>}|D ]4}| j|||d | ||d ||t W 5 Q R X q<q4q,dd }| |dd	d
gddt jgdddg d S )Nr   r   r   c                 S   s   | j d||dS )N      @shaper   r6   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   r6   r   r   r   r'     s    r   r   r6   r   r   r&   r%   r   )r   r   r   r	   rF   rg   adjusted_ulp_precrx   r   r   r   r   test_standard_gamma  s*      
 z(TestRandomGenerators.test_standard_gammac                 C   s   d dddg}d t g}dd }|   | j|d d td W 5 Q R X dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X qVqNd	d }| |d
ddgdddgdddg d S )Nr   r   r   c                 S   s   |   S rh   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%   r	   rF   rg   r   rx   r   r   r   rr   r   r   r   r   r   test_normal  s.    
   z TestRandomGenerators.test_normalc                 C   s   d dddg}d t g}dd }|   | j|d d td W 5 Q R X dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X qVqNd	d }| |d
ddgdddgdddg d S )Nr   r   r   c                 S   s   |   S rh   uniformr   r   r   r   r'     r(   z3TestRandomGenerators.test_uniform.<locals>.<lambda>r   c                 S   s   | j dd|dS )Nr   r   r4   r5   r   r   r   r   r   r   r'     r(   r   c                 S   s   | j |||dS )Nr   r   )r&   r4   r5   r   r   r   r   r'   	  s    r4   r5   r   r   r   r   r&   r%   r   r   r   r   r   test_uniform  s.    
   z!TestRandomGenerators.test_uniformc                 C   s   d dddg}d t g}dd }|   | j|d d d W 5 Q R X dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X qTqLd	d }| |d
dgddgddg d S )Nr   r   r   c                 S   s   |   S rh   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	   rF   rg   rx   r   r   r   r   test_exponential  s*    
   z%TestRandomGenerators.test_exponentialc                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   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   r   r   r   
test_gamma&  s"       zTestRandomGenerators.test_gammac                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   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%   r   r   r   r   r   	test_beta:  s"       zTestRandomGenerators.test_betac                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   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   r   r   rW   r!   r   r&   r%   r   r   r   r   r   test_fM  s"       zTestRandomGenerators.test_fc                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|   | j|d d d W 5 Q R X dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X qTqLd	d }| |d
gdgdg d S )Nr   r   r   c                 S   s   |   S rh   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   d dddg}d t g}dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|   | j|d d td W 5 Q R X dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X qVqNd	d }| |d
ddgdddgdddg d S )Nr   r   r   c                 S   s   |   S rh   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   r   r   r   test_laplace  s.    
   z!TestRandomGenerators.test_laplacec                 C   s   d dddg}d t g}dd }|   | j|d d td W 5 Q R X dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X qVqNd	d }| |d
ddgdddgdddg d S )Nr   r   r   c                 S   s   |   S rh   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%   r   r   r   r   r   test_logistic  s.    
   z"TestRandomGenerators.test_logisticc                 C   s   d dddg}d t g}dd }|   | j|d d td W 5 Q R X dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X qVqNd	d }| |d
ddgdddgdddg d S )Nr   r   r   c                 S   s   |   S rh   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%   r   r   r   r   r   test_lognormal  s.    
   z#TestRandomGenerators.test_lognormalc                 C   s   d dddg}d t g}dd }|   | j|d d d W 5 Q R X dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X qTqLd	d }| |d
dgddgddg d S )Nr   r   r   c                 S   s   |   S rh   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   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   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%   r   r   r   r   r   	test_waldB  s"       zTestRandomGenerators.test_waldc                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]:}|D ]0}| j||d | ||d |d  W 5 Q R X q(q dd }| |dd	d
dgddddgddddg d S )Nr   r   r   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  r   r   r   rW   r   r&   r%   r   r   r   r   r   test_triangular{  s       
 
z$TestRandomGenerators.test_triangularc                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	gd
dgddg d S )Nr   r   r   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   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   c                 S   s   | j dd|dS Nr!   皙?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   r   r   r   test_negative_binomial  s"       z+TestRandomGenerators.test_negative_binomialc              
      sr   dg}d t g}dddg}t|||D ]F\}} | j|| d&  fdd}| ||d |d d W 5 Q R X q&d S )Nr   r   r!   r<   r   r   _axisc                    s   | j |d}| j| d |S )Nr   axis)r+   shuffler&   r   r6   arrr  r   r   rr     s    z4TestRandomGenerators.test_shuffle.<locals>.dist_func)r	   	itertoolsproductrF   rg   )r   r   r   axesr   r   rr   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 rh   r  r&   r!  r   r   r   rr     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   rr   Znb_funcr/   r   r   r   test_shuffle_empty  s    


z'TestRandomGenerators.test_shuffle_emptyc              	   C   s   |    dd }| |ddgtdddgdgddg tjd	}| t$}t	||tdddgd
 W 5 Q R X | 
dt|j d S )Nc                 S   s   | j ||d |S Nr  r'  r&   r!  r  r   r   r   rr     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_checkrx   r   r,  r+   r,   r   
IndexErrorr-   r.   r   r   r   r   rr   r/   r   r   r   r   test_shuffle_check  s     (z'TestRandomGenerators.test_shuffle_checkc              
   C   s   dg}d t g}dddddg}t|||D ]B\}}}| j|||d" dd	 }| ||d |d d W 5 Q R X 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   rr     s    z8TestRandomGenerators.test_permutation.<locals>.dist_funcc                 S   s
   |  |S rh   r:  )r/   r!  r   r   r   r'     r(   z7TestRandomGenerators.test_permutation.<locals>.<lambda>)rP   r   r   )r	   r#  r$  rF   rg   r-   r.   r   r+   r,   rq   r_   )r   r   r   r%  r   r   r  rr   r/   r!  Zarr_cpyr   r   r   test_permutation  s*      

z%TestRandomGenerators.test_permutationc              	   C   s   |    dd }| |ddgtdddgdgddg tjd	}| t$}t	||tdddgd
 W 5 Q R X | 
dt|j | t$}t	||tdddgd W 5 Q R X | 
dt|j d S )Nc                 S   s   | j ||dS r/  r;  r0  r   r   r   rr     s    zBTestRandomGenerators.test_permutation_exception.<locals>.dist_funcr&   r  r   r1  rW   r   r!   r<   r2  r9  r3  r6  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 rh   r;  r(  r   r   r   rr      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   s6  d dddg}d t g}dd }t||D ]4\}}| j||d | ||d |d  W 5 Q R X q(dd }dd	d
g}| |dddg|dddg tj }|g| }t	
|}| t}	| }
d|
d< ||
  W 5 Q R X | dt|	j | t}	| }
d|
d< ||
  W 5 Q R X | dt|	j |   d S )Nr   r   r   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   rA  )r&   r   rB  r   r   r   r   r'   6  s    r@  r   r   r   rB  r   r&   r%   r   r!   zdf <= 0r8  r<   nonc < 0)r	   r#  r$  rF   rg   rx   r   r+   r,   r-   r.   r   rG   rq   r   r   r   r4  r   r   r   rr   r   r   rt   r/   rw   r   rv   r   r   r   test_noncentral_chisquare(  s<      
 


z.TestRandomGenerators.test_noncentral_chisquarec              
   C   s~  d dddg}d t g}dd }t||D ]6\}}| j||d | ||d |d t W 5 Q R X q(dd }dd	dd
g}| |ddddg|ddddg tj	 }|g| }t
|}| t}	| }
d|
d< ||
  W 5 Q R X | dt|	j | t}	| }
d|
d< ||
  W 5 Q R X | dt|	j | t}	| }
d|
d< ||
  W 5 Q R X | dt|	j |   d S )Nr   r   r   c                 S   s   | j ddd|dS r?  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   rB  r   rF  )r&   r   r   rB  r   r   r   r   r'   ^  s    r@  r   r   r   r   rB  r   r&   r%   r   r!   z
dfnum <= 0r<   z
dfden <= 0r8  r   rC  )r	   r#  r$  rF   rg   r   rx   r   r+   r,   r-   r.   r   rG   rq   r   r   r   r4  rD  r   r   r   test_noncentral_fO  sH       



z&TestRandomGenerators.test_noncentral_fc              
   C   s  d dddg}d t g}dd }t||D ]4\}}| j||d | ||d |d  W 5 Q R X q(dd }dd	g}| |d
dg|ddg tjd}|g| }t	
|}ddtjfD ]D}	| t}
| }|	|d< ||  W 5 Q R X | dt|
j q|   d S )Nr   r   r   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  rI  r  r   r   r   r'     s    rH  r   r  r   r&   r%   r!   gzp < 0, p >= 1 or p is NaN)r	   r#  r$  rF   rg   rx   r   r+   r,   r-   r.   nanr   rG   rq   r   r   r   r4  )r   r   r   rr   r   r   rt   r/   rw   _pr   rv   r   r   r   test_logseries}  s4       

z#TestRandomGenerators.test_logseriesc                 C   s   d dddg}d t g}dd }|D ]<}|D ]2}| j||d | ||d |d t W 5 Q R X q(q dd }| |dd	d
gdddgdddg d S )Nr   r   r   c                 S   s   | j dd|dS r  Zbinomialr   r   r   r   r'     s    z4TestRandomGenerators.test_binomial.<locals>.<lambda>r   c                 S   s   | j |||dS r  rM  r  r   r   r   r'     s    r  r  r   r!   r   r   r&   r%   r   r   r   r   r   test_binomial  s"       z"TestRandomGenerators.test_binomialc              
      s^   ddddg}d }|D ]D\ | j  d(  fdd}| |d d |d d W 5 Q R X qd S )	N)r!   r  )2   ?)r>   g?)r>   rP  r  r  c                    s   | j  |dS r   rM  r   rQ  r   r   r'     s    z:TestRandomGenerators.test_binomial_cases.<locals>.<lambda>r   )rF   rg   )r   rJ   r   rr   r   rQ  r   test_binomial_cases  s       z(TestRandomGenerators.test_binomial_cases)NNNNrW   )r!   )1rL   rM   rN   rg   ro   rx   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&  r.  r7  r<  r=  r>  rE  rG  rL  rN  rR  r   r   r   r   rV      sf          
(
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 rO   rQ   r%   r   r   r   r'     r(   z=TestGeneratorCaching.test_randomgen_caching.<locals>.<lambda>Tr)   rP   exitcoder   )	r   r+   r,   r-   r.   r_   r   rU   r   )r   rS   rT   r1   resr   r   r   test_randomgen_caching  s    z+TestGeneratorCaching.test_randomgen_cachingN)rL   rM   rN   rV  r   r   r   r   rS    s   rS  )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   rS  r   r   r   r   <module>   s0   {        2