o
    Je                    @   sH  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	m
Z
mZmZmZmZmZmZmZ d dlmZmZmZmZ ee Zd ddddd	d
dddddddddddg dddddddddgZejdddgddd ZG dd dZG d d! d!ZG d"d# d#ZG d$d% d%ZG d&d' d'ZG d(d) d)Z G d*d+ d+Z!G d,d- d-Z"ej#j$ed.d/G d0d1 d1Z%G d2d3 d3Z&ej#'d4ed5d6 Z(d7d8 Z)d9d: Z*d;d< Z+ej#'d=d>d>ggej#'dddgd?d@ Z,ej#'dAdBdCgdDdE Z-ej#'dAdBdCgej#'dFdGdHgej#'dIej.ejgdJdK Z/dLdM Z0dS )N    N)LinAlgError)
assert_assert_raisesassert_equalassert_allcloseassert_warnsassert_no_warningsassert_array_equalassert_array_almost_equalsuppress_warningsIS_WASM)	GeneratorMT19937SeedSequenceRandomState
   Z@bb1636883c2707b51c5b7fc26c6927af4430f2e0785a8c7bc886337f919f9edf	   )
key_sha256posZ@ff682ac12bb140f2d72fba8d3506cf4e46817a0db27aae1683867629031d8d55iV  )seedstepsinitialjumpedi$<i8  Z@16b791a1e04886ccbbb4d448d6ff791267dc458ae599475d08d5cced29d11614i7  Z@a0110a2cf23b56be0feaed8f787a7fc84bef0cb5623003d75b26bdfa1c18002ci  )i|2iEm:iS43i5  i  Z@d306cf01314d51bd37892d874308200951a35265ede54d200f1e065004c3e9eai  Z@0e00ab449f01a5195a83b4aee0dfbc2ce8d46466a640b92e33977d2e42f777f8i  moduleTF)scopeparamsc                 C   s   | j S N)param)request r   w/home/seandotau/au.memorygallery.club/gallery/lib/python3.10/site-packages/numpy/random/tests/test_generator_mt19937.pyendpoint'   s   r!   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )TestSeedc                 C   s<   t td}t|dd t td}t|dd d S )Nr           D  )r   r   r   integersselfsr   r   r    test_scalar-   s   zTestSeed.test_scalarc                 C   s   t ttd}t|dd t ttd}t|dd t tdg}t|dd t tdg}t|dd d S )Nr   r#   i  r   r$   r%   r&   )r   r   ranger   r'   nparanger(   r   r   r    
test_array3   s   zTestSeed.test_arrayc                 C   s    t td}t|dd d S )Nr      iz)r   r   r   
random_rawr(   r   r   r    test_seedsequence=   s   zTestSeed.test_seedsequencec                 C   s   t ttd t ttd d S )N      r   	TypeErrorr   
ValueErrorr)   r   r   r    test_invalid_scalarA   s   zTestSeed.test_invalid_scalarc                 C   s0   t ttdg t ttdg t ttg d d S )Nr3   r4   )r0           r5   r8   r   r   r    test_invalid_arrayF   s   zTestSeed.test_invalid_arrayc                 C   s   t ttt d S r   )r   r7   r   r   r8   r   r   r    test_noninstantized_bitgenL   s   z#TestSeed.test_noninstantized_bitgenN)	__name__
__module____qualname__r+   r/   r2   r9   r<   r=   r   r   r   r    r"   ,   s    
r"   c                   @   s   e Zd Zdd Zdd ZdS )TestBinomialc                 C   sB   t jddd}dD ]}ttd|dk tt||| q	d S )N   intdtype)r         ?r0   r   )r-   zerosr   randombinomialr	   )r)   rG   pr   r   r    test_n_zeroQ   s
   zTestBinomial.test_n_zeroc                 C   s   t ttjdtj d S )Nr0   )r   r7   rH   rI   r-   nanr8   r   r   r    test_p_is_nanZ   s   zTestBinomial.test_p_is_nanN)r>   r?   r@   rK   rM   r   r   r   r    rA   P   s    	rA   c                   @   sL   e Z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S )TestMultinomialc                 C   s   t dddg d S )Nd   皙?皙?rH   multinomialr8   r   r   r    
