66try :
77 import mkl_random as rnd
88 mkl = True
9- except ImportError :
9+ except ( ImportError , ModuleNotFoundError ) :
1010 import numpy .random as rnd
1111 mkl = False
1212import timeit
@@ -28,7 +28,12 @@ def sample_beta(rs, sz):
2828
2929
3030def sample_randint (rs , sz ):
31- rs .randint (0 , 100 , size = sz , dtype = np .intc )
31+ if hasattr (rs , 'randint' ):
32+ rs .randint (0 , 100 , size = sz , dtype = np .intc )
33+ elif hasattr (rs , 'integers' ):
34+ rs .integers (0 , 100 , size = sz , dtype = np .intc )
35+ else :
36+ raise RuntimeError
3237
3338
3439def sample_poisson (rs , sz ):
@@ -47,7 +52,7 @@ def main():
4752 if mkl :
4853 brngs = ['WH' , 'PHILOX4X32X10' , 'MT2203' , 'MCG59' , 'MCG31' , 'MT19937' , 'MRG32K3A' , 'SFMT19937' , 'R250' ]
4954 else :
50- brngs = [None ]
55+ brngs = [np . random . MT19937 , np . random . Philox ]
5156 samplers = {'uniform' : sample_uniform , 'normal' : sample_normal , 'gamma' : sample_gamma , 'beta' : sample_beta ,
5257 'randint' : sample_randint , 'poisson' : sample_poisson , 'hypergeom' : sample_hypergeom }
5358 multipliers = {'uniform' : 10 , 'normal' : 2 , 'gamma' : 1 , 'beta' : 1 , 'randint' : 10 , 'poisson' : 5 , 'hypergeom' : 1 }
@@ -56,10 +61,10 @@ def main():
5661 m = multipliers [sfn ]
5762 times_list = []
5863 for __ in range (OUTER_REPS ):
59- if brng_name :
64+ if mkl :
6065 rs = rnd .RandomState (123 , brng = brng_name )
6166 else :
62- rs = rnd .RandomState ( 123 )
67+ rs = rnd .Generator ( brng_name ( seed = 123 ) )
6368 t0 = timeit .default_timer ()
6469 for __ in range (INNER_REPS ):
6570 func (rs , (m * 100 , 1000 ))
0 commit comments