8000 ENH: randomgen by mattip · Pull Request #13163 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: randomgen #13163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 139 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
3102fc6
INIT: Initial commit with basic structure
bashtage Feb 20, 2018
fa3bef5
ENH: Add support for xoroshiro128
bashtage Feb 22, 2018
d59494c
ENH: Add entropy initialization to RNGS
bashtage Feb 23, 2018
8942968
ENH: Add seeding to generators
bashtage Feb 23, 2018
aa9060c
CLN: Simplify xoroshiro state
bashtage Feb 24, 2018
b353f87
REF: Add additional state
bashtage Feb 26, 2018
15cab3c
REF: Reactor filler to take a function
bashtage Feb 28, 2018
8367231
ENH: Add extra abstraction
bashtage Feb 28, 2018
d5dc576
ENH: Add float from double and std exponential
bashtage Feb 28, 2018
f4575d9
BUG: Fix bug in xoroshiro
bashtage Mar 1, 2018
c687b84
CLN: Fix warning in entropy
bashtage Mar 1, 2018
0d4eae3
REF: Add types to prng_t 8000
bashtage Mar 1, 2018
27a96bb
ENH: Add Threefry generator
bashtage Mar 2, 2018
a5f17a5
ENH: Use Random123 threefry
bashtage Mar 2, 2018
56fd6e7
CLN: Remove unnecessary code from threefry
bashtage Mar 2, 2018
93b7edf
ENH: Add pickle support
bashtage Mar 3, 2018
d665138
DOC: Add list of TODOs
bashtage Mar 3, 2018
892d43f
BIG: Fix setting state in threee fry
bashtage Mar 3, 2018
ad79fe0
ENH: Add jump and advance to threefry
bashtage Mar 3, 2018
4b2afc2
ENH: Add PCG64
bashtage Mar 4, 2018
6b81fa0
ENH: Add advance and jump to PCG64
bashtage Mar 4, 2018
e150e1a
ENH: Add Philox
bashtage Mar 5, 2018
d6d3ac9
CLN: Remove splitmix64 as a visible PRNG
bashtage Mar 5, 2018
323616c
BUG: Fix bugs which prevented building on Linux
bashtage Mar 5, 2018
626a1a0
REF: Refactor distributions
bashtage Mar 5, 2018
5fe7572
ENH: Add std gamma
bashtage Mar 5, 2018
cecd56d
CLN: Clean random123 generators
bashtage Mar 6, 2018
a071378
CLN: Fix dsfmt import issues
bashtage Mar 7, 2018
eab3390
ENH: Enable Python 2.7 compatability
bashtage Mar 7, 2018
c3155db
ENH: Add jump to mt19937 and dsfmt
bashtage Mar 7, 2018
e9e0a8c
ENH: Add ctypes interface and examples
bashtage Mar 7, 2018
0e5ffae
CLN: Mix skipped nogils
bashtage Mar 7, 2018
5d274af
ENH: Add cffi interface
bashtage Mar 7, 2018
2f9b9c0
ENH: Add example using distributions
bashtage Mar 8, 2018
fcef7ae
ENH: Enable building distributions as a DLL
bashtage Mar 8, 2018
1235545
ENH: Port over external functions
bashtage Mar 8, 2018
7ca6e62
ENH: Add bounded intergers
bashtage Mar 9, 2018
cfe9e95
ENH: Add support for Philon on 32 bit Windows
bashtage Mar 11, 2018
390860a
ENH: Add support for ThreeFry32x4
bashtage Mar 12, 2018
8fa8c2b
BUG: Enable build to run on 32-bit Linux
bashtage Mar 12, 2018
644d883
ENH: Add PCG32
bashtage Mar 12, 2018
e81e93f
BUG: Fix variable declarations in dsfmt
bashtage Mar 12, 2018
76a31a9
ENH: Enable testing on OSX
bashtage Mar 12, 2018
c1f4fa0
REF: Drop Box-Muller
bashtage Mar 13, 2018
ee51dcf
REF: Remove binomial_t from prng
bashtage Mar 13, 2018
fde7742
ENH: Switch to int64
bashtage Mar 13, 2018
fb98ac5
DOC: Start documentation
bashtage Mar 14, 2018
cb24575
REF: Rename from Core PRNG to RandomGen
bashtage Mar 14, 2018
c722f44
DOC: Update docs
bashtage Mar 14, 2018
e69d24c
TST: Improve travis
bashtage Mar 14, 2018
a85ee48
BUG: Fix failing test
bashtage Mar 14, 2018
701326e
DOC: Fix location of tagged docs
bashtage Mar 14, 2018
9e18b77
BLD: Ensure emulated math is used in 32 bit platforms
bashtage Mar 16, 2018
3e69d17
CLN: Remove references to long
bashtage Mar 22, 2018
489015f
ENH: Add Box-Muller gauss
bashtage Mar 21, 2018
8711b32
DOC: Update multithreading doc
bashtage Mar 27, 2018
018faf7
CLN: Remove set/get state for system generator
bashtage Mar 27, 2018
75025d9
TST: Fix tailing test on 32bit platofrms
bashtage Mar 27, 2018
4f37499
CLN: Fix str for RandomGenerator
bashtage Mar 28, 2018
7d37f5f
DOC: Update legacy docs
bashtage Mar 28, 2018
a2e21e6
BUG: Fix pickle for LegacyGenerator
bashtage Mar 28, 2018
d13f398
DOC: Spelling changes
bashtage Apr 2, 2018
df1758d
CLN: Remove redeclared type
bashtage Apr 2, 2018
412e908
BLD: Enable no-sse2 flag
bashtage Apr 3, 2018
87b52f2
SYNC/CLN: Sync with upstream changes
bashtage Apr 16, 2018
db87d7d
BLD: Add lm flag for non-windows platforms
bashtage May 2, 2018
b41949e
ENH: Add dSFMT
bashtage Mar 5, 2018
a9cb58d
ENH: Add out, ziggurat for exponential
bashtage Mar 5, 2018
92a09f3
TST: Add test and benchmark code
bashtage Mar 6, 2018
f029ebb
ENH: Improve benchmark
bashtage Mar 6, 2018
8777c61
CLN: Reformat C files
bashtage Mar 7, 2018
784315e
ENH: Example numba example using external distributions
bashtage Mar 8, 2018
5b262ef
BUG: Precent GC of CorePRNG when using CFFI/CTypes
bashtage Mar 8, 2018
65ceada
TST: Add tests
bashtage Mar 9, 2018
3b7b1e4
DOC: Update readme
bashtage Mar 11, 2018
a8882b2
CLN: Remove small bugs and alter variable size
bashtage Mar 12, 2018
dc0c84b
BUG: Fix returned type
bashtage Mar 13, 2018
f060614
DOC: Update docs and building
bashtage Mar 14, 2018
5d3d955
ENH: Restore filler
bashtage Mar 15, 2018
ce30b74
TST: Improve testing and build
bashtage Mar 17, 2018
447e6b3
DOC: Update change-log and docs
bashtage Mar 17, 2018
50e7242
BUG: Restore nogil for fillers
bashtage Mar 21, 2018
799e20b
TST: Make test more verbose, clean up noise
bashtage Mar 28, 2018
80a3fe1
BUG: Fix absolute_import
bashtage Apr 2, 2018
d780f06
DOC: Fix doc and example error
pdebuyl May 22, 2018
fdd029f
REF: Rename min and max macros
bashtage Jun 14, 2018
3dba22d
MAINT: Sync with NumPy changes
bashtage Jun 19, 2018
f2ace10
ENH: Allow empty choice
bashtage Jul 3, 2018
d0cb154
DOC: Provide a better explanation of bounded int generation
bashtage Sep 22, 2018
8e6b69f
MAINT: Sync with recent upstream changes
bashtage Sep 22, 2018
99bf1a0
DOC: Update docs for 1.15 release [skip ci]
bashtage Sep 22, 2018
8dba0e9
ENH: Added an alternative interval generator using Lemire's algorithm.
bduvenhage Oct 3, 2018
13d8999
DOC: Add license files
bashtage Oct 5, 2018
707371d
REF: Add path using umul
bashtage Oct 5, 2018
15bebed
ENH: Added Lemire algorithms for generating random numbers
bduvenhage Oct 11, 2018
734fbfb
CLN: Add guards to headers
bashtage Oct 21, 2018
c4ed60e
ENH/BUG: Add Xoshiro256starstar generator
bashtage Oct 20, 2018
9dac6a5
MAINT: Sync with upstream changes
bashtage Nov 5, 2018
578889b
BUG: Ensure buffer_loc is reset in DSFMT
bashtage Feb 4, 2019
896f2e4
BUG: Raise on nan probabilities
bashtage Feb 4, 2019
fa8af41
BUILD: move files out of _randomgen
mattip Mar 20, 2019
7e8e19f
BUG: Correct handling of nans
bashtage Apr 8, 2019
c53b2eb
BENCH: convert bencmarks to asv format
mattip Apr 9, 2019
9578dcf
BUG: __dealloc__ can be called without __init__ in some error modes
mattip Apr 12, 2019
0f3dd06
ENH: Extend multinomial and fix zipf
bashtage Apr 11, 2019
8a3c11d
DOC: Add alias docstrings for sample and ranf
bashtage Apr 12, 2019
bb7abf2
ENH: add instance of RandomGenerator(Xoshiro512StarStar) as gen
mattip Apr 12, 2019
f11921d
MAINT: Simplify return types
bashtage Apr 12, 2019
0f931b3
BUG: Fix type in zipf
bashtage Apr 13, 2019
b2f9bea
ENH: Improvce choice without replacement
bashtage Apr 13, 2019
7a41794
DOC: fix doctests, move numpy.random -> numpy.random.gen in generator…
mattip Apr 13, 2019
edfd313
ENH: Finish hypergeometric 0
bashtage Apr 13, 2019
b9b9d70
MAINT: remove legacy, refactor legacy -> mtrand in docs
mattip Apr 14, 2019
2deddc8
MAINT: Remove Cython conditionals
bashtage Apr 14, 2019
d531f92
BUG: Protect gamma generation from 0 input
bashtage Feb 18, 2019
6e386c0
DOC/ENH: Update docstring and enhance logistic
bashtage Feb 19, 2019
8621229
DOC: tighten up documentation, add a table of comparison
mattip Apr 14, 2019
4f06779
ENH: Add fast path for randint broadcasting
bashtage Apr 15, 2019
ca9c542
BUG: Cast high to Python int to avoid overflow
bashtage Apr 15, 2019
dd77ce3
ENH: Add closed generator to randint
bashtage Apr 16, 2019
17e0070
MAINT: Implement API changes for randomgen-derived code
mattip May 13, 2019
b42a5ca
BUG: Ensure integer-type stream on 32bit
bashtage May 18, 2019
720a0a9
BLD: Use numpy detection of SSE
bashtage May 19, 2019
e058ae4
MAINT: remove unused file
mattip May 20, 2019
3d19ae9
MAINT: remove threefry32, xoroshiro128, xorshift1024 BitGenerators
mattip May 20, 2019
060c669
merge master into branch
mattip May 22, 2019
4e6a812
MAINT: remove pre-randomgen _mtrand
mattip May 23, 2019
19b48e2
BUG: test, fix missing return to deprecated function
mattip May 23, 2019
cdb2b0f
MAINT: remove tomaxint, random_sample from generator
mattip May 23, 2019
2c14e47
ENH: Split poisson_lam_max
bashtage May 23, 2019
457c6c5
MAINT: Remove test_against_numpy
bashtage May 23, 2019
9e5ae61
BUG: Change renamed attribute
bashtage May 23, 2019
7c52c28
DOC: Add __all__ and document lock
bashtage May 23, 2019
dabf42b
MAINT: Remove remnants of bit generators
bashtage May 23, 2019
3db5a77
BLD: Improve setup
bashtage May 23, 2019
58c0e72
Revert "MAINT: Implement API changes for randomgen-derived code"
bashtage May 24, 2019
23853d6
STY: Clean up code
bashtage May 24, 2019
9c261e6
PERF: Reorder header for philox (#34)
bashtage May 27, 2019
70d6293
MAINT: fix for dtype specification
mattip May 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Add advance and jump to PCG64
Add advance and jump
Clean other PRNGs
  • Loading branch information
bashtage committed May 20, 2019
commit 6b81fa0a1ebdd769dcd3ce82ef98dcbb0fa17767
8 changes: 4 additions & 4 deletions _randomgen/TODO.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# TODO
2. Add dSFMT
5. Augment state to have binomial structure
6. Port over 0 parameter distributions
* standard exponential ziggurat float
* standard normal ziggurat
* standard normal ziggurat float
7. Remove SplitMix64 as an external generator
8. Restore ability to use `out` in core distributions
10. Seed/Inc for PCG64
11. Advance/Jump for PCG64
12. Key/Counter for ThreeFry
13. Simplify state

## Done
1. Add PCG64
3. Add xorshift2014
4. Augment state to include has_gauss and gauss
5. Augment state to have binomial structure
6. Port over 0 parameter distributions
* standard exponential ziggurat
* standard exponential float
* standard normal
* standard normal float
* standard gamma - Not implement: This is a 1 param
* standard gamma float - Not implement: This is a 1 param

9. Add correct carry for ThreeFry to allow full set of counters. Important when implemeting jump
10. Seed/Inc for PCG64
11. Advance/Jump for PCG64
0. NOT IMPLEMENTABLE due to limits on inheritance in Cython: Use inheritance to simplify CorePRNG structure. The natural base is
xoroshiro128.
22 changes: 22 additions & 0 deletions _randomgen/core_prng/common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ cdef extern from "src/distributions/distributions.h":

ctypedef float (*random_float_0)(void *st) nogil

cdef struct s_binomial_t:
int has_binomial;
double psave;
long nsave;
double r;
double q;
double fm;
long m;
double p1;
double xm;
double xl;
double xr;
double c;
double laml;
double lamr;
double p2;
double p3;
double p4;

ctypedef s_binomial_t binomial_t

cdef struct prng:
void *state
uint64_t (*next_uint64)(void *st)
Expand All @@ -14,6 +35,7 @@ cdef extern from "src/distributions/distributions.h":
double gauss
int has_gauss_f
float gauss_f
binomial_t *binomial

ctypedef prng prng_t

Expand Down
1 change: 1 addition & 0 deletions _randomgen/core_prng/generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import numpy as np
cimport numpy as np
from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
from common cimport *
from libc.stdlib cimport malloc, free

cimport numpy as np
import numpy as np
Expand Down
16 changes: 14 additions & 2 deletions _randomgen/core_prng/mt19937.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cdef class MT19937:
def __init__(self, seed=None):
self.rng_state = <mt19937_state *>malloc(sizeof(mt19937_state))
self._prng = <prng_t *>malloc(sizeof(prng_t))
self._prng.binomial = <binomial_t *>malloc(sizeof(binomial_t))
self.seed(seed)

self._prng.state = <void *>self.rng_state
Expand All @@ -68,6 +69,7 @@ cdef class MT19937:

def __dealloc__(self):
free(self.rng_state)
free(self._prng.binomial)
free(self._prng)

# Pickling support:
Expand All @@ -82,10 +84,15 @@ cdef class MT19937:
(self.state['prng'],),
self.state)

