@@ -23,28 +23,29 @@ from cython_overrides cimport PyFloat_AsDouble, PyInt_AsLong, PyErr_Occurred, Py
23
23
np .import_array ()
24
24
25
25
include "config.pxi"
26
+ include "defaults.pxi"
26
27
27
- IF RNG_MOD_NAME == 'pcg32' :
28
+ IF RS_RNG_MOD_NAME == 'pcg32' :
28
29
include "shims/pcg-32/pcg-32.pxi"
29
- IF RNG_MOD_NAME == 'pcg64' :
30
- IF PCG128_EMULATED :
30
+ IF RS_RNG_MOD_NAME == 'pcg64' :
31
+ IF RS_PCG128_EMULATED :
31
32
include "shims/pcg-64/pcg-64-emulated.pxi"
32
33
ELSE :
33
34
include "shims/pcg-64/pcg-64.pxi"
34
- IF RNG_MOD_NAME == 'mt19937' :
35
+ IF RS_RNG_MOD_NAME == 'mt19937' :
35
36
include "shims/random-kit/random-kit.pxi"
36
- IF RNG_MOD_NAME == 'xorshift128' :
37
+ IF RS_RNG_MOD_NAME == 'xorshift128' :
37
38
include "shims/xorshift128/xorshift128.pxi"
38
- IF RNG_MOD_NAME == 'xorshift1024' :
39
+ IF RS_RNG_MOD_NAME == 'xorshift1024' :
39
40
include "shims/xorshift1024/xorshift1024.pxi"
40
- IF RNG_MOD_NAME == 'mrg32k3a' :
41
+ IF RS_RNG_MOD_NAME == 'mrg32k3a' :
41
42
include "shims/mrg32k3a/mrg32k3a.pxi"
42
- IF RNG_MOD_NAME == 'mlfg_1279_861' :
43
+ IF RS_RNG_MOD_NAME == 'mlfg_1279_861' :
43
44
include "shims/mlfg-1279-861/mlfg-1279-861.pxi"
44
- IF RNG_MOD_NAME == 'dsfmt' :
45
+ IF RS_RNG_MOD_NAME == 'dsfmt' :
45
46
include "shims/dSFMT/dSFMT.pxi"
46
47
47
- IF NORMAL_METHOD == 'inv' :
48
+ IF RS_NORMAL_METHOD == 'inv' :
48
49
__normal_method = 'inv'
49
50
ELSE :
50
51
__normal_method = 'zig'
@@ -139,11 +140,11 @@ cdef class RandomState:
139
140
poisson_lam_max = POISSON_LAM_MAX
140
141
__MAXSIZE = < uint64_t > sys .maxsize
141
142
142
- IF RNG_SEED == 1 :
143
+ IF RS_RNG_SEED == 1 :
143
144
def __init__ (self , seed = None ):
144
145
self .rng_state .rng = < rng_t * > PyArray_malloc_aligned (sizeof (rng_t ))
145
146
self .rng_state .binomial = & self .binomial_info
146
- IF RNG_MOD_NAME == 'dsfmt' :
147
+ IF RS_RNG_MOD_NAME == 'dsfmt' :
147
148
self .rng_state .buffered_uniforms = < double * > PyArray_malloc_aligned (2 * DSFMT_N * sizeof (double ))
148
149
self .lock = Lock ()
149
150
self ._reset_state_variables ()
@@ -158,7 +159,7 @@ cdef class RandomState:
158
159
159
160
def __dealloc__ (self ):
160
161
PyArray_free_aligned (self .rng_state .rng )
161
- IF RNG_MOD_NAME == 'dsfmt' :
162
+ IF RS_RNG_MOD_NAME == 'dsfmt' :
162
163
PyArray_free_aligned (self .rng_state .buffered_uniforms )
163
164
164
165
# Pickling support:
@@ -169,9 +170,9 @@ cdef class RandomState:
169
170
self .set_state (state )
170
171
171
172
def __reduce__ (self ):
172
- return (randomstate .prng .__generic_ctor , (RNG_MOD_NAME ,), self .get_state ())
173
+ return (randomstate .prng .__generic_ctor , (RS_RNG_MOD_NAME ,), self .get_state ())
173
174
174
- IF RNG_NAME == 'mt19937' :
175
+ IF RS_RNG_NAME == 'mt19937' :
175
176
def seed (self , seed = None ):
176
177
"""
177
178
seed(seed=None)
@@ -212,7 +213,7 @@ cdef class RandomState:
212
213
set_seed_by_array (& self .rng_state , < unsigned long * > np .PyArray_DATA (obj ), np .PyArray_DIM (obj , 0 ))
213
214
self ._reset_state_variables ()
214
215
215
- ELIF RNG_SEED == 1 :
216
+ ELIF RS_RNG_SEED == 1 :
216
217
def seed (self , val = None ):
217
218
"""
218
219
seed(seed=None)
@@ -272,8 +273,8 @@ cdef class RandomState:
272
273
raise ValueError ('val < 0' )
273
274
if inc < 0 :
274
275
raise ValueError ('inc < 0' )
275
- IF RNG_NAME == 'pcg64' :
276
- IF PCG128_EMULATED :
276
+ IF RS_RNG_NAME == 'pcg64' :
277
+ IF RS_PCG128_EMULATED :
277
278
set_seed (& self .rng_state ,
278
279
pcg128_from_pylong (val ),
279
280
pcg128_from_pylong (inc ))
@@ -292,7 +293,7 @@ cdef class RandomState:
292
293
self .rng_state .uinteger = 0
293
294
self .rng_state .binomial .has_binomial = 0
294
295
295
- IF RNG_ADVANCEABLE :
296
+ IF RS_RNG_ADVANCEABLE :
296
297
def advance (self , delta ):
297
298
"""
298
299
advance(delta)
@@ -314,8 +315,8 @@ cdef class RandomState:
314
315
Advancing the prng state resets any pre-computed random numbers.
315
316
This is required to ensure exact reproducibility.
316
317
"""
317
- IF RNG_NAME == 'pcg64' :
318
- IF PCG128_EMULATED :
318
+ IF RS_RNG_NAME == 'pcg64' :
319
+ IF RS_PCG128_EMULATED :
319
320
advance_state (& self .rng_state , pcg128_from_pylong (delta ))
320
321
ELSE :
321
322
advance_state (& self .rng_state , delta )
@@ -326,7 +327,7 @@ cdef class RandomState:
326
327
self .rng_state .gauss = 0.0
327
328
return None
328
329
329
- IF RNG_JUMPABLE :
330
+ IF RS_RNG_JUMPABLE :
330
331
def jump (self , uint32_t iter = 1 ):
331
332
"""
332
333
jump(iter = 1)
@@ -356,7 +357,7 @@ cdef class RandomState:
356
357
self .rng_state .gauss = 0.0
357
358
return None
358
359
359
- IF RNG_NAME == 'mt19937' :
360
+ IF RS_RNG_NAME == 'mt19937' :
360
361
def get_state (self , legacy = False ):
361
362
"""
362
363
get_state()
@@ -394,11 +395,11 @@ cdef class RandomState:
394
395
component, see the class documentation.
395
396
"""
396
397
if legacy :
397
- return (RNG_NAME ,) \
398
+ return (RS_RNG_NAME ,) \
398
399
+ _get_state (self .rng_state ) \
399
400
+ (self .rng_state .has_gauss , self .rng_state .gauss )
400
401
401
- return {'name' : RNG_NAME ,
402
+ return {'name' : RS_RNG_NAME ,
402
403
'state' : _get_state (self .rng_state ),
403
404
'gauss' : {'has_gauss' : self .rng_state .has_gauss , 'gauss' : self .rng_state .gauss },
404
405
'uint32' : {'has_uint32' : self .rng_state .has_uint32 , 'uint32' : self .rng_state .uinteger }
@@ -435,7 +436,7 @@ cdef class RandomState:
435
436
For information about the specific structure of the PRNG-specific
436
437
component, see the class documentation.
437
438
"""
438
- return {'name' : RNG_NAME ,
439
+ return {'name' : RS_RNG_NAME ,
439
440
'state' : _get_state (self .rng_state ),
440
441
'gauss' : {'has_gauss' : self .rng_state .has_gauss , 'gauss' : self .rng_state .gauss },
441
442
'uint32' : {'has_uint32' : self .rng_state .has_uint32 , 'uint32' : self .rng_state .uinteger }
@@ -478,8 +479,8 @@ cdef class RandomState:
478
479
For information about the specific structure of the PRNG-specific
479
480
component, see the class documentation.
480
481
"""
481
- rng_name = RNG_NAME
482
- IF RNG_NAME == 'mt19937' :
482
+ rng_name = RS_RNG_NAME
483
+ IF RS_RNG_NAME == 'mt19937' :
483
484
if isinstance (state , tuple ):
484
485
if state [0 ] != 'MT19937' :
485
486
raise ValueError ('Not a ' + rng_name + ' RNG state' )
@@ -4227,7 +4228,7 @@ permutation = _rand.permutation
4227
4228
4228
4229
sample = ranf = random = random_sample
4229
4230
4230
- IF RNG_JUMPABLE :
4231
+ IF RS_RNG_JUMPABLE :
4231
4232
jump = _rand .jump
4232
- IF RNG_ADVANCEABLE :
4233
+ IF RS_RNG_ADVANCEABLE :
4233
4234
advance = _rand .advance
0 commit comments