Skip to content

Commit 8c24046

Browse files
authored
Merge pull request #247 from bashtage/refactor-rdrand
ENH: Add Cary Flag check to RDRAND
2 parents ca3100f + 638aa64 commit 8c24046

35 files changed

+508
-94
lines changed

doc/source/bit_generators/rdrand.rst

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Seeding and State
1515

1616
~RDRAND.seed
1717
~RDRAND.state
18+
~RDRAND.success
1819

1920
Parallel generation
2021
===================
@@ -37,3 +38,9 @@ Testing
3738
:toctree: generated/
3839

3940
~RDRAND.random_raw
41+
~RDRAND.checked_raw
42+
43+
Custom Lock
44+
===========
45+
46+
.. autoclass:: RaisingLock

doc/source/change-log.rst

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ Change Log
1515
maintained until after NumPy 1.21 (or 2 releases after NumPy 1.19) for users who
1616
cannot update NumPy.
1717

18+
v1.19.2
19+
=======
20+
- Corrected :class:`~randomgen.rdrand.RDRAND` to retry on failures with pause
21+
between retries. Add a parameter ``retry`` which allows the number of retries
22+
to be set. It defaults to the Intel recommended value of 10. Also sets an
23+
exception when the number of retries has been exhausted (very unlikely). See
24+
the :class:`~randomgen.rdrand.RDRAND` docstring with unique considerations
25+
when using :class:`~randomgen.rdrand.RDRAND` that do not occur with deterministic
26+
PRNGs.
27+
1828
v1.19.1
1929
=======
2030
- Added :class:`randomgen.romu.Romu` which is among the fastest available bit generators.

doc/source/conf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
# -- Path setup --------------------------------------------------------------
1010

11+
import sphinx_material
12+
1113
# If extensions (or modules to document with autodoc) are in another directory,
1214
# add these directories to sys.path here. If the directory is relative to the
1315
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -16,7 +18,6 @@
1618
# import sys
1719
# sys.path.insert(0, os.path.abspath('.'))
1820
import randomgen
19-
import sphinx_material
2021

2122
# -- Project information -----------------------------------------------------
2223

doc/source/spelling_wordlist.txt

+4
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,7 @@ weyl
272272
Romu
273273
274274
romu
275+
unpickling
276+
Skylake
277+
intel
278+
Intrinsics

randomgen/_testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def __str__(self):
4545
)
4646
)
4747

48+
from functools import wraps
4849
import re
4950
import warnings
50-
from functools import wraps
5151

5252
class suppress_warnings(object):
5353
"""

randomgen/common.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ cdef class BitGenerator:
119119

120120
def random_raw(self, size=None, output=True):
121121
"""
122-
random_raw(size=None)
122+
random_raw(size=None, output=True)
123123
124124
Return randoms as generated by the underlying BitGenerator
125125
@@ -135,7 +135,7 @@ cdef class BitGenerator:
135135
136136
Returns
137137
-------
138-
out : uint or ndarray
138+
out : {uint64, ndarray, None}
139139
Drawn samples.
140140
141141
Notes

randomgen/dsfmt.pxd

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ cdef extern from "src/dsfmt/dsfmt.h":
2727

2828
ctypedef DSFMT_STATE_T dsfmt_state_t
2929

30-
double dsfmt_next_double(dsfmt_state_t *state) nogil
31-
uint64_t dsfmt_next64(dsfmt_state_t *state) nogil
32-
uint32_t dsfmt_next32(dsfmt_state_t *state) nogil
33-
uint64_t dsfmt_next_raw(dsfmt_state_t *state) nogil
30+
double dsfmt_next_double(dsfmt_state_t *state) nogil
31+
uint64_t dsfmt_next64(dsfmt_state_t *state) nogil
32+
uint32_t dsfmt_next32(dsfmt_state_t *state) nogil
33+
uint64_t dsfmt_next_raw(dsfmt_state_t *state) nogil
3434

3535
void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
3636
void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[], int key_length)

randomgen/efiix64.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ cdef extern from "src/efiix64/efiix64.h":
1414

1515
ctypedef EFIIX64_STATE_T efiix64_state_t
1616

17-
uint64_t efiix64_next64(efiix64_state_t *state) nogil
18-
uint32_t efiix64_next32(efiix64_state_t *state) nogil
17+
uint64_t efiix64_next64(efiix64_state_t *state) nogil
18+
uint32_t efiix64_next32(efiix64_state_t *state) nogil
1919
void efiix64_seed(efiix64_state_t *state, uint64_t seed[4])
2020