def __random_integer(self):
def __random_integer(self, bits=64):
"""
64-bit Random Integers from the PRNG

Parameters
----------
bits : {32, 64}
Number of random bits to return

Returns
-------
rv : int
Expand All @@ -95,7 +102,12 @@ cdef class MT19937:
-----
Testing only
"""
return mt19937_next64(self.rng_state)
if bits == 64:
return self._prng.next_uint64(self._prng.state)
elif bits == 32:
return self._prng.next_uint32(self._prng.state)
else:
raise ValueError('bits must be 32 or 64')

def seed(self, seed=None):
"""
Expand Down
26 changes: 20 additions & 6 deletions _randomgen/core_prng/pcg64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cdef extern from "src/pcg64/pcg64.h":
uint64_t pcg64_next64(pcg64_state *state) nogil
uint64_t pcg64_next32(pcg64_state *state) nogil
void pcg64_jump(pcg64_state *state)
void pcg64_advance(pcg64_state *state, uint64_t *step)


cdef uint64_t pcg64_uint64(void* st):# nogil:
Expand Down Expand Up @@ -62,20 +63,18 @@ cdef class PCG64:
cdef prng_t *_prng
cdef public object _prng_capsule

def __init__(self, seed=None):
def __init__(self, seed=None, inc=1):
self.rng_state = <pcg64_state *>malloc(sizeof(pcg64_state))
self.rng_state.pcg_state = <pcg64_random_t *>malloc(sizeof(pcg64_random_t))
self._prng = <prng_t *>malloc(sizeof(prng_t))
self.seed(seed)
self._prng.binomial = <binomial_t *>malloc(sizeof(binomial_t))
self.seed(seed, inc)

self._prng.state = <void *>self.rng_state
self._prng.next_uint64 = &pcg64_uint64
self._prng.next_uint32 = &pcg64_uint32
self._prng.next_double = &pcg64_double

self.rng_state.pcg_state.inc.high = 0
self.rng_state.pcg_state.inc.low = 1

cdef const char *name = "CorePRNG"
self._prng_capsule = PyCapsule_New(<void *>self._prng, name, NULL)

Expand All @@ -93,6 +92,7 @@ cdef class PCG64:

def __dealloc__(self):
free(self.rng_state)
free(self._prng.binomial)
free(self._prng)

def _reset_state_variables(self):
Expand Down Expand Up @@ -124,7 +124,7 @@ cdef class PCG64:
else:
raise ValueError('bits must be 32 or 64')

def seed(self, seed=None):
def seed(self, seed=None, inc=1):
"""
seed(seed=None, stream=None)