test_basic`      zTestMultinomial.test_basicc                 C   s   t dg d d S )NrO   )rP   rQ           rV   rV   rR   r8   r   r   r    test_zero_probabilityc   rU   z%TestMultinomial.test_zero_probabilityc                 C   sZ   t dtdd  kodk n   tddd}t td|k t t|dk  d S )Nr4      )r   rH   r'   r-   allr)   xr   r   r    test_int_negative_intervalf   s   $z*TestMultinomial.test_int_negative_intervalc                 C   s   ddg}t td|tdjd t td|tdjd t td|tdjd t td|ddgjd t td|djd t td|tdjd tttjd|t	d d S )NrF   r0   r0   rB   rB   rB   rB   rB   rB   rB   )
r   rH   rS   r-   uint32shapearrayr   r6   floatr)   rJ   r   r   r    	test_sizel   s   zTestMultinomial.test_sizec                 C   s,   t ttjdddg t ttjdddg d S )NrO   皙?rP   皙?r   r7   rH   rS   r8   r   r   r    test_invalid_probz   s   z!TestMultinomial.test_invalid_probc                 C   s2   t ttjdddg t ttjdgd ddg d S )Nr4   rQ   rP   r   rj   r8   r   r   r    test_invalid_n~   s   zTestMultinomial.test_invalid_nc                 C   sx   t d}|t |dd d  }|dd d }ttd}|jd|d}ttd}|jdt |d}t|| d S )Ng      .@r0      ۠iUrO   )pvals)r-   r.   sumr   r   rS   ascontiguousarrayr	   )r)   rJ   ro   rH   
non_contigcontigr   r   r    test_p_non_contiguous   s   
z%TestMultinomial.test_p_non_contiguousc                 C   sp   t jg dt jd}||  }ttd}d}tjt|d |	d| W d    d S 1 s1w   Y  d S )N)
Gz?ru   &.>rv   rv   rv   rv   rv   rv   rv   rD   rn   z-[\w\s]*pvals array is cast to 64-bit floatingmatchr0   )
r-   rc   float32rp   r   r   pytestraisesr7   rS   )r)   r\   ro   rH   rx   r   r   r    test_multinomial_pvals_float32   s   
"z.TestMultinomial.test_multinomial_pvals_float32N)r>   r?   r@   rT   rW   r]   rf   rk   rl   rt   r|   r   r   r   r    rN   _   s    
rN   c                   @   s   e Zd Zdd Zdd Zejdddgdd	 Zejd
g dejdddgejdg ddd Z	dd Z
dd Zdd ZdS )TestMultivariateHypergeometricc                 C   
   d| _ d S )Ni_ r   r8   r   r   r    setup_method      
z+TestMultivariateHypergeometric.setup_methodc                 C   s   t ttjdd t ttjg dd t ttjg dd t ttjg dd t ttjg d t ttjdd	gd
dd ttj}|j}||jj	 }t ttj|d d	gd
dd d S )Nr      )rB   rm   r   r4   )r4   rB   rm   rB   r0   iɚ;e   rY   	marginalsrO   count)
r   r7   rH   multivariate_hypergeometricr-   iinfoint64maxrE   itemsize)r)   Z
int64_infoZ	max_int64Zmax_int64_indexr   r   r    test_argument_validation   s0   z7TestMultivariateHypergeometric.test_argument_validationmethodr   r   c                 C   s
  t t| j}|jg dd|d}t|g d |jg d|d}t|g  |jg dd|d}t|tjdtjd |jg dd|d}t|g d |jg d	d
|d}t|g d g d}|j|t||d}t|| |jg ddd
|d}t|g dgd
  d S )Nr   r   r   r   r   r0   sizer   )r0   r   rD   r0   rB   rm   )r   r   r   rm   )rm   r   r   )r0   r0   r   r0   r0   rm   r   rY      )	r   r   r   r   r	   r-   emptyr   rp   )r)   r   rH   r\   colorsr   r   r    test_edge_cases   s(   

z.TestMultivariateHypergeometric.test_edge_casesnsample)      -   7   r   )rY   rB   rm   iI c                 C   s   t t| j}tg d}|j||||d}t|tr#|f|j }n||j }t	|j| t
|dk  t
||k  t|jddtj||td t|trj|dkrlt|jdd|| |  dd	d
 d S d S d S )N)r   rY      r   r   r   r4   axis)Z
fill_valuerE   順 MbP?{Gzt?)rtolZatol)r   r   r   r-   rc   r   
isinstancerC   rb   r   r   rZ   r	   rp   fullr   mean)r)   r   r   r   rH   r   sampleexpected_shaper   r   r    test_typical_cases   s(   



z1TestMultivariateHypergeometric.test_typical_casesc                 C   sZ   t t| j}|jg ddddd}tg dg dg dg dg dg}t|| d S )Nr   rY   r   r   )rB   r0   rB   r0   r0   rm   rB   r   rm   r   r   r   r   r-   rc   r	   r)   rH   r   expectedr   r   r    test_repeatability1   s   
z2TestMultivariateHypergeometric.test_repeatability1c                 C   sZ   t t| j}|jg ddddd}tg dg dg dg dg d	g}t|| d S )
Nr      2   r   rY   r   r   )r         )      r   )r         )r      r   r   r   r   r   r    test_repeatability2     
z2TestMultivariateHypergeometric.test_repeatability2c                 C   sZ   t t| j}|jg ddddd}tg dg dg dg dg d	g}t|| d S )
Nr   r   rY   r   r   )rB   rm   r   )rY   rm   r   )rB   rY   rY   )r0   rY      r   r   r   r   r    test_repeatability3  r   z2TestMultivariateHypergeometric.test_repeatability3N)r>   r?   r@   r   r   rz   markparametrizer   r   r   r   r   r   r   r   r    r}      s    !
"r}   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestSetStatec                 C   sT   d| _ tt| j | _| jj| _| jj| _| jd | jd d | jd d f| _d S )NIbit_generatorstatekeyr   )r   r   r   rgr   r   Zlegacy_stater8   r   r   r    r     s   


zTestSetState.setup_methodc                 C   s<   | j jdd}| j| j_| j jdd}tt||k d S Nrm   r   )r   standard_normalr   r   r   r-   rZ   )r)   oldnewr   r   r    test_gaussian_reset&  s   
z TestSetState.test_gaussian_resetc                 C   sL   | j   | jj}| j jdd}|| j_| j jdd}tt||k d S r   )r   r   r   r   r   r-   rZ   )r)   r   r   r   r   r   r     test_gaussian_reset_in_media_res-  s   
z-TestSetState.test_gaussian_reset_in_media_resc                 C   s   | j dd d S NrF   )r   negative_binomialr8   r   r   r    test_negative_binomial8  s   z#TestSetState.test_negative_binomialN)r>   r?   r@   r   r   r   r   r   r   r   r    r     s
    	r   c                   @   s\  e Zd ZejZeejej	ej
ejejejejejg	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ejddeg dfdeg dfdeg dfgdd Z d d! Z!d"d# Z"d$d% Z#d&d' Z$d(d) Z%d*d+ Z&d,d- Z'ejj(ejd.d/d0ejd1fd/d2ej	d3fd4d5ej
d6fd7d8ejd9fgd:d; Z)d<S )=TestIntegersc                 C   s   t t| jd|td d S Nr0   r!   rE   )r   r6   rfuncrd   )r)   r!   r   r   r    test_unsupported_typeE  s   z"TestIntegers.test_unsupported_typec              	   C   s>  | j D ]}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}tt| j|d |||d tt| j||d ||d tt| j||||d tt| jdd||d tt| j|d g|||d tt| j|g|d g||d tt| j|g|g||d tt| jddg||d tt| j|d g|g||d qd S Nr   rB   r0   r   	itypeboolr-   r   minr   r   r7   r   r)   r!   dtlbndubndr   r   r    test_bounds_checkingH  s@   
z!TestIntegers.test_bounds_checkingc              	   C   s   | j D ]_}|tu rdnt|j}|tu rdnt|j|  }tt| j|d gd |gd ||d tt| j|gd |d gd ||d tt| j||gd ||d tt| jdgd d||d qd S r   r   r   r   r   r    test_bounds_checking_arraya  s    
z'TestIntegers.test_bounds_checking_arrayc              	   C   s.  | j D ]}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}| }|d }t| j||| d||d| t| j|g|| d||d| |}t| j||| d||d| t| j||| gd||d| || d }t| j||| d||d| t| j|g|| gd||d| qd S )Nr   rB   r0   r#   r   r!   rE   r   r   r-   r   r   r   r   r   )r)   r!   r   r   r   Zis_opentgtr   r   r    test_rng_zero_and_extremeso  sN   
z'TestIntegers.test_rng_zero_and_extremesc                 C   s  d}| j D ]}|tu rdnt|j}|tu rdnt|jd }|r'|d n|}|d }t| j|g|d g||d| t| j|g| |d g| |d| t| j|g| |d g| ||d| |}t| j|g|d g||d| t| j|g| |d g| |d| t| j|g| |d g| ||d| || d }t| j|g|d g||d| t| j|g| |d g| |d| t| j|g| |d g| ||d| qd S )Nr#   r   rB   r0   r   rE   rD   r   )r)   r!   r   r   r   r   r   r   r   r     test_rng_zero_and_extremes_array  sl   
z-TestIntegers.test_rng_zero_and_extremes_arrayc                 C   s   | j D ]C}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}z| j||||d W q tyF } ztdt	| d }~ww d S Nr   rB   r0   r   zMNo error should have been raised, but one was with the following message:

%s
r   r   r-   r   r   r   r   	ExceptionAssertionErrorstrr)   r!   r   r   r   er   r   r    test_full_range  s   
zTestIntegers.test_full_rangec                 C   s   | j D ]G}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}z| j|gd |g||d W q tyJ } ztdt	| d }~ww d S r   r   r   r   r   r    test_full_range_array  s   
z"TestIntegers.test_full_range_arrayc              	   C   s   t t }| jdd  D ]#}dD ]}| jd|| d||d}t| |k  t| dk qq| jdd| d|td}t| dk  t| dk d S )Nr0   )r   r      rB   i   r   r   )r   r   r   r   r   r   r   r   )r)   r!   rH   r   r   valsr   r   r    test_in_bounds_fuzz  s   
z TestIntegers.test_in_bounds_fuzzc           
      C   s   | j D ]h}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}d}ttd}|j|||||d}ttd}|j|g|g|||d}ttd}|j|g| |g| |||d}	t	|| t	||	 qd S )Nr   rB   r0   r#     r   )
r   r   r-   r   r   r   r   r   r'   r	   )
r)   r!   r   r   r   r   rH   ZscalarZscalar_arrayrc   r   r   r    test_scalar_array_equiv  s,   

z$TestIntegers.test_scalar_array_equivc              
   C   s   dddddddddd	}| j dd  D ];}ttd}tjd	kr-|jd
d| d||d}n|jd
d| d||d }t|	 }t
|t|j |k qttd}|jd
d| d|tdtj}t|	 }t
|ttj |k d S )NZ@053594a9b82d656f967c54869bc6970aa0358cf94ad469c81478459c6a90eee3Z@54de9072b6ee9ff7f20b58329556a46a447a8a29d67db51201bf88baa6e4e5d4Z@d3a0d5efb04542b25ac712e50d21f39ac30f312a5052e9bbb1ad3baa791ac84bZ@14e224389ac4580bfbdccb5697d6190b496f91227cf67df60989de3d546389b1Z@0e203226ff3fbbd1580f15da4621e5f7164d0d8d6b51696dd42d004ece2cbec1)	r   int16int32r   int8uint16ra   uint64uint8r0   r   littler   r   r#   r   rB   )r   r   r   sys	byteorderr'   byteswaphashlibsha256	hexdigestr   r-   rE   namer   viewr   )r)   r!   r   r   rH   valresr   r   r    test_repeatability  s>   

zTestIntegers.test_repeatabilityc                 C   s   | j D ]k}|ttjfv rdnt|j}|ttjfv rdnt|jd }|r+|d n|}ttd}|j	||d||d}ttd}|j	|gd |||d}t
|| ttd}|j	|gd |gd ||d}t
|| qd S )Nr   rB   r0   r   r#   r   r   )r   r   r-   bool_r   r   r   r   r   r'   r	   )r)   r!   r   r   r   rH   r  Zval_bcr   r   r    test_repeatability_broadcasting  s&   
"
z,TestIntegers.test_repeatability_broadcastingzbound, expectedr%   )iui,YQiXgi$#Pl   bA i{El   /Yi r;   )ui,YQXgi%#Pl   bA i|El   0Yi        )r  r	  l   bA l   1Yi i{,miuHl   HM c                 C   sJ   d t |fD ]}ttd}|j||d}t||d ur|n|d  qd S )Nr   r   r   )lenr   r   r'   r   )r)   boundr   r   rH   r\   r   r   r    !test_repeatability_32bit_boundary%  s
   
z.TestIntegers.test_repeatability_32bit_boundaryc              
   C   s   t g dg dg dgg dg dg dgg dg dg d	gg d
g dg dgg dg dg dgg}dD ]%}ttd}|jdgdgdggg d|d}t||d urY|n|d  q9d S )N)i
`l   Y/ i0b)i)H{TiP-iTq)l   C iZ'l   !g )l   k40 l   n2c l   DBJ )i|(iy+l   _&A )ip@GiG^l   J|xK )l   
f l   Dmv l   E"g )i>{l   wT2L iJQ)iQ//itLol   k )i\siJi)i=l   }D l   E9l )l   
+x i#Jl   b )i0i7Ol   rn )ixiiAi.t)l   q/q i;-/i)N)rY   rm   rm   i90  r4   r   r0   )r%   r;   r
  r   )r-   rc   r   r   r'   r	   )r)   desiredr   rH   r\   r   r   r    .test_repeatability_32bit_boundary_broadcasting4  s:   
z;TestIntegers.test_repeatability_32bit_boundary_broadcastingc              
   C   s2  t jddd fdddft jdi}|D ]}|| D ]}}|\}}|| }t |gd g}t |gd }tttj||||d	 tttj||||d	 tttj||||d	 tttj||||d	 t j|gd gtd
}	t j|gd td
}
tttj|	|||d	 tttj||
||d	 tttj|	|
||d	 qqd S )Nr   rB   A   )r4               r   r   r   r   ))r   l            )l         r  r  r  )        r  r   r   rD   )	r-   r   r   rc   r   r7   rH   r'   object)r)   r!   ZconfigsrE   configlowhighZlow_aZhigh_aZlow_oZhigh_or   r   r    &test_int64_uint64_broadcast_exceptionsK  sD   z3TestIntegers.test_int64_uint64_broadcast_exceptionsc                 C   sd   t j}t t jj}t t t jj}t t t jjd | }tj||||d}t|| d S r   )r-   r   r   r   r   rH   r'   r   )r)   r!   r   r   r   r   actualr   r   r    test_int64_uint64_corner_caseg  s   z*TestIntegers.test_int64_uint64_corner_casec                 C   s  | j D ]<}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}|tu r.tjn|}| j||||d}t|j	| qtt
fD ];}|tu rLdnt|j}|tu rXdnt|jd }|rf|d n|}| j||||d}t|drxJ tt|| qDd S )Nr   rB   r0   r   rE   )r   r   r-   r   r   r   r  r   r   rE   rC   hasattrtyper)   r!   r   r   r   r   r   r   r    test_respect_dtype_singleton~  s   
z)TestIntegers.test_respect_dtype_singletonc                 C   s   | j D ]S}|tu rdnt|j}|tu rdnt|jd }|r%|d n|}|tu r.tjn|}| j|g|g||d}t|j	| | j|gd |gd ||d}t|j	| qd S r   )
r   r   r-   r   r   r   r  r   r   rE   r  r   r   r    test_respect_dtype_array  s   
z%TestIntegers.test_respect_dtype_arrayc                 C   s   | j D ]M}| jddd||d}|jdksJ |j|ksJ | jddd||djdks,J ttjddddjd ttjddddjd ttjddddjd qd S )Nr   rm   r   r   r   r   r   r   )r   r   rb   rE   r   rH   r'   )r)   r!   r   r   r   r   r    test_zero_size  s   
zTestIntegers.test_zero_sizec                 C   sT   t jdkrdnd}tt tjddd|d W d    d S 1 s#w   Y  d S )Nbigz<i4z>i4r      r   r   )r   r   rz   r{   r7   rH   r'   )r)   Zother_byteord_dtr   r   r    test_error_byteorder  s   "z!TestIntegers.test_error_byteorderzsample_size,high,dtype,chi2maxi@KL rY   g     @_@r   g     b@i i	  g     ȩ@i  g     d@c           
      C   sN   t j|||d}tj|dd\}}|| }|| d |  }	|	|k s%J d S )Nr   T)Zreturn_countsrB   )rH   r'   r-   uniquerp   )
r)   Zsample_sizer  rE   Zchi2maxsamplesvaluescountsr   Zchi2r   r   r    $test_integers_small_dtype_chisquared  s
   
z1TestIntegers.test_integers_small_dtype_chisquaredN)*r>   r?   r@   rH   r'   r   r   r-   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rz   r   r   rc   r  r  r  r  r  r   r$  r'  slowr-  r   r   r   r    r   >  sP    #
	r   c                   @   sd  e Z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