2121

randomgen/entropy.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __all__ = ["random_entropy", "seed_by_array"]
88
np.import_array()
99

1010
cdef extern from "src/splitmix64/splitmix64.h":
11-
cdef uint64_t splitmix64_next(uint64_t *state) nogil
11+
cdef uint64_t splitmix64_next(uint64_t *state) nogil
1212

1313
cdef extern from "src/entropy/entropy.h":
1414
cdef bint entropy_getbytes(void* dest, size_t size)

randomgen/mt19937.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ cdef extern from "src/mt19937/mt19937.h":
88

99
ctypedef MT19937_STATE_T mt19937_state_t
1010

11-
uint64_t mt19937_next64(mt19937_state_t *state) nogil
12-
uint32_t mt19937_next32(mt19937_state_t *state) nogil
13-
double mt19937_next_double(mt19937_state_t *state) nogil
11+
uint64_t mt19937_next64(mt19937_state_t *state) nogil
12+
uint32_t mt19937_next32(mt19937_state_t *state) nogil
13+
double mt19937_next_double(mt19937_state_t *state) nogil
1414
void mt19937_init_by_array(mt19937_state_t *state, uint32_t *init_key, int key_length)
1515
void mt19937_seed(mt19937_state_t *state, uint32_t seed)
1616
void mt19937_jump(mt19937_state_t *state)

randomgen/mt64.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ cdef extern from "src/mt64/mt64.h":
1010

1111
ctypedef MT64_STATE_T mt64_state_t
1212

13-
uint64_t mt64_next64(mt64_state_t *state) nogil
14-
uint32_t mt64_next32(mt64_state_t *state) nogil
15-
double mt64_next_double(mt64_state_t *state) nogil
13+
uint64_t mt64_next64(mt64_state_t *state) nogil
14+
uint32_t mt64_next32(mt64_state_t *state) nogil
15+
double mt64_next_double(mt64_state_t *state) nogil
1616
void mt64_init_by_array(mt64_state_t *state, uint64_t *init_key, int key_length)
1717
void mt64_seed(mt64_state_t *state, uint64_t seed)
1818

randomgen/pcg32.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ cdef extern from "src/pcg32/pcg32.h":
1313

1414
ctypedef PCG32_STATE_T pcg32_state_t
1515

16-
uint64_t pcg32_next64(pcg32_state_t *state) nogil
17-
uint32_t pcg32_next32(pcg32_state_t *state) nogil
18-
double pcg32_next_double(pcg32_state_t *state) nogil
16+
uint64_t pcg32_next64(pcg32_state_t *state) nogil
17+
uint32_t pcg32_next32(pcg32_state_t *state) nogil
18+
double pcg32_next_double(pcg32_state_t *state) nogil
1919
void pcg32_jump(pcg32_state_t *state)
2020
void pcg32_advance_state(pcg32_state_t *state, uint64_t step)
2121
void pcg32_set_seed(pcg32_state_t *state, uint64_t seed, uint64_t inc)

randomgen/pcg64.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ cdef extern from "src/pcg64/pcg64-v2.h":
1515

1616
ctypedef PCG64_STATE_T pcg64_state_t
1717

18-
uint64_t pcg64_next64(pcg64_state_t *state) nogil
19-
uint32_t pcg64_next32(pcg64_state_t *state) nogil
18+
uint64_t pcg64_next64(pcg64_state_t *state) nogil
19+
uint32_t pcg64_next32(pcg64_state_t *state) nogil
2020
uint64_t pcg64_cm_dxsm_next64(pcg64_state_t *state) nogil
2121
uint32_t pcg64_cm_dxsm_next32(pcg64_state_t *state) nogil
2222

randomgen/rdrand.pxd

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from randomgen.common cimport *
2+
3+
DEF BUFFER_SIZE = 256
4+
5+
cdef extern from "src/rdrand/rdrand.h":
6+
7+
struct s_rdrand_state:
8+
uint64_t buffer[BUFFER_SIZE]
9+
int buffer_loc
10+
int status
11+
int retries
12+
uint64_t weyl_seq
13+
14+
ctypedef s_rdrand_state rdrand_state
15+
16+
int rdrand_fill_buffer(rdrand_state *state) nogil
17+
int rdrand_next64(rdrand_state *state, uint64_t *val) nogil
18+
int rdrand_capable()

0 commit comments

Comments
 (0)