Expand All @@ -138,6 +138,8 @@ cdef class PCG64:
----------
seed : int, optional
Seed for ``RandomState``.
inc : int, optional
Increment to use for PCG stream

Raises
------
Expand All @@ -156,6 +158,8 @@ cdef class PCG64:
state = entropy.seed_by_array(seed, 2)
self.rng_state.pcg_state.state.high = <uint64_t>int(state[0])
self.rng_state.pcg_state.state.low = <uint64_t>int(state[1])
self.rng_state.pcg_state.inc.high = inc // 2**64
self.rng_state.pcg_state.inc.low = inc % 2**64
self._reset_state_variables()

@property
Expand Down Expand Up @@ -186,3 +190,13 @@ cdef class PCG64:
self.rng_state.pcg_state.inc.low = value['state']['inc'] % 2 ** 64
self.rng_state.has_uint32 = value['has_uint32']
self.rng_state.uinteger = value['uinteger']

def advance(self, step):
cdef np.ndarray delta = np.empty(2,dtype=np.uint64)
delta[0] = step // 2**64
delta[1] = step % 2**64
pcg64_advance(self.rng_state, <uint64_t *>delta.data)
return self

def jump(self):
return self.advance(2**64)
16 changes: 14 additions & 2 deletions _randomgen/core_prng/splitmix64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ cdef class SplitMix64:
def __init__(self, seed=None):
self.rng_state = <splitmix64_state *>malloc(sizeof(splitmix64_state))
self._prng = <prng_t *>malloc(sizeof(prng_t))
self._prng.binomial = <binomial_t *>malloc(sizeof(binomial_t))
self.seed(seed)