ejdejejfejejfg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,ejdFe-e.gejdGdHe/g dIg dJgfdKe/g dLg dMgfdNe/g dOg dPgfgdQdR Z0dSdT Z1dUdV Z2ejdWdXdYgdZd[ Z3d\d] Z4d^d_ Z5d`da Z6dbdc Z7ddde Z8dfdg Z9dhdi Z:djdk Z;dldm Z<dndo Z=ejj>dpdq Z?ejdrg dsg dtg dug dvg dwg dxdygg dzgd{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQejdeRdyddejSdgdd ZTdd ZUejjVeWddejdg ddd ZXejddKgdggfdgdNggfgdd ZYejdg ddd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd ZaddÄ Zbddń ZcddǄ ZdddɄ Zedd˄ Zfdd̈́ Zgddτ Zhddф Ziddӄ ZjddՄ Zkddׄ Zlddل Zmddۄ Zndd݄ Zodd߄ Zpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd Zejddd gdd Zejddej dejdgejdg ddd	 Zd
d Zdd Zdd Zdd ZdHS (  TestRandomDistc                 C   r~   )Nr   r   r8   r   r   r    r     r   zTestRandomDist.setup_methodc                 C   H   t t| j}|jdddd}tddgddgd	d
gg}t|| d S )Nc   rm   rB   r   )   %   ir   r   r   r'   r-   rc   r	   r)   rH   r  r  r   r   r    test_integers  s   zTestRandomDist.test_integersc                 C   sR   t t| j}|jdddtjd}tjddgddgd	d
ggtjd}t|| d S )Nr   r2  r3  r   r      F   D   r   r6  rD   )r   r   r   r'   r-   ra   rc   r	   r:  r   r   r    test_integers_masked  s   "z#TestRandomDist.test_integers_maskedc                 C   sJ   t t| j}|jddddd}tddgdd	gd
dgg}t|| d S )Nr1  r2  r3  T)r   r!   r4  r5  r6  &   r8  ir9  r:  r   r   r    test_integers_closed  s   z#TestRandomDist.test_integers_closedc                 C   s:   t jtdjtdjdd}tdj}t|| d S )NlTr!   )rH   r'   r-   r   r   r   )r)   r  r  r   r   r    test_integers_max_int  s
   z$TestRandomDist.test_integers_max_intc                 C   sn   t t| j}|d}tddgddgddgg}t||dd	 t t| j}| }t||d
 dd	 d S )Nr3  gG0Ը?gæ?g2?gu	A?gH
>H?g;dE?r   decimalr  r   r   r   rH   r-   rc   r
   r:  r   r   r    test_random  s   

zTestRandomDist.test_randomc                 C   sF   t t| j}|d}tddgddgddgg}t||dd	 d S )
Nr3  CԸ?gP?gtX?g81
A?grO>H?g88dE?r   rE  rG  r:  r   r   r    test_random_float  s   

z TestRandomDist.test_random_floatc                 C   s2   t t| j}|jtjd}d}t||dd d S )NrD   rI  r   rE  )r   r   r   rH   r-   ry   r
   r:  r   r   r    test_random_float_scalar  s   z'TestRandomDist.test_random_float_scalarzdtype, uint_view_typec                 C   sP   t t| j}|jd|d}t||d@ }d|  k r#dk s&J  J d S )Nr   rD   r0   i$^  i,e  )r   r   r   rH   r-   Zcount_nonzeror  )r)   rE   Zuint_view_typerH   r   Znum_ones_in_lsbr   r   r    test_random_distribution_of_lsb  s    z.TestRandomDist.test_random_distribution_of_lsbc                 C   s   t ttjdd d S )Nr   rD   )r   r6   rH   r8   r   r   r    test_random_unsupported_type  rU   z+TestRandomDist.test_random_unsupported_typec                 C   s<   t t| j}|dd}tjg dtjd}t|| d S )Nr   )r   r   rB   rB   rD   r   r   r   choicer-   rc   r   r	   r:  r   r   r    test_choice_uniform_replace  s   z*TestRandomDist.test_choice_uniform_replacec                 C   sD   t t| j}|jddg dd}tjg dtjd}t|| d S )Nr   )皙?rQ  皙?rR  rJ   )r   r0   r   r0   rD   rN  r:  r   r   r    test_choice_nonuniform_replace  s   z-TestRandomDist.test_choice_nonuniform_replacec                 C   sl   t t| j}|jdddd}tjg dtjd}t|| |jddddd}tjdtjd}t|| d S )Nr   rm   Freplacer   rD   )rV  shuffle)	r   r   r   rO  r-   rc   r   r	   r.   r:  r   r   r    test_choice_uniform_noreplace"  s   
z,TestRandomDist.test_choice_uniform_noreplacec                 C   sF   t t| j}|jdddg dd}tjg dtjd}t|| d S )Nr   rm   F)rR  333333?rF   rR  rV  rJ   )r   rB   rm   rD   rN  r:  r   r   r     test_choice_nonuniform_noreplace+  s   z/TestRandomDist.test_choice_nonuniform_noreplacec                 C   s:   t t| j}|g dd}tg d}t|| d S )N)abcdr   )r\  r\  r^  r^  r   r   r   rO  r-   rc   r	   r:  r   r   r    test_choice_noninteger1  s   z%TestRandomDist.test_choice_nonintegerc                 C   s\   t t| j}|ddgddgddgddggd}tddgddgddgg}t|| d S )	Nr   r0   rB   rm   r   rY   r   r   r`  r:  r   r   r    )test_choice_multidimensional_default_axis7  s   $z8TestRandomDist.test_choice_multidimensional_default_axisc                 C   s^   t t| j}|jddgddgddgddggddd	}tdgdgdgdgg}t|| d S )
Nr   r0   rB   rm   r   rY   r   r   r   r`  r:  r   r   r    (test_choice_multidimensional_custom_axis=  s   (z7TestRandomDist.test_choice_multidimensional_custom_axisc                 C   s  t j}tt|dd tt|dd tt|g d tt|g ddddgddggd tt|ddgdg d	d tt|ddgdd
dgd tt|ddgdddgd tt|g dddd tt|g dddd tt|g dddd tt|g dddd tt|g dddg dd d S )Nr4   rm         @)r0   rB   rm   r         ?rS  r0   rB   )rQ  rQ  rP   rg   rh   rQ  r   r   FrU  r:   )r4   )r4   r0   )r0   r   r   rZ  )rH   rO  r   r7   )r)   r   r   r   r    test_choice_exceptionsC  s"   
z%TestRandomDist.test_choice_exceptionsc              	   C   s   ddg}t ttjddd t ttjddd t ttjdd|d t ttjdd|d t ttjddgdd t tjd gddd u  tddg}tjdtd	}||d
< t tj|dd|u  t }t ttjd|dd  t ttjd|dd  t ttjd|d|d  t ttjd|d|d  t ttjddg|dd  t tjd g|ddj	d
k tddg}tjdtd	}||d
< t tj||dd
 |u  d}g d}ttjd|ddj| ttjd|ddj| ttjd|d|dj| ttjd|d|dj| ttjtd|ddj| ttjd
d
ddjd ttjd
dd
djd ttjddd
djd ttjd
d
djd ttjg ddjd ttjddgddjd tttjg d d S )NrR  ri   rB   TrU  FrZ  r0   rD   r   r   )rR  rR  rR  rR  rQ  rP   r   r!  r   r"  r#  r   r\  r]  )r   r-   ZisscalarrH   rO  rc   r   r  tuplendimitemr   rb   r.   r'   r   r7   )r)   rJ   r\  arrr*   r   r   r    test_choice_return_shapeU  sL    z'TestRandomDist.test_choice_return_shapec                 C   s,   t g d}g d}tttj||d d S )N)*   r0   rB   )NNNrS  )r-   rc   r   r7   rH   rO  )r)   r\  rJ   r   r   r    test_choice_nan_probabilities  s   z,TestRandomDist.test_choice_nan_probabilitiesc              	   C   s   t dd }d|dd d< tt| j}|jdd|d d d d}tt| j}|jddt |d d d d}t|| d S )Nr   rY   rd  r0   rB   rm   rS  )r-   onesr   r   r   rO  rq   r	   )r)   rJ   rH   rr   rs   r   r   r    test_choice_p_non_contiguous  s    z+TestRandomDist.test_choice_p_non_contiguousc                 C   s   t dd }tdd}|jt jksJ tjdddd}|jt jks%J tjdd|d}|jt jks5J tjdd|dd}|jt jksFJ d S )Nr   g      @rB   FrU  rS  )rJ   rV  )r-   rn  rH   rO  rE   r   )r)   rJ   r  r   r   r    test_choice_return_type  s   z&TestRandomDist.test_choice_return_typec                 C   sZ   d}t t| j}|jdddd}tjdkr| }t|	t
j }t||k d S )NZ@4266599d12bfcfb815213303432341c06b4349f5455890446578877bb322e222'  r(  FrU  r   )r   r   r   rO  r   r   r   r   r   r  r-   r   r   r   )r)   Zchoice_hashrH   r  r  r   r   r    test_choice_large_sample  s   
z'TestRandomDist.test_choice_large_samplec                 C   s*   t t| j}|d}d}t|| d S )Nr   s
   	8%)r   r   r   bytesr   r:  r   r   r    
test_bytes  s   
zTestRandomDist.test_bytesc                 C   s   dd dd dd dd dd dd dd d	d d
d dd dd fD ]!}t t| j}|g d}|| |}|g d}t|| q#d S )Nc                 S   s
   t g S r   )r-   rc   r\   r   r   r    <lambda>  s   
 z-TestRandomDist.test_shuffle.<locals>.<lambda>c                 S   s   | S r   r   ru  r   r   r    rv    s    c                 S      t | t jS r   )r-   asarrayastyper   ru  r   r   r    rv        c                 S   rw  r   )r-   rx  ry  ry   ru  r   r   r    rv    rz  c                 S   rw  r   )r-   rx  ry  Z	complex64ru  r   r   r    rv    rz  c                 S   s   t | tS r   )r-   rx  ry  r  ru  r   r   r    rv        c                 S   s   dd | D S )Nc                 S      g | ]}||fqS r   r   .0ir   r   r    
<listcomp>      ATestRandomDist.test_shuffle.<locals>.<lambda>.<locals>.<listcomp>r   ru  r   r   r    rv    s    c                 S   s   t dd | D S )Nc                 S   s   g | ]}||gqS r   r   r}  r   r   r    r    r  r  )r-   rx  ru  r   r   r    rv    r  c                 S   s   t | | gjS r   )r-   vstackTru  r   r   r    rv    r{  c                 S   s*   t dd | D dtfdtfgt jS )Nc                 S   r|  r   r   r}  r   r   r    r    r  r  r\  r]  )r-   rx  rC   r  Zrecarrayru  r   r   r    rv    s    
c                 S   s(   t dd | D dtdfdt jdfgS )Nc                 S   r|  r   r   r}  r   r   r    r    r  r  r\  r0   r]  )r-   rx  r  r   ru  r   r   r    rv    s
    

r0   rB   rm   r   rY   r   r   r   r   r   
r   r0   r   r   r   rY   rm   r   rB   r   )r   r   r   rW  r	   )r)   convrH   alistr  r  r   r   r    test_shuffle  s&   
zTestRandomDist.test_shufflec                 C   s   t t| j}tdd}|j|dd tg dg dg dg dg}t|| t t| j}tdd}|j|d	d t|| d S )
Nr   r   r   r0   r   r   rm   r0   rB   r   r   rY   r   r      r   r   r   r   r   r   r4   )	r   r   r   r-   r.   reshaperW  rc   r	   r:  r   r   r    test_shuffle_custom_axis  s   

z'TestRandomDist.test_shuffle_custom_axisc                 C   sT   t t| j}tg d}dD ]}tg d}|j||d t|| qd S )N)r   r   )r   r0   r   )r   r   r   r-   rc   r  rW  r	   )r)   rH   r  r   r  r   r   r    test_shuffle_custom_axis_empty  s   z-TestRandomDist.test_shuffle_custom_axis_emptyc                 C   s^   t ddd}| }tt| j}|j|dd tt| j}||j t	|| d S )Nr   rB   r   r0   r   )
r-   r.   r  copyr   r   r   rW  r  r	   )r)   y1y2rH   r   r   r    test_shuffle_axis_nonsquare  s   z*TestRandomDist.test_shuffle_axis_nonsquarec                 C   s   t jt tddd d d}t jt dd d d}| }| }tdD ]2}t| t	t
|j|j  t
|j|j   t| t	t
|j|j  t
|j|j   q+d S )Nr   )rY   r   rm   r0   r4   r   )r-   maZmasked_valuesr  r,   r.   r  rH   rW  r   sorteddatamask)r)   r\  r]  Za_origZb_origr  r   r   r    test_shuffle_masked  s   "
 
 z"TestRandomDist.test_shuffle_maskedc                 C   s   t t| j}td}ttj|j|d tdd}ttj|j|d tt	|j|t
ddd  g dg dg}tt|j|d td}tt	|j| td	}ttj|j|d d S )
Nr   r0   r   rm   rm   rm   rB   r   )r   rY   r   r3  )r   r   r   r-   r.   r   	AxisErrorrW  r  r6   sliceNotImplementedErrorrc   rn  r)   rH   rj  r   r   r    test_shuffle_exceptions  s   


z&TestRandomDist.test_shuffle_exceptionsc                 C   s^   t t| j}td}d|j_tjt	dd |
| W d    d S 1 s(w   Y  d S )NrY   F	read-onlyrw   )r   r   r   r-   rG   flags	writeablerz   r{   r7   rW  )r)   rH   r\  r   r   r    test_shuffle_not_writeable  s   
"z)TestRandomDist.test_shuffle_not_writeablec           	      C   s   t t| j}g d}||}g d}t|| t t| j}tg dj}||}t|t|j d}ttj	|j| d}ttj	|j| t t| j}d}g d}||}t|| d S )Nr  r  abcdg333333?r   )
rm   r   r   r   r   r   rB   rY   r0   r   )
r   r   r   permutationr	   r-   Z
atleast_2dr  r   r  )	r)   rH   r  r  r  Zarr_2dZ	bad_x_strZbad_x_floatZinteger_valr   r   r    test_permutation
  s$   



zTestRandomDist.test_permutationc                 C   s   t dd}t g dg dg dg dg}tt| j}|j|dd}t|| tt| j}|j|d	d}t|| d S )
Nr   r  r  r  r  r  r0   r   r4   )	r-   r.   r  rc   r   r   r   r  r	   )r)   r\  r  rH   r  r   r   r    test_permutation_custom_axis#  s   

z+TestRandomDist.test_permutation_custom_axisc                 C   sh   t t| j}td}ttj|j|d tdd}ttj|j|d tt	|j|t
ddd  d S )Nr   r0   r   r  rm   rB   )r   r   r   r-   r.   r   r  r  r  r6   r  r  r   r   r    test_permutation_exceptions0  s   
z*TestRandomDist.test_permutation_exceptionsrE   zaxis, expectedN)rm   r   r   r   r   r  )r   r   rB   rY   r0   r   r   )r   r0   rB   r   r   r  )r   r   r   rm   r   rY   r0   )rY   rm   r   r   rB   r0   )r  r   r   r   r   r   c                 C   s   t t| j}tddd|}|j|||d t|| t t| j}tddd|}|j||d}|j	|ksAJ t|| d S )Nr   rB   r   r   outr   )
r   r   r   r-   r.   r  ry  permutedr	   rE   )r)   rE   r   r   rH   r\   yr   r   r    test_permuted8  s   	
zTestRandomDist.test_permutedc                 C   s   t t| j}tddd}| }|d d d d df }|j|d|d}tg dg dg}t	|| ||d d d d df< t	|| d S )	N   rB   r  rm   r0   r  )r   r   rm   r   )r   r   r  r   )
r   r   r   r-   r.   r  r  r  rc   r	   )r)   rH   Zx0x1r\   r  r   r   r   r    test_permuted_with_stridesL  s   

z)TestRandomDist.test_permuted_with_stridesc                 C   s   t g }t|g  d S r   )rH   r  r	   )r)   r  r   r   r    test_permuted_emptyY  s   
z"TestRandomDist.test_permuted_emptyoutshaper   rY   c                 C   s`   t g d}t j||jd}tjtdd tj||d W d    d S 1 s)w   Y  d S )Nr   rD   z
same shaperw   r  )	r-   rc   rG   rE   rz   r{   r7   rH   r  )r)   r  r\  r  r   r   r    "test_permuted_out_with_wrong_shape]  s
   "z1TestRandomDist.test_permuted_out_with_wrong_shapec                 C   s^   t jdt jd}t d}tjtdd tj|d|d W d    d S 1 s(w   Y  d S )N)rm   rY   rD   zCannot castrw   r0   r  )	r-   rG   r   rn  rz   r{   r6   rH   r  )r)   r  r\   r   r   r    !test_permuted_out_with_wrong_typed  s
   
