Skip to content

Commit

Permalink
Merge pull request #50 from bashtage/xoroshiro
Browse files Browse the repository at this point in the history
ENH: Add xoroshiro128+ prng
  • Loading branch information
bashtage committed May 19, 2016
2 parents e97a060 + a665658 commit e83c366
Show file tree
Hide file tree
Showing 25 changed files with 2,687 additions and 49 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# License

Copyright (c) 2015 Kevin Sheppard
Copyright (c) 2016 Kevin Sheppard
All rights reserved.

Developed by: Kevin Sheppard
Expand Down
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The RNGs include:
the NumPy rng
* [dSFMT](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/) a SSE2-aware
version of the MT19937 generator that is especially fast at generating doubles
* [xorshift128+](http://xorshift.di.unimi.it/) and
* [xorshift128+](http://xorshift.di.unimi.it/), [xoroshiro128+](http://xoroshiro.di.unimi.it/)
[xorshift1024*](http://xorshift.di.unimi.it/)
* [PCG32](http://www.pcg-random.org/) and [PCG64](http:w//www.pcg-random.org/)
* [MRG32K3A](http://simul.iro.umontreal.ca/rng)
Expand Down Expand Up @@ -97,8 +97,8 @@ This module is essentially complete. There are a few rough edges that need to b
## Requirements
Building requires:

* Numpy (1.9, 1.10)
* Cython (0.22, 0.23)
* Numpy (1.9, 1.10, 1.11)
* Cython (0.22, 0.23, 0.24)
* Python (2.6, 2.7, 3.3, 3.4, 3.5)

**Note:** it might work with other versions but only tested with these
Expand Down Expand Up @@ -169,23 +169,25 @@ Performance is promising, and even the mt19937 seems to be faster than NumPy's m
```
Speed-up relative to NumPy (Box-Muller)
************************************************************
randomstate.prng-dsfmt-standard_normal 70.5%
randomstate.prng-mlfg_1279_861-standard_normal 26.9%
randomstate.prng-mrg32k3a-standard_normal -18.7%
randomstate.prng-mt19937-standard_normal 13.5%
randomstate.prng-pcg32-standard_normal 26.1%
randomstate.prng-pcg64-standard_normal 26.2%
randomstate.prng-xorshift1024-standard_normal 27.2%
randomstate.prng-xorshift128-standard_normal 30.0%
randomstate.prng-dsfmt-standard_normal 30.2%
randomstate.prng-mlfg_1279_861-standard_normal 24.7%
randomstate.prng-mrg32k3a-standard_normal -17.8%
randomstate.prng-mt19937-standard_normal 11.2%
randomstate.prng-pcg32-standard_normal 22.0%
randomstate.prng-pcg64-standard_normal 21.8%
randomstate.prng-xoroshiro128plus-standard_normal 26.5%
randomstate.prng-xorshift1024-standard_normal 20.2%
randomstate.prng-xorshift128-standard_normal 23.5%
Speed-up relative to NumPy (Ziggurat)
************************************************************
randomstate.prng-dsfmt-standard_normal 316.1%
randomstate.prng-mlfg_1279_861-standard_normal 247.0%
randomstate.prng-mrg32k3a-standard_normal 51.2%
randomstate.prng-mt19937-standard_normal 175.9%
randomstate.prng-pcg32-standard_normal 255.9%
randomstate.prng-pcg64-standard_normal 329.1%
randomstate.prng-xorshift1024-standard_normal 362.0%
randomstate.prng-xorshift128-standard_normal 513.7%
```
randomstate.prng-dsfmt-standard_normal 494.2%
randomstate.prng-mlfg_1279_861-standard_normal 464.2%
randomstate.prng-mrg32k3a-standard_normal 103.8%
randomstate.prng-mt19937-standard_normal 362.6%
randomstate.prng-pcg32-standard_normal 539.6%
randomstate.prng-pcg64-standard_normal 407.7%
randomstate.prng-xoroshiro128plus-standard_normal 722.8%
randomstate.prng-xorshift1024-standard_normal 506.1%
randomstate.prng-xorshift128-standard_normal 686.3%
```
41 changes: 22 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ in addition to the MT19937 that is included in NumPy. The RNGs include:
- `dSFMT <http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/>`__ a
SSE2-aware version of the MT19937 generator that is especially fast
at generating doubles
- `xorshift128+ <http://xorshift.di.unimi.it/>`__ and
- `xorshift128+ <http://xorshift.di.unimi.it/>`__,
`xoroshiro128+ <http://xoroshiro.di.unimi.it/>`__
`xorshift1024\* <http://xorshift.di.unimi.it/>`__
- `PCG32 <http://www.pcg-random.org/>`__ and
`PCG64 <http:w//www.pcg-random.org/>`__
Expand Down Expand Up @@ -117,8 +118,8 @@ Requirements

Building requires:

- Numpy (1.9, 1.10)
- Cython (0.22, 0.23)
- Numpy (1.9, 1.10, 1.11)
- Cython (0.22, 0.23, 0.24)
- Python (2.6, 2.7, 3.3, 3.4, 3.5)

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

Speed-up relative to NumPy (Box-Muller)
************************************************************
randomstate.prng-dsfmt-standard_normal 70.5%
randomstate.prng-mlfg_1279_861-standard_normal 26.9%
randomstate.prng-mrg32k3a-standard_normal -18.7%
randomstate.prng-mt19937-standard_normal 13.5%
randomstate.prng-pcg32-standard_normal 26.1%
randomstate.prng-pcg64-standard_normal 26.2%
randomstate.prng-xorshift1024-standard_normal 27.2%
randomstate.prng-xorshift128-standard_normal 30.0%
randomstate.prng-dsfmt-standard_normal 30.2%
randomstate.prng-mlfg_1279_861-standard_normal 24.7%
randomstate.prng-mrg32k3a-standard_normal -17.8%
randomstate.prng-mt19937-standard_normal 11.2%
randomstate.prng-pcg32-standard_normal 22.0%
randomstate.prng-pcg64-standard_normal 21.8%
randomstate.prng-xoroshiro128plus-standard_normal 26.5%
randomstate.prng-xorshift1024-standard_normal 20.2%
randomstate.prng-xorshift128-standard_normal 23.5%

Speed-up relative to NumPy (Ziggurat)
************************************************************
randomstate.prng-dsfmt-standard_normal 316.1%
randomstate.prng-mlfg_1279_861-standard_normal 247.0%
randomstate.prng-mrg32k3a-standard_normal 51.2%
randomstate.prng-mt19937-standard_normal 175.9%
randomstate.prng-pcg32-standard_normal 255.9%
randomstate.prng-pcg64-standard_normal 329.1%
randomstate.prng-xorshift1024-standard_normal 362.0%
randomstate.prng-xorshift128-standard_normal 513.7%
randomstate.prng-dsfmt-standard_normal 494.2%
randomstate.prng-mlfg_1279_861-standard_normal 464.2%
randomstate.prng-mrg32k3a-standard_normal 103.8%
randomstate.prng-mt19937-standard_normal 362.6%
randomstate.prng-pcg32-standard_normal 539.6%
randomstate.prng-pcg64-standard_normal 407.7%
randomstate.prng-xoroshiro128plus-standard_normal 722.8%
randomstate.prng-xorshift1024-standard_normal 506.1%
randomstate.prng-xorshift128-standard_normal 686.3%

.. |Travis Build Status| image:: https://travis-ci.org/bashtage/ng-numpy-randomstate.svg?branch=master
:target: https://travis-ci.org/bashtage/ng-numpy-randomstate
Expand Down
32 changes: 32 additions & 0 deletions doc/source/change-log.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.. _change-log:

Change Log
==========

Version 1.11.1
--------------

* Added xoroshiro128+ PRNG. This is an improved version of the xorshirt128+
PRNG and should be used instead. In the long run, xorshift128+ will likely
be removed.
* Fixed DeprecationWarning when initializing a PRNG using a single element
array.

Version 1.11
------------

* Update to recent changes in NumPy's RandomState
* Expose system entropy through :meth:`randomstate.entropy.random_entropy`
* Add vector initialization for all PRNGs

Version 1.10.1
--------------

* Added support for jumping the MRG32K3A generator
* Added support for jumping the dSFMT generator
* Update to recent changes in NumPy's RandomState

Version 1.10
------------

* This is the initial release with compatibility with NumPy 1.10
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
# The short X.Y version.
version = '1.11'
# The full version, including alpha/beta/rc tags.
release = '1.11.0'
release = '1.11.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
13 changes: 11 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ What's New or Different
``/dev/urandom`` on Unix).
* The normal generator supports a 256-step ziggurat method which is 2-6 times
faster than NumPy's ``standard_normal``. This generator can be accessed using
* For changes since the previous release, see the :ref:`change-log`

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

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

91 changes: 91 additions & 0 deletions doc/source/xoroshiro128plus.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
XorShift128+ Randomstate
************************

.. currentmodule:: randomstate.prng.xoroshiro128plus


Random generator
================
.. autoclass::
RandomState

.. autosummary::
:toctree: generated/

seed
get_state
set_state

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

jump

Simple random data
==================
.. autosummary::
:toctree: generated/

rand
randn
randint
random_integers
random_sample
random
ranf
sample
choice
bytes
random_uintegers
random_raw

Permutations
============
.. autosummary::
:toctree: generated/

shuffle
permutation

Distributions
=============
.. autosummary::
:toctree: generated/

beta
binomial
chisquare
dirichlet
exponential
f
gamma
geometric
gumbel
hypergeometric
laplace
logistic
lognormal
logseries
multinomial
multivariate_normal
negative_binomial
noncentral_chisquare
noncentral_f
normal
pareto
poisson
power
rayleigh
standard_cauchy
standard_exponential
standard_gamma
standard_normal
standard_t
triangular
uniform
vonmises
wald
weibull
zipf
2 changes: 2 additions & 0 deletions randomstate/distributions.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef int bool;
#include "interface/xorshift128/xorshift128-shim.h"
#elif defined(RS_XORSHIFT1024)
#include "interface/xorshift1024/xorshift1024-shim.h"
#elif defined(RS_XOROSHIRO128PLUS)
#include "interface/xoroshiro128plus/xoroshiro128plus-shim.h"
#elif defined(RS_MRG32K3A)
#include "interface/mrg32k3a/mrg32k3a-shim.h"
#elif defined(RS_MLFG_1279_861)
Expand Down
38 changes: 38 additions & 0 deletions randomstate/interface/xoroshiro128plus/xoroshiro128plus-shim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "xoroshiro128plus-shim.h"

extern inline uint32_t random_uint32(aug_state* state);

extern inline uint64_t random_uint64(aug_state* state);

extern inline double random_double(aug_state* state);

extern inline uint64_t random_raw_values(aug_state* state);

void set_seed(aug_state* state, uint64_t seed)
{
xoroshiro128plus_seed(state->rng, seed);
}

void set_seed_by_array(aug_state* state, uint64_t *vals, int count)
{
xoroshiro128plus_seed_by_array(state->rng, vals, count);
}


void entropy_init(aug_state* state)
{
uint64_t seed[1];
entropy_fill((void*) seed, sizeof(seed));
xoroshiro128plus_seed(state->rng, seed[0]);
}

void jump_state(aug_state* state)
{
xoroshiro128plus_jump(state->rng);
}

void init_state(aug_state* state, uint64_t* state_vals)
{
xoroshiro128plus_init_state(state->rng, *(state_vals), *(state_vals + 1));
}

0 comments on commit e83c366

Please sign in to comment.