self._prng.state = <void *>self.rng_state
Expand All @@ -65,6 +66,7 @@ cdef class SplitMix64:

def __dealloc__(self):
free(self.rng_state)
free(self._prng.binomial)
free(self._prng)

# Pickling support:
Expand All @@ -84,10 +86,15 @@ cdef class SplitMix64:
self.rng_state.has_uint32 = 0
self.rng_state.uinteger = 0

def __random_integer(self):
def __random_integer(self, bits=64):
"""
64-bit Random Integers from the PRNG

Parameters
----------
bits : {32, 64}
Number of random bits to return

Returns
-------
rv : int
Expand All @@ -97,7 +104,12 @@ cdef class SplitMix64:
-----
Testing only
"""
return splitmix64_next64(self.rng_state)
if bits == 64:
return self._prng.next_uint64(self._prng.state)
elif bits == 32:
return self._prng.next_uint32(self._prng.state)
else:
raise ValueError('bits must be 32 or 64')

def seed(self, seed=None):
"""
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions _randomgen/core_prng/src/distributions/distributions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ typedef int bool;
typedef double (*random_double_0)(void *st);
typedef float (*random_float_0)(void *st);

typedef struct s_binomial_t
{
int has_binomial; /* !=0: following parameters initialized for binomial */
double psave;
long nsave;
double r;
double q;
double fm;
long m;
double p1;
double xm;
double xl;
double xr;
double c;
double laml;
double lamr;
double p2;
double p3;
double p4;
} binomial_t;

typedef struct prng {
void *state;
uint64_t (*next_uint64)(void *st);
Expand All @@ -29,6 +50,7 @@ typedef struct prng {
double gauss;
int has_gauss_f;
float gauss_f;
binomial_t *binomial;
} prng_t;

float random_float(prng_t *prng_state);
Expand Down
15 changes: 14 additions & 1 deletion _randomgen/core_prng/src/pcg64/pcg64.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ pcg128_t pcg_advance_lcg_128(pcg128_t state, pcg128_t delta, pcg128_t cur_mult,
#endif

extern inline uint64_t pcg64_next64(pcg64_state *state);
extern inline uint32_t pcg64_next32(pcg64_state *state);
extern inline uint32_t pcg64_next32(pcg64_state *state);

#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
extern void pcg64_advance(pcg64_state *state, pcg128_t step) {
pcg64_advance_r(state->pcg_state, step);
}
#else
extern void pcg64_advance(pcg64_state *state, uint64_t *step) {
pcg128_t delta;
delta.high = step[0];
delta.low = step[1];
pcg64_advance_r(state->pcg_state, delta);
}
#endif
8 changes: 7 additions & 1 deletion _randomgen/core_prng/src/pcg64/pcg64.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,10 @@ static inline uint32_t pcg64_next32(pcg64_state *state) {
state->has_uint32 = 1;
state->uinteger = (uint32_t)(next & 0xffffffff);
return (uint32_t)(next >> 32);
}
}

#if __SIZEOF_INT128__ && !defined(PCG_FORCE_EMULATED_128BIT_MATH)
void pcg64_advance(pcg64_state *state, pcg128_t step);
#else
void pcg64_advance(pcg64_state *state, uint64_t *step);
#endif
7 changes: 5 additions & 2 deletions _randomgen/core_prng/threefry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ cdef class ThreeFry:
self.rng_state.ctr = <threefry4x64_ctr_t *>malloc(sizeof(threefry4x64_ctr_t))
self.rng_state.key = <threefry4x64_key_t *>malloc(sizeof(threefry4x64_key_t))
self._prng = <prng_t *>malloc(sizeof(prng_t))
self._prng.binomial = <binomial_t *>malloc(sizeof(binomial_t))
self.seed(seed)

self._prng.state = <void *>self.rng_state
Expand All @@ -94,6 +95,7 @@ cdef class ThreeFry:
free(self.rng_state.ctr)
free(self.rng_state.key)
free(self.rng_state)
free(self._prng.binomial)
free(self._prng)

def _reset_state_variables(self):
Expand Down Expand Up @@ -122,9 +124,9 @@ cdef class ThreeFry:
Testing only
"""
if bits == 64:
return threefry_next64(self.rng_state)
return self._prng.next_uint64(self._prng.state)
elif bits == 32:
return threefry_next32(self.rng_state)
return self._prng.next_uint32(self._prng.state)
else:
raise ValueError('bits must be 32 or 64')

Expand Down Expand Up @@ -200,6 +202,7 @@ cdef class ThreeFry:
def jump(self):
"""Jump the state as-if 2**128 draws have been made"""
threefry_jump(self.rng_state)
return self

def advance(self, step):
"""Advance the state as-if a specific number of draws have been made"""
Expand Down
3 changes: 3 additions & 0 deletions _randomgen/core_prng/xoroshiro128.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cdef class Xoroshiro128:
def __init__(self, seed=None):
self.rng_state = <xoroshiro128_state *>malloc(sizeof(xoroshiro128_state))
self._prng = <prng_t *>malloc(sizeof(prng_t))
self._prng.binomial = <binomial_t *>malloc(sizeof(binomial_t))
self.seed(seed)

self._prng.state = <void *>self.rng_state
Expand All @@ -79,6 +80,7 @@ cdef class Xoroshiro128:

def __dealloc__(self):
free(self.rng_state)
free(self._prng.binomial)
free(self._prng)

def _reset_state_variables(self):
Expand Down Expand Up @@ -146,6 +148,7 @@ cdef class Xoroshiro128:

def jump(self):
xoroshiro128_jump(self.rng_state)
return self

@property
def state(self):
Expand Down
Loading
0