"z0TestRandomDist.test_permuted_out_with_wrong_typec                 C   sV   t d}d|j_tjtdd tj|d|d W d    d S 1 s$w   Y  d S )N)rB   rY   Fr  rw   r0   r  )	r-   rG   r  r  rz   r{   r7   rH   r  r[   r   r   r    test_permuted_not_writeablej  s
   
"z*TestRandomDist.test_permuted_not_writeablec                 C   L   t t| j}|jdddd}tddgddgd	d
gg}t||dd d S )NrR  ri   r3  r   gW<$=g^
=g/:Ћ?gG!Gc>g'`2?gU?r   rE  )r   r   r   betar-   rc   r
   r:  r   r   r    	test_betap  s   zTestRandomDist.test_betac                 C   sp   t t| j}|jdddd}tddgddgdd	gg}t|| t t| j}|dd}d}t|| d S )
NgZd;Y@gv/?r3  r   rl  r6  0   ,   r   )r   r   r   rI   r-   rc   r	   r:  r   r   r    test_binomialy  s   

zTestRandomDist.test_binomialc                 C   J   t t| j}|jddd}tddgddgdd	gg}t||d
d d S )Nr   r3  r   gmE~@@g
1ςC@grӳL@gm%xL@g<kQK@gtK@r   rE  )r   r   r   	chisquarer-   rc   r
   r:  r   r   r    test_chisquare     
zTestRandomDist.test_chisquarec                 C   s   t t| j}tddg}|j|dd}tddgddggd	d
gddggddgddggg}t||dd tddg}tt|j| t t| j}tddg}||}t||d dd d S )NI<I@EZC@r3  r   g28\h?gɎG/?gAp?g|);?gLX?gfOh?g됷W?g(ސP?gz$Q?gmWt ?g搝K?g4hz?r   rE  HzG?缉ؗҜr  )	r   r   r   r-   rc   	dirichletr
   r   r7   )r)   rH   alphar  r  Z	bad_alphar   r   r    test_dirichlet  s(   

zTestRandomDist.test_dirichletc                 C   s   t ddg}tt|t djd tt|t djd tt|t djd tt|ddgjd tt|djd tt|t djd tttj|t	d d S )Nr  r  r0   r^   rB   r_   r`   )
r-   rc   r   rH   r  ra   rb   r   r6   rd   re   r   r   r    test_dirichlet_size  s   z"TestRandomDist.test_dirichlet_sizec                 C   s   t ddg}tttj| tttjddgg tttjdgdgg tttjdgdggdgdggg tttjt ddgddgg d S )Nr  r  rY   r0   )r-   rc   r   r7   rH   r  )r)   r  r   r   r    test_dirichlet_bad_alpha  s   "$z'TestRandomDist.test_dirichlet_bad_alphac                 C   sh   t g d}|d d d }tt| j}|j|dd}tt| j}|jt |dd}t|| d S )N)r  g      r  rB   r3  r   )r-   rc   r   r   r   r  rq   r
   )r)   r\  r  rH   rr   rs   r   r   r    #test_dirichlet_alpha_non_contiguous  s   z2TestRandomDist.test_dirichlet_alpha_non_contiguousc                 C   sx   d}|t ddg }tt| j}|j|dd}t ddgddggddgddggddgddggg}t||dd d S )	Nrv         ?r   r3  r   rV   r   rE  )r-   rc   r   r   r   r  r
   )r)   Zepsr  rH   r  r   r   r   r    test_dirichlet_small_alpha  s    z)TestRandomDist.test_dirichlet_small_alphac                 C   sT   t g d}||  }tt| j}|j|dd}|jdd}t||dd d S )N)g{Gz?{Gz?Q?i -1r   r   r   r   )r   )	r-   rc   rp   r   r   r   r  r   r   )r)   r  Z
exact_meanrH   r   Zsample_meanr   r   r    %test_dirichlet_moderately_small_alpha  s   z4TestRandomDist.test_dirichlet_moderately_small_alphar  )rY   r   r   r   )rF   r   r   r   )r0   rY   r   r         ?r   r   r   )g{Gz?r  r   r   )gh㈵>r   r   r   )gMb`?gQ?r   r   r  r   r   r   rV   r   c                 C   s*   t |}t|}t||dk d d S )Nr   rV   )r-   rc   rH   r  r   )r)   r  r  r   r   r    &test_dirichlet_multiple_zeros_in_alpha  s   

z5TestRandomDist.test_dirichlet_multiple_zeros_in_alphac                 C   r  )Ng8EGr?r3  r   gvM?g?g#c?gQ:N?gAP?gE_9@r   rE  )r   r   r   exponentialr-   rc   r
   r:  r   r   r    test_exponential  r  zTestRandomDist.test_exponentialc                 C   &   t tjddd tttjdd d S Nr   scale       )r   rH   r  r   r7   r8   r   r   r    test_exponential_0     z!TestRandomDist.test_exponential_0c                 C   r  )Nr   M   r3  r   g}(Ҍ?gi?g=r?g]hDA?gjӨ?g8k*u?r   rE  )r   r   r   fr-   rc   r
   r:  r   r   r    test_f     
