8000 Merge pull request #22 from bashtage/sync-upstream · mattip/numpy@63ababa · GitHub
[go: up one dir, main page]

Skip to content

Commit 63ababa

Browse files
authored
Merge pull request #22 from bashtage/sync-upstream
ENH: Allow empty choice
2 parents ce22f0c + 6ade4aa commit 63ababa

File tree

4 files changed

+223
-178
lines changed

4 files changed

+223
-178
lines changed

_randomgen/README.md

Lines changed: 105 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,36 @@ which can fully reproduce the sequence produced by NumPy.
2323

2424
* Replacement for NumPy's RandomState
2525

26-
```python
27-
# import numpy.random as rnd
28-
from randomgen import RandomGenerator, MT19937
29-
rnd = RandomGenerator(MT19937())
30-
x = rnd.standard_normal(100)
31-
y = rnd.random_sample(100)
32-
z = rnd.randn(10,10)
33-
```
26+
```python
27+
from randomgen import RandomGenerator, MT19937
28+
rnd = RandomGenerator(MT19937())
29+
x = rnd.standard_normal(100)
30+
y = rnd.random_sample(100)
31+
z = rnd.randn(10,10)
32+
```
3433

3534
* Default random generator is a fast generator called Xoroshiro128plus
3635
* Support for random number generators that support independent streams
3736
and jumping ahead so that sub-streams can be generated
3837
* Faster random number generation, especially for normal, standard
3938
exponential and standard gamma using the Ziggurat method
4039

41-
```python
42-
from randomgen import RandomGenerator
43-
# Use Xoroshiro128
44-
rnd = RandomGenerator()
45-
w = rnd.standard_normal(10000, method='zig')
46-
x = rnd.standard_exponential(10000, method='zig')
47-
y = rnd.standard_gamma(5.5, 10000, method='zig')
48-
```
40+
```python
41+
from randomgen import RandomGenerator
42+
# Default basic PRNG is Xoroshiro128
43+
rnd = RandomGenerator()
44+
w = rnd.standard_normal(10000, method='zig')
45+
x = rnd.standard_exponential(10000, method='zig')
46+
y = rnd.standard_gamma(5.5, 10000, method='zig')
47+
```
4948

5049
* Support for 32-bit floating randoms for core generators.
5150
Currently supported:
5251

53-
* Uniforms (`random_sample`)
54-
* Exponentials (`standard_exponential`, both Inverse CDF and Ziggurat)
55-
* Normals (`standard_normal`)
56-
* Standard Gammas (via `standard_gamma`)
52+
* Uniforms (`random_sample`)
53+
* Exponentials (`standard_exponential`, both Inverse CDF and Ziggurat)
54+
* Normals (`standard_normal`)
55+
* Standard Gammas (via `standard_gamma`)
5756

5857
**WARNING**: The 32-bit generators are **experimental** and subject
5958
to change.
@@ -64,10 +63,10 @@ y = rnd.standard_gamma(5.5, 10000, method='zig')
6463
* Support for filling existing arrays using `out` keyword argument. Currently
6564
supported in (both 32- and 64-bit outputs)
6665

67-
* Uniforms (`random_sample`)
68-
* Exponentials (`standard_exponential`)
69-
* Normals (`standard_normal`)
70-
* Standard Gammas (via `standard_gamma`)
66+
* Uniforms (`random_sample`)
67+
* Exponentials (`standard_exponential`)
68+
* Normals (`standard_normal`)
69+
* Standard Gammas (via `standard_gamma`)
7170

7271
## Included Pseudo Random Number Generators
7372

