Skip to content

Commit

Permalink
Merge a1d040e into 9a5aa71
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed May 30, 2019
2 parents 9a5aa71 + a1d040e commit 01be27d
Show file tree
Hide file tree
Showing 30 changed files with 4,881 additions and 20 deletions.
2 changes: 1 addition & 1 deletion benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

PRNGS = ['DSFMT', 'PCG64', 'PCG32', 'MT19937', 'MT64', 'Xoroshiro128',
'Xorshift1024', 'Xoshiro256', 'Xoshiro512', 'Philox', 'ThreeFry',
'ThreeFry32', 'numpy']
'ThreeFry32', 'numpy', 'SFMT']


def timer(code, setup):
Expand Down
6 changes: 4 additions & 2 deletions doc/source/bit_generators/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ These RNGs will be included in future releases.

DSFMT <dsfmt>
MT19937 <mt19937>
MT64 <mt64>
PCG64 <pcg64>
Philox <philox>
SFMT <sfmt>
ThreeFry <threefry>
XoroShiro128+ <xoroshiro128>
Xorshift1024*φ <xorshift1024>
Xoshiro256** <xoshiro256>
Xoshiro512** <xoshiro512>

Expand All @@ -42,5 +42,7 @@ permanent.
.. toctree::
:maxdepth: 1

XoroShiro128+ <xoroshiro128>
Xorshift1024*φ <xorshift1024>
PCG32 <pcg32>
ThreeFry32 <threefry32>
33 changes: 33 additions & 0 deletions doc/source/bit_generators/mt64.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
64-bit Mersenne Twister
-----------------------

.. module:: randomgen.mt64

.. currentmodule:: randomgen.mt64


.. autoclass:: MT64

Seeding and State
=================

.. autosummary::
:toctree: generated/

~MT64.seed
~MT64.state

Extending
=========
.. autosummary::
:toctree: generated/

~MT64.cffi
~MT64.ctypes

Testing
=======
.. autosummary::
:toctree: generated/

~MT64.random_raw
41 changes: 41 additions & 0 deletions doc/source/bit_generators/sfmt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
SIMD-oriented Fast Mersenne Twister (SFMT)
------------------------------------------

.. module:: randomgen.sfmt

.. currentmodule:: randomgen.sfmt


.. autoclass:: SFMT

Seeding and State
=================

.. autosummary::
:toctree: generated/

~SFMT.seed
~SFMT.state

Parallel generation
===================
.. autosummary::
:toctree: generated/

~SFMT.jumped
~SFMT.jump

Extending
=========
.. autosummary::
:toctree: generated/

~SFMT.cffi
~SFMT.ctypes

Testing
=======
.. autosummary::
:toctree: generated/

~SFMT.random_raw
5 changes: 3 additions & 2 deletions doc/source/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import pandas as pd

from randomgen import MT19937, DSFMT, ThreeFry, PCG64, Philox, Xoshiro256, \
Xoshiro512, MT64
Xoshiro512, MT64, SFMT

NUMBER = 100
REPEAT = 10
SIZE = 25000
PRNGS = [DSFMT, MT19937, MT64, Philox, PCG64, ThreeFry, Xoshiro256, Xoshiro512]
PRNGS = [DSFMT, MT19937, MT64, Philox, PCG64, ThreeFry, SFMT,
Xoshiro256, Xoshiro512]

funcs = OrderedDict()
funcs['32-bit Unsigned Int'] = f'integers(2**32, dtype="uint32", size={SIZE})'
Expand Down
3 changes: 2 additions & 1 deletion randomgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from randomgen.xorshift1024 import Xorshift1024
from randomgen.xoshiro256 import Xoshiro256
from randomgen.xoshiro512 import Xoshiro512
from randomgen.sfmt import SFMT

from ._version import get_versions

__all__ = ['Generator', 'DSFMT', 'MT19937', 'PCG64', 'PCG32', 'Philox',
'ThreeFry', 'ThreeFry32', 'Xoroshiro128', 'Xorshift1024',
'Xoshiro256', 'Xoshiro512', 'RandomState']
'Xoshiro256', 'Xoshiro512', 'RandomState', 'SFMT']


__version__ = get_versions()['version']
Expand Down
3 changes: 2 additions & 1 deletion randomgen/_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from randomgen.threefry32 import ThreeFry32
from randomgen.xoroshiro128 import Xoroshiro128
from randomgen.xorshift1024 import Xorshift1024

from randomgen.sfmt import SFMT
from randomgen.mt64 import MT64
from randomgen.xoshiro256 import Xoshiro256
from randomgen.xoshiro512 import Xoshiro512
Expand All @@ -26,6 +26,7 @@
'Xoroshiro128': Xoroshiro128,
'Xoshiro256': Xoshiro256,
'Xoshiro512': Xoshiro512,
'SFMT': SFMT,
}


Expand Down
17 changes: 10 additions & 7 deletions randomgen/dsfmt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,17 @@ cdef class DSFMT:
ValueError
If seed values are out of range for the PRNG.
"""
cdef np.ndarray obj
cdef np.ndarray obj, seed_arr
try:
if seed is None:
try:
seed = random_entropy(1)
seed_arr = random_entropy(2 * DSFMT_N64)
except RuntimeError:
seed = random_entropy(1, 'fallback')
dsfmt_init_gen_rand(self.rng_state.state, seed)
seed_arr = random_entropy(2 * DSFMT_N64, 'fallback')
dsfmt_init_by_array(self.rng_state.state,
<uint32_t *>np.PyArray_DATA(seed_arr),
<int>np.PyArray_DIM(seed_arr, 0))

else:
if hasattr(seed, 'squeeze'):
seed = seed.squeeze()
Expand All @@ -269,10 +272,10 @@ cdef class DSFMT:
obj = np.asarray(seed).astype(np.int64, casting='safe').ravel()
if ((obj > int(2**32 - 1)) | (obj < 0)).any():
raise ValueError("Seed must be between 0 and 2**32 - 1")
obj = obj.astype(np.uint32, casting='unsafe', order='C')
seed_arr = obj.astype(np.uint32, casting='unsafe', order='C')
dsfmt_init_by_array(self.rng_state.state,
<uint32_t *>np.PyArray_DATA(obj),
<int>np.PyArray_DIM(obj, 0))
<uint32_t *>np.PyArray_DATA(seed_arr),
<int>np.PyArray_DIM(seed_arr, 0))
# Clear the buffer
self._reset_state_variables()

Expand Down
5 changes: 5 additions & 0 deletions randomgen/entropy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def seed_by_array(object seed, Py_ssize_t n):
n : int
Number of 64-bit unsigned integers required in the seed
Returns
-------
initial_state : array
Array of uint64 containing the initial state
Notes
-----
Uses SplitMix64 to transform the input to a seed
Expand Down

0 comments on commit 01be27d

Please sign in to comment.