zTestRandomDist.test_fc                 C   r  )NrY   rm   r3  r   g,שn'@gt@g<e2@g1a3@g3r
y-2@gs1-2@r   rE  )r   r   r   gammar-   rc   r
   r:  r   r   r    
test_gamma  r  zTestRandomDist.test_gammac                 C   s*   t tjdddd tttjddd d S )Nr   )rb   r  r  )r   rH   r  r   r7   r8   r   r   r    test_gamma_0
  s   zTestRandomDist.test_gamma_0c                 C   sF   t t| j}|jddd}tddgddgddgg}t|| d S )N_c97ݚ?r3  r   r0   r  r   r   )r   r   r   	geometricr-   rc   r	   r:  r   r   r    test_geometric     
zTestRandomDist.test_geometricc                 C   s   t ttjd t ttjdgd  t ttjd t ttjdgd  tjdd t ttjtj t ttjtjgd  W d    d S 1 sGw   Y  d S )Nrg   r   rh   ignoreinvalid)r   r7   rH   r  r-   errstaterL   r8   r   r   r    test_geometric_exceptions  s   "z(TestRandomDist.test_geometric_exceptionsc                 C   r  )Nr         @r3  locr  r   gA7G@g1Fiҿgei@g_Cg0cPg`(_տr   rE  )r   r   r   gumbelr-   rc   r
   r:  r   r   r    test_gumbel  r  zTestRandomDist.test_gumbelc                 C   r  r  )r   rH   r  r   r7   r8   r   r   r    test_gumbel_0'  r  zTestRandomDist.test_gumbel_0c                 C   s   t t| j}|jddddd}tddgddgddgg}t|| |jdd	d
dd}tg d}t|| |jdd	ddd}tg d}t|| |jd	dd
dd}tg d}t|| |jd	dddd}tg d}t|| d S )Ng333333$@g      @r   r3  r   r   r   rY   r   rm   r   )rm   rm   rm   rm   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   hypergeometricr-   rc   r	   r:  r   r   r    test_hypergeometric+  s&   




z"TestRandomDist.test_hypergeometricc                 C   r  )Nr  r  r3  r  g6@	ga@bDA"?g*[r{g>K?g(?g<?r   rE  )r   r   r   laplacer-   rc   r
   r:  r   r   r    test_laplaceE  r  zTestRandomDist.test_laplacec                 C   r  r  )r   rH   r  r   r7   r8   r   r   r    test_laplace_0M  r  zTestRandomDist.test_laplace_0c                 C   r  )Nr  r  r3  r  gbZgHʊg$>?g>&gQh@g%?n?gĉ8|?r   rE  )r   r   r   logisticr-   rc   r
   r:  r   r   r    test_logisticQ  r  zTestRandomDist.test_logisticc                 C   r  )Nr  r  r3  )r   sigmar   gܒx?gk*+@g<Ҿ?g
@g5a@g%jz(@r   rE  )r   r   r   	lognormalr-   rc   r
   r:  r   r   r    test_lognormalY  r  zTestRandomDist.test_lognormalc                 C   s&   t tjddd tttjdd d S )Nr   )r  r0   r  )r   rH   r  r   r7   r8   r   r   r    test_lognormal_0a  r  zTestRandomDist.test_lognormal_0c                 C   sF   t t| j}|jddd}tddgddgdd	gg}t|| d S )
Ngƀ@?r3  )rJ   r   r   r   rm      rY   r0   )r   r   r   	logseriesr-   rc   r	   r:  r   r   r    test_logseriese  r  zTestRandomDist.test_logseriesc                 C   s$   t t| j}|ddksJ d S )Nr   r0   )r   r   r   r   r)   rH   r   r   r    test_logseries_zerom  s   z"TestRandomDist.test_logseries_zerovaluer4   r  g      @c              	   C   s  t t| j}tjddp tt || W d    n1 s#w   Y  tt |t	|gd  W d    n1 sCw   Y  tt |t	|gd d d d  W d    n1 shw   Y  W d    d S W d    d S 1 sw   Y  d S )Nr  r  r   rB   )
r   r   r   r-   r  rz   r{   r7   r   rc   )r)   r  rH   r   r   r    test_logseries_exceptionsq  s   ""z(TestRandomDist.test_logseries_exceptionsc                 C   sf   t t| j}|jddgd dd}tg dg dgg dg d	gg d
g dgg}t|| d S )Nr   UUUUUU?r   r3  r   )r0   rY   r0   r   r   rm   )r   rB   r   rB   r   rB   )rY   rm   rB   r   rm   r0   )r   r   r   rB   rm   r   )r   rm   r0   rY   rm   rB   )rY   rY   rm   r0   rB   r   )r   r   r   rS   r-   rc   r	   r:  r   r   r    test_multinomial~  s   
zTestRandomDist.test_multinomialzfp errors don't work in wasmreasonr   )svdeighcholeskyc                 C   s  t t| j}d}ddgddgg}d}|j||||d}tddgdd	ggd
dgddggddgddggg}t||dd |j|||d}tddg}t||dd ddg}ddgddgg}tt|j||dd ddgddgg}t	t
|j|| t	t
|j||dd tt|j||dd t|j||dd tt|j||dd tt|j||ddd ddgddgg}|dv r|j||d|d}t|d |d  d!d n
tt|j||dd tjdd"gd"dggtjd#}t }	|j|||d |	t
}
t|
dksJ W d    n	1 sw   Y  td}td}tt|j||d$d tt|jtd%| tt|j|td tt|j|td& d S )'N)r  r   r0   r   r3  r   gtg$&@g&بO=g!$@gDo?g\&@g,R{?g
f!@g?ժ?gT^o#@g`R?gP'@r   rE  gl?g$("@rB   raise)check_validr  r  r  )r  r   )r
  r  r   ).r   ).r0   r   rR  rD   other)rB   r0   r0   rm   )r   r   r   multivariate_normalr-   rc   r
   r   r7   r   RuntimeWarningr   r   ry   r   recordr  rG   eyer   )r)   r   rH   r   covr   r  r  r*  supwmur   r   r    test_multivariate_normal  s   








z'TestRandomDist.test_multivariate_normalz	mean, covy      ?      ?y                c                 C   sN   t t| j}tjtdd ||| W d    d S 1 s w   Y  d S )Nzmust not be complexrw   )r   r   r   rz   r{   r6   r  )r)   r   r  rH   r   r   r    )test_multivariate_normal_disallow_complex  s   "z8TestRandomDist.test_multivariate_normal_disallow_complexc           	      C   s   t t| j}d}tddg}tddgddgg}|j|||f|d}|| }|j| |d  }tt|	ddk sAJ tt|| dk sOJ d S )Nr#   r0   rB   r   r:   rR  rP   )
r   r   r   r-   rc   r  r  rZ   absr   )	r)   r   rH   Zn_sr   r  r*   Zs_centerZcov_empr   r   r    $test_multivariate_normal_basic_stats  s    z3TestRandomDist.test_multivariate_normal_basic_statsc                 C   r0  )NrO   g|Pk?r3  )nrJ   r   i  i  i  i  iX  i  )r   r   r   r   r-   rc   r	   r:  r   r   r    r     s   
z%TestRandomDist.test_negative_binomialc                 C   s\   t jdd tttjdt j tttjdt jgd  W d    d S 1 s'w   Y  d S )Nr  r  rO   r   )r-   r  r   r7   rH   r   rL   r8   r   r   r    !test_negative_binomial_exceptions  s   

"z0TestRandomDist.test_negative_binomial_exceptionsc                 C   s:   t t tdd}W d    d S 1 sw   Y  d S Nr0   r   )r   r7   rH   r   r[   r   r   r    #test_negative_binomial_p0_exception  s   
"z2TestRandomDist.test_negative_binomial_p0_exceptionc                 C   sV   t jdd tttjdd tttjdgdg W d    d S 1 s$w   Y  d S )Nr  r  r  rR  )r-   r  r   r7   rH   r   r8   r   r   r    .test_negative_binomial_invalid_p_n_combination  s   "z=TestRandomDist.test_negative_binomial_invalid_p_n_combinationc                 C   s   t t| j}|jdddd}tddgddgdd	gg}t||d
d |jdddd}tddgddgddgg}t||d
d t t| j}|jdddd}tddgddgddgg}t||d
d d S )NrY   r3  )dfnoncr   gs؀3J?gugو/@gNJm+@gA}-4@gq=&@gjhn@r   rE  rF   rP   gZօDN?gE!X&?gt%T?gQ)V?g5Zlf?gΎ{?r   gmK?gZ?g%yKY@g@W@gĈ{>@g&BB=@)r   r   r   noncentral_chisquarer-   rc   r
   r:  r   r   r    test_noncentral_chisquare  s(   


z(TestRandomDist.test_noncentral_chisquarec                 C   N   t t| j}|jddddd}tddgdd	gd
dgg}t||dd d S )NrY   rB   r0   r3  )dfnumdfdenr"  r   gHP
?gn?g%f?gch?gzƎ?g]?:?r   rE  )r   r   r   noncentral_fr-   rc   r
   r:  r   r   r    test_noncentral_f     

z TestRandomDist.test_noncentral_fc                 C   s2   t t| j}|jddtjd}t|sJ d S )NrY   rB   )r&  r'  r"  )r   r   r   r(  r-   rL   isnanr)   rH   r  r   r   r    test_noncentral_f_nan  s   z$TestRandomDist.test_noncentral_f_nanc                 C   r  )Nr  r  r3  r  g?`xg\P@g/7u g0aj?gi%?gog@r   rE  )r   r   r   normalr-   rc   r
   r:  r   r   r    test_normal$  r  zTestRandomDist.test_normalc                 C   r  r  )r   rH   r.  r   r7   r8   r   r   r    test_normal_0,  r  zTestRandomDist.test_normal_0c                 C   sN   t t| j}|jddd}tddgddgdd	gg}tjj||d
