Skip to content

Commit e83c366

Browse files
committed
Merge pull request #50 from bashtage/xoroshiro
ENH: Add xoroshiro128+ prng
2 parents e97a060 + a665658 commit e83c366

25 files changed

+2687
-49
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# License
22

3-
Copyright (c) 2015 Kevin Sheppard
3+
Copyright (c) 2016 Kevin Sheppard
44
All rights reserved.
55

66
Developed by: Kevin Sheppard

README.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The RNGs include:
4040
the NumPy rng
4141
* [dSFMT](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/) a SSE2-aware
4242
version of the MT19937 generator that is especially fast at generating doubles
43-
* [xorshift128+](http://xorshift.di.unimi.it/) and
43+
* [xorshift128+](http://xorshift.di.unimi.it/), [xoroshiro128+](http://xoroshiro.di.unimi.it/)
4444
[xorshift1024*](http://xorshift.di.unimi.it/)
4545
* [PCG32](http://www.pcg-random.org/) and [PCG64](http:w//www.pcg-random.org/)
4646
* [MRG32K3A](http://simul.iro.umontreal.ca/rng)
@@ -97,8 +97,8 @@ This module is essentially complete. There are a few rough edges that need to b
9797
## Requirements
9898
Building requires:
9999

100-
* Numpy (1.9, 1.10)
101-
* Cython (0.22, 0.23)
100+
* Numpy (1.9, 1.10, 1.11)
101+
* Cython (0.22, 0.23, 0.24)
102102
* Python (2.6, 2.7, 3.3, 3.4, 3.5)
103103

104104
**Note:** it might work with other versions but only tested with these
@@ -169,23 +169,25 @@ Performance is promising, and even the mt19937 seems to be faster than NumPy's m
169169
```
170170
Speed-up relative to NumPy (Box-Muller)
171171
************************************************************
172-
randomstate.prng-dsfmt-standard_normal 70.5%
173-
randomstate.prng-mlfg_1279_861-standard_normal 26.9%
174-
randomstate.prng-mrg32k3a-standard_normal -18.7%
175-
randomstate.prng-mt19937-standard_normal 13.5%
176-
randomstate.prng-pcg32-standard_normal 26.1%
177-
randomstate.prng-pcg64-standard_normal 26.2%
178-
randomstate.prng-xorshift1024-standard_normal 27.2%
179-
randomstate.prng-xorshift128-standard_normal 30.0%
172+
randomstate.prng-dsfmt-standard_normal 30.2%
173+
randomstate.prng-mlfg_1279_861-standard_normal 24.7%
174+
randomstate.prng-mrg32k3a-standard_normal -17.8%
175+
randomstate.prng-mt19937-standard_normal 11.2%
176+
randomstate.prng-pcg32-standard_normal 22.0%
177+
randomstate.prng-pcg64-standard_normal 21.8%
178+
randomstate.prng-xoroshiro128plus-standard_normal 26.5%
179+
randomstate.prng-xorshift1024-standard_normal 20.2%
180+
randomstate.prng-xorshift128-standard_normal 23.5%
180181
181182
Speed-up relative to NumPy (Ziggurat)
182183
************************************************************
183-
randomstate.prng-dsfmt-standard_normal 316.1%
184-
randomstate.prng-mlfg_1279_861-standard_normal 247.0%
185-
randomstate.prng-mrg32k3a-standard_normal 51.2%
186-
randomstate.prng-mt19937-standard_normal 175.9%
187-
randomstate.prng-pcg32-standard_normal 255.9%
188-
randomstate.prng-pcg64-standard_normal 329.1%
189-
randomstate.prng-xorshift1024-standard_normal 362.0%
190-
randomstate.prng-xorshift128-standard_normal 513.7%
191-
```
184+
randomstate.prng-dsfmt-standard_normal 494.2%
185+
randomstate.prng-mlfg_1279_861-standard_normal 464.2%
186+
randomstate.prng-mrg32k3a-standard_normal 103.8%
187+
randomstate.prng-mt19937-standard_normal 362.6%
188+
randomstate.prng-pcg32-standard_normal 539.6%
189+
randomstate.prng-pcg64-standard_normal 407.7%
190+
randomstate.prng-xoroshiro128plus-standard_normal 722.8%
191+
randomstate.prng-xorshift1024-standard_normal 506.1%
192+
randomstate.prng-xorshift128-standard_normal 686.3%
193+
```

README.rst

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ in addition to the MT19937 that is included in NumPy. The RNGs include:
4141
- `dSFMT <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/>`__ a
4242
SSE2-aware version of the MT19937 generator that is especially fast
4343
at generating doubles
44-
- `xorshift128+ <http://xorshift.di.unimi.it/>`__ and
44+
- `xorshift128+ <http://xorshift.di.unimi.it/>`__,
45+
`xoroshiro128+ <http://xoroshiro.di.unimi.it/>`__
4546
`xorshift1024\* <http://xorshift.di.unimi.it/>`__
4647
- `PCG32 <http://www.pcg-random.org/>`__ and
4748
`PCG64 <http:w//www.pcg-random.org/>`__
@@ -117,8 +118,8 @@ Requirements
117118

118119
Building requires:
119120

120-
- Numpy (1.9, 1.10)
121-
- Cython (0.22, 0.23)
121+
- Numpy (1.9, 1.10, 1.11)
122+
- Cython (0.22, 0.23, 0.24)
122123
- Python (2.6, 2.7, 3.3, 3.4, 3.5)
123124

124125
**Note:** it might work with other versions but only tested with these
@@ -203,25 +204,27 @@ NumPy's mt19937.
203204

204205
Speed-up relative to NumPy (Box-Muller)
205206
************************************************************
206-
randomstate.prng-dsfmt-standard_normal 70.5%
207-
randomstate.prng-mlfg_1279_861-standard_normal 26.9%
208-
randomstate.prng-mrg32k3a-standard_normal -18.7%
209-
randomstate.prng-mt19937-standard_normal 13.5%
210-
randomstate.prng-pcg32-standard_normal 26.1%
211-
randomstate.prng-pcg64-standard_normal 26.2%
212-
randomstate.prng-xorshift1024-standard_normal 27.2%
213-
randomstate.prng-xorshift128-standard_normal 30.0%
207+
randomstate.prng-dsfmt-standard_normal 30.2%
208+
randomstate.prng-mlfg_1279_861-standard_normal 24.7%
209+
randomstate.prng-mrg32k3a-standard_normal -17.8%
210+
randomstate.prng-mt19937-standard_normal 11.2%
211+
randomstate.prng-pcg32-standard_normal 22.0%
212+
randomstate.prng-pcg64-standard_normal 21.8%
213+
randomstate.prng-xoroshiro128plus-standard_normal 26.5%
214+
randomstate.prng-xorshift1024-standard_normal 20.2%
215+
randomstate.prng-xorshift128-standard_normal 23.5%
214216

215217
Speed-up relative to NumPy (Ziggurat)
216218
************************************************************
217-
randomstate.prng-dsfmt-standard_normal 316.1%
218-
randomstate.prng-mlfg_1279_861-standard_normal 247.0%
219-
randomstate.prng-mrg32k3a-standard_normal 51.2%
220-
randomstate.prng-mt19937-standard_normal 175.9%
221-
randomstate.prng-pcg32-standard_normal 255.9%
222-
randomstate.prng-pcg64-standard_normal 329.1%
223-
randomstate.prng-xorshift1024-standard_normal 362.0%
224-
randomstate.prng-xorshift128-standard_normal 513.7%
219+
randomstate.prng-dsfmt-standard_normal 494.2%
220+
randomstate.prng-mlfg_1279_861-standard_normal 464.2%
221+
randomstate.prng-mrg32k3a-standard_normal 103.8%
222+
randomstate.prng-mt19937-standard_normal 362.6%
223+
randomstate.prng-pcg32-standard_normal 539.6%
224+
randomstate.prng-pcg64-standard_normal 407.7%
225+
randomstate.prng-xoroshiro128plus-standard_normal 722.8%
226+
randomstate.prng-xorshift1024-standard_normal 506.1%
227+
randomstate.prng-xorshift128-standard_normal 686.3%
225228

226229
.. |Travis Build Status| image:: https://travis-ci.org/bashtage/ng-numpy-randomstate.svg?branch=master
227230
:target: https://travis-ci.org/bashtage/ng-numpy-randomstate

doc/source/change-log.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.. _change-log:
2+
3+
Change Log
4+
==========
5+
6+
Version 1.11.1
7+
--------------
8+
9+
* Added xoroshiro128+ PRNG. This is an improved version of the xorshirt128+
10+
PRNG and should be used instead. In the long run, xorshift128+ will likely
11+
be removed.
12+
* Fixed DeprecationWarning when initializing a PRNG using a single element
13+
array.
14+
15+
Version 1.11
16+
------------
17+
18+
* Update to recent changes in NumPy's RandomState
19+
* Expose system entropy through :meth:`randomstate.entropy.random_entropy`
20+
* Add vector initialization for all PRNGs
21+
22+
Version 1.10.1
23+
--------------
24+
25+
* Added support for jumping the MRG32K3A generator
26+
* Added support for jumping the dSFMT generator
27+
* Update to recent changes in NumPy's RandomState
28+
29+
Version 1.10
30+
------------
31+
32+
* This is the initial release with compatibility with NumPy 1.10

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
# The short X.Y version.
6666
version = '1.11'
6767
# The full version, including alpha/beta/rc tags.
68-
release = '1.11.0'
68+
release = '1.11.1'
6969

7070
# The language for content autogenerated by Sphinx. Refer to documentation
7171
# for a list of supported languages.

doc/source/index.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ What's New or Different
1212
``/dev/urandom`` on Unix).
1313
* The normal generator supports a 256-step ziggurat method which is 2-6 times
1414
faster than NumPy's ``standard_normal``. This generator can be accessed using
15+
* For changes since the previous release, see the :ref:`change-log`
1516

1617
.. code-block:: python
1718
@@ -37,11 +38,17 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
3738
* dSFMT - A SSE2 enables version of the MT19937 generator. Theoretically the
3839
same, but with a different state and so it is not possible to produce a
3940
sequence identical to MT19937. See the `dSFMT authors' page`_.
41+
* XoroShiro128+ - Improved version of XorShift128+ with improved performance
42+
and better statistical quality. Like the XorShift generators, can be jumped
43+
to produce multiple streams in parallel applications. See
44+
:meth:`randomstate.prng.xoroshiro128plus.jump` for details. More information
45+
about this PRNG is available at the `xorshift and xoroshiro authors' page`_.
4046
* XorShit128+ and XorShift1024* - Vast fast generators based on the XSadd
4147
generator. These generators can be rapidly 'jumped' and so can be used in
4248
parallel applications. See the documentation for
4349
:meth:`randomstate.prng.xorshift1024.jump` for details. More information
44-
about these PRNGs is available at the `xorshift authors' page`_.
50+
about these PRNGs is available at the
51+
`xorshift and xoroshiro authors' page`_.
4552
* PCG-32 and PCG-64 - Fast generators that support many parallel streams and
4653
can be advanced by an arbitrary amount. See the documentation for
4754
:meth:`randomstate.prng.pcg64.advance`. PCG-32 only as a period of
@@ -57,7 +64,7 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
5764

5865
.. _`NumPy's documentation`: http://docs.scipy.org/doc/numpy/reference/routines.random.html
5966
.. _`dSFMT authors' page`: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/
60-
.. _`xorshift authors' page`: http://xorshift.di.unimi.it/
67+
.. _`xorshift and xoroshiro authors' page`: http://xoroshiro.di.unimi.it/
6168
.. _`PCG author's page`: http://www.pcg-random.org/
6269
.. _`wiki page on Fibonacci generators`: https://en.wikipedia.org/wiki/Lagged_Fibonacci_generator
6370
.. _`MRG32K3A author's page`: http://simul.iro.umontreal.ca/
@@ -72,6 +79,7 @@ Individual Pseudo Random Number Generators
7279
MT19937 <mt19937>
7380
dSFMT <dsfmt>
7481
XorShift128+ <xorshift128>
82+
XoroShiro128+ <xoroshiro128plus>
7583
XorShift1024* <xorshift1024>
7684
PCG-32 <pcg32>
7785
PCG-64 <pcg64>
@@ -86,3 +94,4 @@ Indices and tables
8694
* :ref:`genindex`
8795
* :ref:`modindex`
8896
* :ref:`search`
97+

doc/source/xoroshiro128plus.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
XorShift128+ Randomstate
2+
************************
3+
4+
.. currentmodule:: randomstate.prng.xoroshiro128plus
5+
6+
7+
Random generator
8+
================
9+
.. autoclass::
10+
RandomState
11+
12+
.. autosummary::
13+
:toctree: generated/
14+
15+
seed
16+
get_state
17+
set_state
18+
19+
Parallel generation
20+
===================
21+
.. autosummary::
22+
:toctree: generated/
23+
24+
jump
25+
26+
Simple random data
27+
==================
28+
.. autosummary::
29+
:toctree: generated/
30+
31+
rand
32+
randn
33+
randint
34+
random_integers
35+
random_sample
36+
random
37+
ranf
38+
sample
39+
choice
40+
bytes
41+
random_uintegers
42+
random_raw
43+
44+
Permutations
45+
============
46+
.. autosummary::
47+
:toctree: generated/
48+
49+
shuffle
50+
permutation
51+
52+
Distributions
53+
=============
54+
.. autosummary::
55+
:toctree: generated/
56+
57+
beta
58+
binomial
59+
chisquare
60+
dirichlet
61+
exponential
62+
f
63+
gamma
64+
geometric
65+
gumbel
66+
hypergeometric
67+
laplace
68+
logistic
69+
lognormal
70+
logseries
71+
multinomial
72+
multivariate_normal
73+
negative_binomial
74+
noncentral_chisquare
75+
noncentral_f
76+
normal
77+
pareto
78+
poisson
79+
power
80+
rayleigh
81+
standard_cauchy
82+
standard_exponential
83+
standard_gamma
84+
standard_normal
85+
standard_t
86+
triangular
87+
uniform
88+
vonmises
89+
wald
90+
weibull
91+
zipf

randomstate/distributions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ typedef int bool;
3232
#include "interface/xorshift128/xorshift128-shim.h"
3333
#elif defined(RS_XORSHIFT1024)
3434
#include "interface/xorshift1024/xorshift1024-shim.h"
35+
#elif defined(RS_XOROSHIRO128PLUS)
36+
#include "interface/xoroshiro128plus/xoroshiro128plus-shim.h"
3537
#elif defined(RS_MRG32K3A)
3638
#include "interface/mrg32k3a/mrg32k3a-shim.h"
3739
#elif defined(RS_MLFG_1279_861)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "xoroshiro128plus-shim.h"
2+
3+
extern inline uint32_t random_uint32(aug_state* state);
4+
5+
extern inline uint64_t random_uint64(aug_state* state);
6+
7+
extern inline double random_double(aug_state* state);
8+
9+
extern inline uint64_t random_raw_values(aug_state* state);
10+
11+
void set_seed(aug_state* state, uint64_t seed)
12+
{
13+
xoroshiro128plus_seed(state->rng, seed);
14+
}
15+
16+
void set_seed_by_array(aug_state* state, uint64_t *vals, int count)
17+
{
18+
xoroshiro128plus_seed_by_array(state->rng, vals, count);
19+
}
20+
21+
22+
void entropy_init(aug_state* state)
23+
{
24+
uint64_t seed[1];
25+
entropy_fill((void*) seed, sizeof(seed));
26+
xoroshiro128plus_seed(state->rng, seed[0]);
27+
}
28+
29+
void jump_state(aug_state* state)
30+
{
31+
xoroshiro128plus_jump(state->rng);
32+
}
33+
34+
void init_state(aug_state* state, uint64_t* state_vals)
35+
{
36+
xoroshiro128plus_init_state(state->rng, *(state_vals), *(state_vals + 1));
37+
}
38+

0 commit comments

Comments
 (0)