@@ -84,9 +83,11 @@ The RNGs include:
8483
[xorshift1024*φ](http://xorshift.di.unimi.it/)
8584
* [PCG64](http://www.pcg-random.org/)
8685
* ThreeFry and Philox from [Random123](https://www.deshawresearch.com/resources_random123.html)
86+
8787
## Differences from `numpy.random.RandomState`
8888

8989
### New Features
90+
9091
* `standard_normal`, `normal`, `randn` and `multivariate_normal` all
9192
use the much faster (100%+) Ziggurat method.
9293
* `standard_gamma` and `gamma` both use the much faster Ziggurat method.
@@ -101,21 +102,20 @@ The RNGs include:
101102
`out` keyword argument
102103
* Standardizes integer-values random values as int64 for all platforms.
103104

104-
105105
### New Functions
106106

107-
* `random_entropy` - Read from the system entropy provider, which is
108-
commonly used in cryptographic applications
109-
* `random_raw` - Direct access to the values produced by the underlying
110-
PRNG. The range of the values returned depends on the specifics of the
111-
PRNG implementation.
107+
* `random_entropy` - Read from the system entropy provider, which is
108+
commonly used in cryptographic applications
109+
* `random_raw` - Direct access to the values produced by the underlying
110+
PRNG. The range of the values returned depends on the specifics of the
111+
PRNG implementation.
112112
* `random_uintegers` - unsigned integers, either 32- (`[0, 2**32-1]`)
113-
or 64-bit (`[0, 2**64-1]`)
114-
* `jump` - Jumps RNGs that support it. `jump` moves the state a great
115-
distance. _Only available if supported by the RNG._
116-
* `advance` - Advanced the RNG 'as-if' a number of draws were made,
117-
without actually drawing the numbers. _Only available if supported by
118-
the RNG._
113+
or 64-bit (`[0, 2**64-1]`)
114+
* `jump` - Jumps RNGs that support it. `jump` moves the state a great
115+
distance. _Only available if supported by the RNG._
116+
* `advance` - Advanced the RNG 'as-if' a number of draws were made,
117+
without actually drawing the numbers. _Only available if supported by
118+
the RNG._
119119

120120
## Status
121121

@@ -126,53 +126,70 @@ the RNG._
126126
* Windows 32/64 bit, Python 2.7, 3.5 and 3.6
127127

128128
## Version
129-
The version matched the latest version of NumPy where
129+
130+
The version matched the latest version of NumPy where
130131
`RandomGenerator(MT19937())` passes all NumPy test.
131132

132133
## Documentation
133134

134135
Documentation for the latest release is available on
135-
[my GitHub pages](http://bashtage.github.io/randomgen/). Documentation for
136-
the latest commit (unreleased) is available under
136+
[my GitHub pages](http://bashtage.github.io/randomgen/). Documentation for
137+
the latest commit (unreleased) is available under
137138
[devel](http://bashtage.github.io/randomgen/devel/).
138139

139140
## Plans
141+
140142
This module is essentially complete. There are a few rough edges that
141143
need to be smoothed.
142144

143-
* Creation of additional streams from where supported
145+
* Creation of additional streams from where supported
144146
(i.e. a `next_stream()` method)
145147

146148
## Requirements
147149
Building requires:
148150

149-
* Python (2.7, 3.4, 3.5, 3.6)
150-
* NumPy (1.11, 1.12, 1.13, 1.14, 1.15)
151-
* Cython (0.26+)
152-
* tempita (0.5+), if not provided by Cython
151+
* Python (2.7, 3.4, 3.5, 3.6)
152+
* NumPy (1.11, 1.12, 1.13, 1.14, 1.15)
153+
* Cython (0.26+)
154+
* tempita (0.5+), if not provided by Cython
153155

154156
Testing requires pytest (3.0+).
155157

156-
**Note:** it might work with other versions but only tested with these
157-
versions.
158+
**Note:** it might work with other versions but only tested with these
159+
versions.
158160

159161
## Development and Testing
160162

161-
All development has been on 64-bit Linux, and it is regularly tested on
163+
All development has been on 64-bit Linux, and it is regularly tested on
162164
Travis-CI (Linux/OSX) and Appveyor (Windows). The library is occasionally
163165
tested on Linux 32-bit and Free BSD 11.1.
164166

165-
Basic tests are in place for all RNGs. The MT19937 is tested against
167+
Basic tests are in place for all RNGs. The MT19937 is tested against
166168
NumPy's implementation for identical results. It also passes NumPy's
167169
test suite where still relevant.
168170

169171
## Installing
170172

173+
Either install from PyPi using
174+
175+
```bash
176+
pip install randomgen
177+
```
178+
179+
or, if you want the latest version,
180+
181+
```bash
182+
pip install git+https://github.com/bashtage/randomgen.git
183+
```
184+
185+
or from a cloned repo,
186+
171187
```bash
172188
python setup.py install
173189
```
174190

175191
### SSE2
192+
176193
`dSFTM` makes use of SSE2 by default. If you have a very old computer
177194
or are building on non-x86, you can install using:
178195

@@ -181,12 +198,12 @@ python setup.py install --no-sse2
181198
```
182199

183200
### Windows
201+
184202
Either use a binary installer, or if building from scratch, use
185203
Python 3.6 with Visual Studio 2015/2017 Community Edition. It can also
186204
be build using Microsoft Visual C++ Compiler for Python 2.7 and
187205
Python 2.7.
188206

189-
190207
## Using
191208

192209
The separate generators are importable from `randomgen`
@@ -205,46 +222,46 @@ rg.random_sample(100)
205222
```
206223

207224
## License
225+
208226
Standard NCSA, plus sub licenses for components.
209227

210228
## Performance
211-
Performance is promising, and even the mt19937 seems to be faster than
212-
NumPy's mt19937.
213229

214-
```
215-
Speed-up relative to NumPy (Uniform Doubles)
216-
************************************************************
217-
DSFMT 137.1%
218-
MT19937 21.0%
219-
PCG32 101.2%
220-
PCG64 110.7%
221-
Philox -2.7%
222-
ThreeFry -11.4%
223-
ThreeFry32 -62.3%
224-
Xoroshiro128 181.4%
225-
Xorshift1024 141.8%
226-
227-
Speed-up relative to NumPy (64-bit unsigned integers)
228-
************************************************************
229-
DSFMT 24.8%
230-
MT19937 15.0%
231-
PCG32 92.6%
232-
PCG64 99.0%
233-
Philox -20.4%
234-
ThreeFry -21.7%
235-
ThreeFry32 -64.4%
236-
Xoroshiro128 164.2%
237-
Xorshift1024 120.8%
238-
239-
Speed-up relative to NumPy (Standard normals)
240-
************************************************************
241-
DSFMT 299.4%
242-
MT19937 271.2%
243-
PCG32 364.5%
244-
PCG64 364.2%
245-
Philox 256.9%
246-
ThreeFry 236.0%
247-
ThreeFry32 97.0%
248-
Xoroshiro128 477.4%
249-
Xorshift1024 360.7%
250-
```
230+
Performance is promising, and even the mt19937 seems to be faster than
231+
NumPy's mt19937.
232+
233+
Speed-up relative to NumPy (Uniform Doubles)
234+
************************************************************
235+
DSFMT 137.1%
236+
MT19937 21.0%
237+
PCG32 101.2%
238+
PCG64 110.7%
239+
Philox -2.7%
240+
ThreeFry -11.4%
241+
ThreeFry32 -62.3%
242+
Xoroshiro128 181.4%
243+
Xorshift1024 141.8%
244+
245+
Speed-up relative to NumPy (64-bit unsigned integers)
246+
************************************************************
247+
DSFMT 24.8%
248+
MT19937 15.0%
249+
PCG32 92.6%
250+
PCG64 99.0%
251+
Philox -20.4%
252+
ThreeFry -21.7%
253+
ThreeFry32 -64.4%
254+
Xoroshiro128 164.2%
255+
Xorshift1024 120.8%
256+
257+
Speed-up relative to NumPy (Standard normals)
258+
************************************************************
259+
DSFMT 299.4%
260+
MT19937 271.2%
261+
PCG32 364.5%
262+
PCG64 364.2%
263+
Philox 256.9%
264+
ThreeFry 236.0%
265+
ThreeFry32 97.0%
266+
Xoroshiro128 477.4%
267+
Xorshift1024 360.7%

0 commit comments

Comments
 (0)
0