d d S )Nr  r3  r\  r   gá?gƫh@gi`>?g0"&Agc@g=fAr   )Znulp)r   r   r   paretor-   rc   testingZassert_array_almost_equal_nulpr:  r   r   r    test_pareto0  s   
	zTestRandomDist.test_paretoc                 C   sF   t t| j}|jddd}tddgddgddgg}t|| d S )Nr  r3  )lamr   r   )r   r   r   poissonr-   rc   r	   r:  r   r   r    test_poisson>  r  zTestRandomDist.test_poissonc                 C   s   t dj}d}tttj| tttj|gd  tttj| tttj|gd  t jdd tttjt j tttjt jgd  W d    d S 1 sOw   Y  d S )Nr   r4   r   r  r  )	r-   r   r   r   r7   rH   r6  r  rL   )r)   ZlambigZlamnegr   r   r    test_poisson_exceptionsF  s   "z&TestRandomDist.test_poisson_exceptionsc                 C   r  )Nr  r3  r1  gZ >g?gÄ(=g҇?gŚE?gߢH?r   rE  )r   r   r   powerr-   rc   r
   r:  r   r   r    
test_powerQ  r  zTestRandomDist.test_powerc                 C   r  )Nr   r3  )r  r   gry@gtQP0@gAI_@g@u81@g	G0@g"wc5@r   rE  )r   r   r   rayleighr-   rc   r
   r:  r   r   r    test_rayleighY  r  zTestRandomDist.test_rayleighc                 C   r  r  )r   rH   r;  r   r7   r8   r   r   r    test_rayleigh_0a  r  zTestRandomDist.test_rayleigh_0c                 C   H   t t| j}|jdd}tddgddgddgg}t||d	d
 d S )Nr3  r   gH1gW|3
g\?gLeg5P	gFA?r   rE  )r   r   r   Zstandard_cauchyr-   rc   r
   r:  r   r   r    test_standard_cauchye     
z#TestRandomDist.test_standard_cauchyc                 C   r  )Nr3  invr   ga\5?gr7k?g8PC*?g5$[?gW3T?g*?r   rE  )r   r   r   standard_exponentialr-   rc   r
   r:  r   r   r    test_standard_exponentialm  r  z(TestRandomDist.test_standard_exponentialc                 C      t ttjtjd d S NrD   )r   r6   rH   rB  r-   r   r8   r   r   r    #test_standard_expoential_type_erroru     z2TestRandomDist.test_standard_expoential_type_errorc                 C   r  )Nrm   r3  rb   r   gΈ̏&?gTϿ?g1n21@gDb<z@gBv@gc^@r   rE  r   r   r   standard_gammar-   rc   r
   r:  r   r   r    test_standard_gammax  r  z"TestRandomDist.test_standard_gammac                 C   s4   t t| j}|jdtjd}d}t||dd d S )Nrm   rD   g   d@r   rE  )r   r   r   rJ  r-   ry   r
   r:  r   r   r    !test_standard_gammma_scalar_float  s   z0TestRandomDist.test_standard_gammma_scalar_floatc                 C   r  )Nrm   r3  rH  gf&?gMO?g1@g):@g@g;i@rY   rE  rI  r:  r   r   r    test_standard_gamma_float  r  z(TestRandomDist.test_standard_gamma_floatc                 C   s   t jdt jd}tt| j}|jd|t jd t jddgddgd	d
ggt jd}t||dd tt| j}|jd|dt jd t||dd d S )Nr3  rD         $@r  rE   gM»L$@ga {@gN]"@gPS")@g_+@gmB@rY   rE  r  r   rE   )	r-   rG   ry   r   r   r   rJ  rc   r
   )r)   r  rH   r  r   r   r    test_standard_gammma_float_out  s   
z-TestRandomDist.test_standard_gammma_float_outc                 C   s   t ttjddd d S )Nr  r   rD   )r   r6   rH   rJ  r8   r   r   r     test_standard_gamma_unknown_type  s   

z/TestRandomDist.test_standard_gamma_unknown_typec                 C   s6   t d}tttjdd|d tttjdd|d d S )Nr   rN  r   )r   r  )r   r0   )r-   rG   r   r7   rH   rJ  )r)   r  r   r   r    test_out_size_mismatch  s   

z%TestRandomDist.test_out_size_mismatchc                 C   r  )Nr   )rb   r  )r   rH   rJ  r   r7   r8   r   r   r    test_standard_gamma_0  r  z$TestRandomDist.test_standard_gamma_0c                 C   r>  )Nr3  r   g
bYg? ?gGH{Lgz\?gc`+?gT}?r   rE  )r   r   r   r   r-   rc   r
   r:  r   r   r    test_standard_normal  r@  z#TestRandomDist.test_standard_normalc                 C   rD  rE  )r   r6   rH   r   r-   r   r8   r   r   r    %test_standard_normal_unsupported_type  rG  z4TestRandomDist.test_standard_normal_unsupported_typec                 C   r  )Nr   r3  )r!  r   gV1g	|ڙ(?g-?g NhڿgMc?g!uLM r   rE  )r   r   r   
standard_tr-   rc   r
   r:  r   r   r    test_standard_t  r  zTestRandomDist.test_standard_tc                 C   r%  )Ng{Gz@g(\u$@gףp=
W4@r3  )leftmoderightr   gEpw@g4DC+@gŋ@g/,@gkuR*@gHNPcr+@r   rE  )r   r   r   
triangularr-   rc   r
   r:  r   r   r    test_triangular  r*  zTestRandomDist.test_triangularc                 C   r  )NGz?gGz%@r3  )r  r  r   gm2@gJaD@g: @g
Q @g@T{e@gb@r   rE  r   r   r   uniformr-   rc   r
   r:  r   r   r    test_uniform  r  zTestRandomDist.test_uniformc                 C   s   t dj}t dj}tj}tt|t j d tt|dt j tt||| tt|t j gdg tt|dgt jg tjt 	|d|d d d S )Nrd   r   r0   g ؅W4vC)r  r  )
r-   Zfinfor   r   rH   r`  r   OverflowErrorinf	nextafter)r)   ZfminZfmaxfuncr   r   r    test_uniform_range_bounds  s   z(TestRandomDist.test_uniform_range_boundsc                 C   sn   t j}|dd}t|d |dtjgdtjg}t|dtjg |dgdggddg}t|dtd  d S )Nr  rV   g
ףp= @r`   )rH   r`  r   r-   pirG   )r)   re  resultr   r   r    test_uniform_zero_range  s   

z&TestRandomDist.test_uniform_zero_rangec                 C   sH   t j}tt|dd tt|ddgddg tt|ddgddggd d S )NrB   r0   r   rm   )rH   r`  r   r7   )r)   re  r   r   r    test_uniform_neg_range  s   z%TestRandomDist.test_uniform_neg_rangec                 C   sj   G dd dt j}t d|}tttj|| G dd dt j}t d|}tttj|dd d S )Nc                   @      e Zd Zdd ZdS )zGTestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingFloatc                 S      t r   r6   r8   r   r   r    	__float__     zQTestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingFloat.__float__N)r>   r?   r@   rn  r   r   r   r    ThrowingFloat      rp  r  c                   @   rk  )zITestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingIntegerc                 S   rl  r   rm  r8   r   r   r    __int__  ro  zQTestRandomDist.test_scalar_exception_propagation.<locals>.ThrowingInteger.__int__N)r>   r?   r@   rr  r   r   r   r    ThrowingInteger  rq  rs  r0   )	r-   Zndarrayrc   r  r   r6   rH   r`  r  )r)   rp  Zthrowing_floatrs  Zthrowing_intr   r   r    !test_scalar_exception_propagation  s   
z0TestRandomDist.test_scalar_exception_propagationc                 C   r  )Nr^  p=
ף?r3  r  kappar   gLA?gxyw@gzVR?gpE ?g8&Aпgv @r   rE  )r   r   r   vonmisesr-   rc   r
   r:  r   r   r    test_vonmises  r  zTestRandomDist.test_vonmisesc                 C   s4   t t| j}|jdddd}tt|  d S )NrV   gg5_PG>i@B rv  )r   r   r   rx  r   r-   isfiniterZ   r)   rH   rr   r   r    test_vonmises_small  s   z"TestRandomDist.test_vonmises_smallc                 C   s0   t t| j}|jdtjd}tt| d S )NrV   )r  rw  )r   r   r   rx  r-   rL   r   r+  r{  r   r   r    test_vonmises_nan  s   z TestRandomDist.test_vonmises_nanrw  g     @  4&kCc                 C   st   t t| j}t|j}|jj}|jd|dd}||j_|jd|dd}|dk r/t|| d S t	||ks8J d S )Nr   r   r   g    .A)
r   r   r   r   r   r   rx  r   r-   rZ   )r)   rw  rH   rsr   Zrandom_state_valsZgen_valsr   r   r    test_vonmises_large_kappa  s   
z(TestRandomDist.test_vonmises_large_kappar  g      gg	@)rv   gư>r0   g     @@r  c                 C   sF   t t| j}|||d}tt|tj kot|tjk d S )Nr   )r   r   r   rx  r   r-   rZ   rg  )r)   r  rw  rH   r|  r   r   r    test_vonmises_large_kappa_range$  s   *z.TestRandomDist.test_vonmises_large_kappa_rangec                 C   r  )Nr^  ru  r3  )r   r  r   g*س2?gt	@g;S@g\ F@gxF @g6b?r   rE  )r   r   r   waldr-   rc   r
   r:  r   r   r    	test_wald+  r  zTestRandomDist.test_waldc                 C   r  )Nr^  r3  r1  gnJZ?g*/F?gs(RY?g]'%?g,qD?g8 ?r   rE  )r   r   r   weibullr-   rc   r
   r:  r   r   r    test_weibull3  r  zTestRandomDist.test_weibullc                 C   s<   t t| j}t|jdddtd tt|jdd d S )Nr   r   r1  r  )r\  )	r   r   r   r   r  r-   rG   r   r7   r  r   r   r    test_weibull_0;  s   zTestRandomDist.test_weibull_0c                 C   sF   t t| j}|jddd}tddgddgddgg}t|| d S )	Nr^  r3  r1  r0   r   ic  ib  rB   )r   r   r   zipfr-   rc   r	   r:  r   r   r    	test_zipf@  r  zTestRandomDist.test_zipf)r>   r?   r@   r   r;  r?  rA  rD  rH  rJ  rK  rz   r   r   r-   ry   ra   Zfloat64r   rL  rM  rP  rT  rX  r[  ra  rb  rc  rf  rk  rm  ro  rp  rr  rt  r  r  r  r  r  r  r  r  r  r  rC   r  rc   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  rd  rL   r  r  skipifr   r  r  r  r   r  r  r   r$  r)  r-  r/  r0  r4  r7  r8  r:  r<  r=  r?  rC  rF  rK  rL  rM  rQ  rR  rS  rT  rU  rV  rX  r]  ra  rf  ri  rj  rt  ry  r}  r~  r  rg  r  r  r  r  r  r   r   r   r    r/    s8   


		.			
	


	
$I

			$r/  c                	   @   sT  e Z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d)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"e#j$%dAdBe&'dBdBge&'dBggdBggggdCdD Z(dEdF Z)dGdH Z*dIS )JTestBroadcastc                 C   r~   )Ni[r   r8   r   r   r    r   L  r   zTestBroadcast.setup_methodc                 C   s   t t| j}dg}dg}|j}tg d}t t| j}||d |}t||dd t t| j}|||d }t||dd d S )Nr   r0   )g4
7^?gF]
"?g .?rm   r   rE  r_  )r)   rH   r  r  r`  r  r  r   r   r    ra  O  s   zTestBroadcast.test_uniformc                 C   s   dg}dg}dg}t t| j}tg d}t t| j}||d |}t||dd tt|j|d | t t| j}|j}|||d }t||dd tt|||d  d S )Nr   r0   r4   )gw-Dؿgn0_x?gʊ;<.?rm   r   rE  )	r   r   r   r-   rc   r.  r
   r   r7   )r)   r  r  	bad_scalerH   r  r  r.  r   r   r    r/  ^  s   zTestBroadcast.test_normalc           	      C   s   dg}dg}dg}dg}t g d}tt| j}|j}||d |}t||dd tt||d | tt||d | tt| j}|||d }t||dd d S )	Nr0   rB   r4   r:   )gf8?g%eo?g$q??rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )	r)   r\  r]  bad_aZbad_br  rH   r  r  r   r   r    r  p  s   zTestBroadcast.test_betac                 C   Z   dg}dg}t g d}tt| j}||d }t||dd tt|j|d  d S Nr0   r4   )g`ʄ?gE]?g?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   r)   r  r  r  rH   r  r   r   r    r       zTestBroadcast.test_exponentialc                 C   s\   dg}dg}t g d}tt| j}|j}||d }t||dd tt||d  d S r  )	r-   rc   r   r   r   rJ  r
   r   r7   )r)   rb   	bad_shaper  rH   Z	std_gammar  r   r   r    rK    s   z!TestBroadcast.test_standard_gammac           	      C      dg}dg}dg}dg}t g d}tt| j}|j}||d |}t||dd tt||d | tt||d | tt| j}|j}|||d }t||dd tt|||d  tt|||d  d S )	Nr0   rB   r4   r:   )g3ʄ?gJE]?g?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )	r)   rb   r  r  r  r  rH   r  r  r   r   r    r    "   zTestBroadcast.test_gammac           	      C   r  )	Nr0   rB   r4   r:   )gM3B?gybi@g0?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )	r)   r&  r'  	bad_dfnum	bad_dfdenr  rH   r  r  r   r   r    r    r  zTestBroadcast.test_fc              	   C   s  dg}dg}dg}dg}dg}dg}t g d}tt| j}|j}	|	|d ||}
t|
|dd	 t t |	||t j	gd sDJ t
t|	|d || t
t|	|d || t
t|	|d || tt| j}|j}	|	||d |}
t|
|dd	 t
t|	||d | t
t|	||d | t
t|	||d | tt| j}|j}	|	|||d }
t|
|dd	 t
t|	|||d  t
t|	|||d  t
t|	|||d  d S )
NrB   rm   r   r   r4   r:   )gŜ,n1 @g!6)@g9?r   rE  )r-   rc   r   r   r   r(  r
   rZ   r+  rL   r   r7   )r)   r&  r'  r"  r  r  bad_noncr  rH   Znonc_fr  r   r   r    r)    s:   $zTestBroadcast.test_noncentral_fc                 C   s@   t t| j}tddg}|jddddd}t||dd d S )NgZ\#?gDqw?ri   rB   r   r   rE  )r   r   r   r-   rc   r(  r
   )r)   rH   r  r  r   r   r    test_noncentral_f_small_df  s   z(TestBroadcast.test_noncentral_f_small_dfc                 C   r  )Nr0   r4   )gC{?g7Q#?g%h1T@rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   r)   r!  bad_dfr  rH   r  r   r   r    r    r  zTestBroadcast.test_chisquarec           	      C   r  )	Nr0   rB   r4   r:   )g-S?g[@gr3/.?rm   r   rE  )	r-   rc   r   r   r   r#  r
   r   r7   )	r)   r!  r"  r  r  r  rH   Znonc_chir  r   r   r    r$    r  z'TestBroadcast.test_noncentral_chisquarec                 C   r  )Nr0   r4   )g>Qg{g,e?rm   r   rE  )	r-   rc   r   r   r   rW  r
   r   r7   r  r   r   r    rX  	  r  zTestBroadcast.test_standard_tc                 C   s   dg}dg}dg}t g d}tt| j}||d |}t||dd tt|j|d | tt| j}|||d }t||dd tt|j||d  d S )NrB   r0   r4   )gD()@g,)ʸ@gPorm   r   rE  )	r-   rc   r   r   r   rx  r
   r   r7   )r)   r  rw  Z	bad_kappar  rH   r  r   r   r    ry    s   zTestBroadcast.test_vonmisesc                 C   r  )Nr0   r4   )g/h?gcE?g/gV?rm   r   rE  )	r-   rc   r   r   r   r2  r
   r   r7   r)   r\  r  r  rH   r  r   r   r    r4  #  r  zTestBroadcast.test_paretoc                 C   r  r  )	r-   rc   r   r   r   r  r
   r   r7   r  r   r   r    r  -  r  zTestBroadcast.test_weibullc                 C   r  )Nr0   r4   )gT?gʥ?gKܮc?rm   r   rE  )	r-   rc   r   r   r   r9  r
   r   r7   r  r   r   r    r:  7  r  zTestBroadcast.test_powerc                 C      dg}dg}dg}t g d}tt| j}|j}||d |}t||dd tt||d | tt| j}|j}|||d }t||dd tt|||d  d S )Nr   r0   r4   )gh&BgsgR#?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )r)   r  r  r  r  rH   r  r  r   r   r    r  A     zTestBroadcast.test_laplacec                 C   r  )Nr   r0   r4   )gs4?g$Cw%T?gտrm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )r)   r  r  r  r  rH   r  r  r   r   r    r  S  r  zTestBroadcast.test_gumbelc                 C   s   dg}dg}dg}t g d}tt| j}||d |}t||dd tt|j|d | tt| j}|||d }t||dd tt|j||d  t	|dd	d d S )
Nr   r0   r4   )g$DgXPg,?rm   r   rE  r  rV   )
r-   rc   r   r   r   r  r
   r   r7   r   )r)   r  r  r  r  rH   r  r   r   r    r  e  s   zTestBroadcast.test_logisticc                 C   s   dg}dg}dg}t g d}tt| j}|j}||d |}t||dd tt||d | tt| j}|||d }tt|j||d  d S )Nr   r0   r4   )g c?gu@gVQ?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )r)   r   r  Z	bad_sigmar  rH   r  r  r   r   r    r  v  s   zTestBroadcast.test_lognormalc                 C   r  )Nr0   r4   )gs(?g4mK?gVk+?rm   r   rE  )	r-   rc   r   r   r   r;  r
   r   r7   r  r   r   r    r<    s   zTestBroadcast.test_rayleighc                 C   s   dg}dg}dg}dg}t g d}tt| j}||d |}t||dd tt|j|d | tt|j|d | tt| j}|||d }t||dd tt|j||d  tt|j||d  d S )	NrF   r0   r   r:   )gk7Z?g*}z9?gc-	?rm   r   rE  )	r-   rc   r   r   r   r  r
   r   r7   )r)   r   r  Zbad_meanr  r  rH   r  r   r   r    r    s   zTestBroadcast.test_waldc                 C   s  dg}dg}dg}dg}dg}|d \}}t g d}tt| j}	|	j}
|
|d ||}t||dd tt|
|d || tt|
|d || tt|
|d || tt| j}	|	j}
|
||d |}t||dd tt|
||d | tt|
||d | tt|
||d | tt| j}	|	j}
|
|||d }t||dd tt|
|||d  tt|
|||d  tt|
|||d  tt|
dd	d
 tt|
ddd
 tt|
ddd d S )Nr0   rm   rB   r   )gR8T>?gK?g;>h@r   rE  rN  rV   g      4@g      9@)	r-   rc   r   r   r   r\  r
   r   r7   )r)   rY  r[  rZ  Zbad_left_oneZbad_mode_oneZbad_left_twoZbad_mode_twor  rH   r\  r  r   r   r    r]    sJ   
zTestBroadcast.test_triangularc           
      C   s   dg}dg}dg}dg}dg}t g d}tt| j}|j}||d |}	t|	| tt||d | tt||d | tt||d | tt| j}|||d }	t|	| tt|||d  tt|||d  tt|||d  d S )Nr0   rF   r4   r  r   r   r0   rm   )	r-   rc   r   r   r   rI   r	   r   r7   )
r)   r  rJ   bad_n	bad_p_one	bad_p_twor  rH   Zbinomr  r   r   r    r    s&   

zTestBroadcast.test_binomialc           
      C   s   dg}dg}dg}dg}dg}t jg dt jd}tt| j}|j}||d |}	t|	| tt	||d | tt	||d | tt	||d | tt| j}|j}|||d }	t|	| tt	|||d  tt	|||d  tt	|||d  d S )Nr0   rF   r4   r  )r   rB   r0   rD   rm   )
r-   rc   r   r   r   r   r   r	   r   r7   )
r)   r  rJ   r  r  r  r  rH   Z	neg_binomr  r   r   r    r     s(   

z$TestBroadcast.test_negative_binomialc           	      C   sx   dg}dg}t g d}tt| j}|j}|d g}|j}||d }t|| tt	||d  tt	||d  d S )Nr0   r4   )r   r   rm   rB   rm   )
r-   rc   r   r   r   Z_poisson_lam_maxr6  r	   r   r7   )	r)   r5  Zbad_lam_oner  rH   Zmax_lamZbad_lam_twor6  r  r   r   r    r7    s   

zTestBroadcast.test_poissonc                 C   s   dg}dg}t g d}tt| j}|j}||d }t|| tt||d  t j	dd tt|t j
 tt|ddt j
g W d    d S 1 sMw   Y  d S )NrB   r   )r0   r   r0   rm   r  r  )r-   rc   r   r   r   r  r	   r   r7   r  rL   )r)   r\  r  r  rH   r  r  r   r   r    r  	  s   
"zTestBroadcast.test_zipfc                 C   n   dg}dg}dg}t g d}tt| j}|j}||d }t|| tt||d  tt||d  d S )NrF   r4   r  r   rm   )	r-   rc   r   r   r   r  r	   r   r7   )r)   rJ   r  r  r  rH   r  r  r   r   r    r  	     
zTestBroadcast.test_geometricc                 C   s2  dg}dg}dg}dg}dg}dg}dg}t g d}tt| j}	|	|d ||}
t|
| tt|	j|d || tt|	j|d || tt|	j|d || tt|	j|d || tt| j}	|	||d |}
t|
| tt|	j||d | tt|	j||d | tt|	j||d | tt|	j||d | tt| j}	|	j}||||d }
t|
| tt||||d  tt||||d  tt||||d  tt||||d  tt|ddd	 tt|ddd	 tt|ddd tt|ddd
 tt|ddd	 tt|ddd tt|dddgd d S )Nr0   rB   r4   r:   r   r  rm   r   r   r   i   @i  l        r   i    r#   )	r-   rc   r   r   r   r  r	   r   r7   )r)   ZngoodZnbadr   Z	bad_ngoodZbad_nbadZbad_nsample_oneZbad_nsample_twor  rH   r  Z	hypergeomr   r   r    r  (	  sJ   


z!TestBroadcast.test_hypergeometricc                 C   r  )NrF   rB   r4   )r0   r0   r0   rm   )	r-   rc   r   r   r   r   r	   r   r7   )r)   rJ   r  r  r  rH   r   r  r   r   r    r  U	  r  zTestBroadcast.test_logseriesc                 C   sn  t t| j}|jddgdgd dd}tjg dg dgg d	g d
gg dg dggtjd}t|| t t| j}|ddgdgd }tjg dg dgtjd}t|| t t| j}|ddgdgd gd }tjg dg dgtjd}t|| t t| j}|dgdggdgd gd }tjg dg dgg dg d
ggtjd}t|| d S )NrY   r   r  r   r3  r   )r   r   rB   r0   rB   r   )rB   rm   r   r   rB   rm   )r0   r   r0   r   rB   r0   )r   rB   rB   r0   r   r   )r   rB   r   r0   rB   r   )rm   rB   rm   rm   r   rY   rD   rB   )r   r   rB   r0   r0   r0   )r   rB   rm   rm   rY   rm   )r   r   r   rS   r-   rc   r   r	   r:  r   r   r    r  b	  sV   





 
zTestBroadcast.test_multinomialr  r   c                 C   sH  t t| j}tdgd }|||}t|trt n|j	}|d }|j	|ks+J t
||g}|||}t||j	d d d }|j	|ksLJ t
|g|gg}|||}t||j	d d }|j	|d ksoJ |j||d| d}|j	d| d ksJ tt |j||dd}W d    d S 1 sw   Y  d S )Nre  r   )r   r4   r3  r   )r0   r0   r0   r0   r0   r0   )r   r   r   r-   rc   rS   r   rC   rg  rb   r  Zbroadcast_shapesrz   r{   r7   )r)   r  rH   ro   r  Zn_shaper   r   r   r    test_multinomial_pval_broadcast	  s&   "z-TestBroadcast.test_multinomial_pval_broadcastc                 C   sF   t t| j}dgd dgd g}tt|jd| tt|jdd d S )Nr  r   re  r0   rF   )r   r   r   r   r7   rS   )r)   rH   ro   r   r   r    test_invalid_pvals_broadcast	  s   z*TestBroadcast.test_invalid_pvals_broadcastc                 C   s   t t| j}|tdddgd }|jdksJ |dtd}|jdks+J |tddtd	}|jd	ks?J d S )
N)r   r   r   i8r  r   )r   r   r   r   r   )r   r   r   )rm   r   r   )rm   r   r   r   )r   r   r   rS   r-   r   rb   r,  r   r   r    test_empty_outputs	  s   z TestBroadcast.test_empty_outputsN)+r>   r?   r@   r   ra  r/  r  r  rK  r  r  r)  r  r  r$  rX  ry  r4  r  r:  r  r  r  r  r<  r  r]  r  r   r7  r  r  r  r  r  rz   r   r   r-   rc   r  r  r  r   r   r   r    r  I  sP    
#




(-

r  zcan't start threadr  c                   @   4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )
TestThreadc                 C   s   t d| _d S )Nr   )r,   seedsr8   r   r   r    r   	  s   zTestThread.setup_methodc                    s   ddl m  tt| jf| }tt| jf| } fddt| j|D }dd |D  dd |D  t| j|D ]\}}tt|| q>t	 j
jdkr`tjdkr`t|| d S t|| d S )	Nr   )Threadc                    s(   g | ]\}} t t||fd qS ))targetargs)r   r   )r~  r*   or  functionr   r    r  	  s    z-TestThread.check_function.<locals>.<listcomp>c                 S      g | ]}|  qS r   )startr~  r\   r   r   r    r  	  r  c                 S   r  r   )joinr  r   r   r    r  	  r  r   win32)	threadingr  r-   r   r  r  zipr   r   ZintprE   r   r   platformr
   r	   )r)   r  szZout1Zout2tr*   r  r   r  r    check_function	  s   
zTestThread.check_functionc                 C      dd }| j |dd d S )Nc                 S   s   | j dd|d< d S )Nrq  r   .)r.  r   r  r   r   r    
gen_random	  rU   z*TestThread.test_normal.<locals>.gen_random)rq  r  r  r)   r  r   r   r    r/  	     zTestThread.test_normalc                 C   r  )Nc                 S   s   | j tdd|d< d S )NrO   r#   r  .)r  r-   rn  r  r   r   r    r  	  s   z'TestThread.test_exp.<locals>.gen_randomr  r  r  r  r   r   r    test_exp	  r  zTestThread.test_expc                 C   r  )Nc                 S   s   | j ddgd dd|d< d S )Nr   r  r   rq  r   .)rS   r  r   r   r    r  	  s   z/TestThread.test_multinomial.<locals>.gen_random)rq  r   r  r  r  r   r   r    r  	  r  zTestThread.test_multinomialN)r>   r?   r@   r   r  r/  r  r  r   r   r   r    r  	  s    r  c                   @   r  )TestSingleEltArrayInputc                 C   s4   t dg| _t dg| _t dg| _d| _d S )NrB   rm   r   r  )r-   rc   argOneargTwoargThreetgtShaper8   r   r   r    r   	  s   
z$TestSingleEltArrayInput.setup_methodc                 C   s   t jt jt jt jt jt jt jt jt j	t j
t jt jf}t jt jf}|D ]}||v r1|tdg}n|| j}t|j| j q"d S r   )rH   r  rJ  r  rW  r2  r  r9  r;  r6  r  r  r   r-   rc   r  r   rb   r  )r)   funcs	probfuncsre  r  r   r   r    test_one_arg_funcs	  s   
z*TestSingleEltArrayInput.test_one_arg_funcsc                 C   s   t jt jt jt jt jt jt jt jt j	t j
t jt jt jt jf}t jt jf}|D ];}||v r3tdg}n| j}|| j|}t|j| j || jd |}t|j| j || j|d }t|j| j q&d S )NrF   r   )rH   r`  r.  r  r  r  r#  rx  r  r  r  r  r  rI   r   r-   rc   r  r  r   rb   r  )r)   r  r  re  r  r  r   r   r    test_two_arg_funcs	  s(   z*TestSingleEltArrayInput.test_two_arg_funcsc              	   C   s   t jt jt jt jt jt jt jt jt j	g	}t
j}t dg}t dg}|D ]3}|||||d}t|j| j ||d |||d}t|j| j |||d ||d}t|j| j q%d S )Nr0   r   r   )r-   r  r   r   r   r   r   ra   r   r   rH   r'   rc   r   rb   r  )r)   r!   r   re  r  r  r   r  r   r   r    r;  
  s   z%TestSingleEltArrayInput.test_integersc                 C   s   t jt jt jg}|D ]6}|| j| j| j}t|j| j	 || jd | j| j}t|j| j	 || j| jd | j}t|j| j	 q
d S )Nr   )
rH   r(  r\  r  r  r  r  r   rb   r  )r)   r  re  r  r   r   r    test_three_arg_funcs$
  s   z,TestSingleEltArrayInput.test_three_arg_funcsN)r>   r?   r@   r   r  r  r;  r  r   r   r   r    r  	  s    r  r  c                 C   s   | d }| d }t |}|| |jd d }tjdkr!| }t|}|jd d | d d ks5J | | d d ksAJ |	 }|jd d }tjdkrU| }t|}|jd d | d	 d ksiJ | | d	 d ksuJ d S )
Nr   r   r   r   r%  r   r   r   r   )
r   r1   r   r   r   r   r   r   r   r   )r  r   r   Zmt19937r   r   r   r   r   r    test_jumped3
  s"   




r  c                  C   sh  t d} t d}d}tj| |ddjdksJ tt tj| ||d W d    n1 s1w   Y  tt tj| |dd W d    n1 sNw   Y  tt tj| |dd W d    n1 skw   Y  t d}tt tj||d W d    n1 sw   Y  tt tj|dd W d    n1 sw   Y  tt tj|dd W d    n1 sw   Y  t 	|}tt tj||d	 W d    n1 sw   Y  tt tj
d
ddgdd W d    n	1 sw   Y  tt tj
d
dgddd W d    n	1 s%w   Y  tt tj
d
dgddgdd W d    n	1 sGw   Y  tt tjddgddgdd W d    n	1 siw   Y  tjddd}tjddd}tjddd}t|||jdksJ tjtdd tj|||dd W d    d S 1 sw   Y  d S )Nrm   )r   rm   )r   r   rB   )rY   r   rm   r   )r0   rm   )r   r0   r0   )rm   r  r0   rY  gffffff?)rB   r0   rB   rY   zOutput size \(6, 5, 1, 1\) isrw   )r   rY   r0   r0   )r-   rn  rH   r.  rb   rz   r{   r7   rJ  r   rI   rS   r  r(  )r  r  r   rb   r  r\  r]  r^  r   r   r    test_broadcast_size_errorO
  s\   



$r  c                  C   sd   t d} t d}tj| |dd tt tj| |dd W d    d S 1 s+w   Y  d S )Nrm   r   rB   )r-   rn  rH   r.  rz   r{   r7   )r  r  r   r   r    test_broadcast_size_scalarz
  s   

"r  c                  C   s8   g g dg} t td}t|j|  | dg g gksJ d S r  )r   r   r   rW  )seqgenr   r   r    test_ragged_shuffle
  s   
r  r  r:   c                 C   s   t td}|r
dnd}tjt|d |j| |d W d    n1 s%w   Y  |r.dnd}tjt|d |jd| |d W d    n1 sJw   Y  tjt|d |jdg| |d W d    d S 1 skw   Y  d S )	Nr   zhigh < 0z	high <= 0rw   rC  z
low > highzlow >= highr4   )r   r   rz   r{   r7   r'   )r  r!   r  msgr   r   r    !test_single_arg_integer_exception
  s   "r  rE   Zf4Zf8c                 C   s   t jdd| d}g d}tjtdd tj||| d W d    n1 s&w   Y  tjtdd tj|||j| d W d    d S 1 sHw   Y  d S )	Nr   F)orderrE   r   zSupplied output arrayrw   rO  rP  )r-   r   rz   r{   r7   rH   rJ  rb   )rE   r  rb   r   r   r    test_c_contig_req_out
  s   "r  r  r  Cdistc                 C   sH   t jd||d}| ||d}||u sJ | |||jd}||u s"J d S )Nr   )rE   r  rO  )r  rE   r   )r-   r   rb   )r  r  rE   r  Zvariatesr   r   r    test_contig_req_out
  s
   r  c                  C   sp   t jt jd} | d |  \}}}|d d dks J ||d d  }||j_|jj}||ks6J d S )Nr   r0   )	PCG64DXSM)r-   rH   r   r  r   
__reduce__r   r   )r   Zctorr  Zstate_ar]  Zstate_br   r   r    $test_generator_ctor_old_style_pickle
  s   
r  )1r   r   rz   numpyr-   Znumpy.linalgr   Znumpy.testingr   r   r   r   r   r   r	   r
   r   r   Znumpy.randomr   r   r   r   rH   ZJUMP_TEST_DATAZfixturer!   r"   rA   rN   r}   r   r   r/  r  r   r  r  r  r   r  r  r  r  r  r  r   r  r  r   r   r   r    <module>   s    0

$7 "                i/U
+

	