Skip to content

Commit

Permalink
Merge pull request #247 from bashtage/refactor-rdrand
Browse files Browse the repository at this point in the history
ENH: Add Cary Flag check to RDRAND
  • Loading branch information
bashtage authored Jul 13, 2020
2 parents ca3100f + 638aa64 commit 8c24046
Show file tree
Hide file tree
Showing 35 changed files with 508 additions and 94 deletions.
7 changes: 7 additions & 0 deletions doc/source/bit_generators/rdrand.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Seeding and State

~RDRAND.seed
~RDRAND.state
~RDRAND.success

Parallel generation
===================
Expand All @@ -37,3 +38,9 @@ Testing
:toctree: generated/

~RDRAND.random_raw
~RDRAND.checked_raw

Custom Lock
===========

.. autoclass:: RaisingLock
10 changes: 10 additions & 0 deletions doc/source/change-log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ Change Log
maintained until after NumPy 1.21 (or 2 releases after NumPy 1.19) for users who
cannot update NumPy.

v1.19.2
=======
- Corrected :class:`~randomgen.rdrand.RDRAND` to retry on failures with pause
between retries. Add a parameter ``retry`` which allows the number of retries
to be set. It defaults to the Intel recommended value of 10. Also sets an
exception when the number of retries has been exhausted (very unlikely). See
the :class:`~randomgen.rdrand.RDRAND` docstring with unique considerations
when using :class:`~randomgen.rdrand.RDRAND` that do not occur with deterministic
PRNGs.

v1.19.1
=======
- Added :class:`randomgen.romu.Romu` which is among the fastest available bit generators.
Expand Down
3 changes: 2 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

# -- Path setup --------------------------------------------------------------

import sphinx_material

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

# -- Project information -----------------------------------------------------

Expand Down
4 changes: 4 additions & 0 deletions doc/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,7 @@ weyl
Romu
romu
unpickling
Skylake
intel
Intrinsics
2 changes: 1 addition & 1 deletion randomgen/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def __str__(self):
)
)

from functools import wraps
import re
import warnings
from functools import wraps

class suppress_warnings(object):
"""
Expand Down
4 changes: 2 additions & 2 deletions randomgen/common.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ cdef class BitGenerator:

def random_raw(self, size=None, output=True):
"""
random_raw(size=None)
random_raw(size=None, output=True)
Return randoms as generated by the underlying BitGenerator
Expand All @@ -135,7 +135,7 @@ cdef class BitGenerator:
Returns
-------
out : uint or ndarray
out : {uint64, ndarray, None}
Drawn samples.
Notes
Expand Down
8 changes: 4 additions & 4 deletions randomgen/dsfmt.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ cdef extern from "src/dsfmt/dsfmt.h":

ctypedef DSFMT_STATE_T dsfmt_state_t

double dsfmt_next_double(dsfmt_state_t *state) nogil
uint64_t dsfmt_next64(dsfmt_state_t *state) nogil
uint32_t dsfmt_next32(dsfmt_state_t *state) nogil
uint64_t dsfmt_next_raw(dsfmt_state_t *state) nogil
double dsfmt_next_double(dsfmt_state_t *state) nogil
uint64_t dsfmt_next64(dsfmt_state_t *state) nogil
uint32_t dsfmt_next32(dsfmt_state_t *state) nogil
uint64_t dsfmt_next_raw(dsfmt_state_t *state) nogil

void dsfmt_init_gen_rand(dsfmt_t *dsfmt, uint32_t seed)
void dsfmt_init_by_array(dsfmt_t *dsfmt, uint32_t init_key[], int key_length)
Expand Down
4 changes: 2 additions & 2 deletions randomgen/efiix64.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ cdef extern from "src/efiix64/efiix64.h":

ctypedef EFIIX64_STATE_T efiix64_state_t

uint64_t efiix64_next64(efiix64_state_t *state) nogil
uint32_t efiix64_next32(efiix64_state_t *state) nogil
uint64_t efiix64_next64(efiix64_state_t *state) nogil
uint32_t efiix64_next32(efiix64_state_t *state) nogil
void efiix64_seed(efiix64_state_t *state, uint64_t seed[4])


Expand Down
2 changes: 1 addition & 1 deletion randomgen/entropy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __all__ = ["random_entropy", "seed_by_array"]
np.import_array()

cdef extern from "src/splitmix64/splitmix64.h":
cdef uint64_t splitmix64_next(uint64_t *state) nogil
cdef uint64_t splitmix64_next(uint64_t *state) nogil

cdef extern from "src/entropy/entropy.h":
cdef bint entropy_getbytes(void* dest, size_t size)
Expand Down
6 changes: 3 additions & 3 deletions randomgen/mt19937.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ cdef extern from "src/mt19937/mt19937.h":

ctypedef MT19937_STATE_T mt19937_state_t

uint64_t mt19937_next64(mt19937_state_t *state) nogil
uint32_t mt19937_next32(mt19937_state_t *state) nogil
double mt19937_next_double(mt19937_state_t *state) nogil
uint64_t mt19937_next64(mt19937_state_t *state) nogil
uint32_t mt19937_next32(mt19937_state_t *state) nogil
double mt19937_next_double(mt19937_state_t *state) nogil
void mt19937_init_by_array(mt19937_state_t *state, uint32_t *init_key, int key_length)
void mt19937_seed(mt19937_state_t *state, uint32_t seed)
void mt19937_jump(mt19937_state_t *state)
Expand Down
6 changes: 3 additions & 3 deletions randomgen/mt64.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ cdef extern from "src/mt64/mt64.h":

ctypedef MT64_STATE_T mt64_state_t

uint64_t mt64_next64(mt64_state_t *state) nogil
uint32_t mt64_next32(mt64_state_t *state) nogil
double mt64_next_double(mt64_state_t *state) nogil
uint64_t mt64_next64(mt64_state_t *state) nogil
uint32_t mt64_next32(mt64_state_t *state) nogil
double mt64_next_double(mt64_state_t *state) nogil
void mt64_init_by_array(mt64_state_t *state, uint64_t *init_key, int key_length)
void mt64_seed(mt64_state_t *state, uint64_t seed)

Expand Down
6 changes: 3 additions & 3 deletions randomgen/pcg32.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ cdef extern from "src/pcg32/pcg32.h":

ctypedef PCG32_STATE_T pcg32_state_t

uint64_t pcg32_next64(pcg32_state_t *state) nogil
uint32_t pcg32_next32(pcg32_state_t *state) nogil
double pcg32_next_double(pcg32_state_t *state) nogil
uint64_t pcg32_next64(pcg32_state_t *state) nogil
uint32_t pcg32_next32(pcg32_state_t *state) nogil
double pcg32_next_double(pcg32_state_t *state) nogil
void pcg32_jump(pcg32_state_t *state)
void pcg32_advance_state(pcg32_state_t *state, uint64_t step)
void pcg32_set_seed(pcg32_state_t *state, uint64_t seed, uint64_t inc)
Expand Down
4 changes: 2 additions & 2 deletions randomgen/pcg64.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cdef extern from "src/pcg64/pcg64-v2.h":

ctypedef PCG64_STATE_T pcg64_state_t

uint64_t pcg64_next64(pcg64_state_t *state) nogil
uint32_t pcg64_next32(pcg64_state_t *state) nogil
uint64_t pcg64_next64(pcg64_state_t *state) nogil
uint32_t pcg64_next32(pcg64_state_t *state) nogil
uint64_t pcg64_cm_dxsm_next64(pcg64_state_t *state) nogil
uint32_t pcg64_cm_dxsm_next32(pcg64_state_t *state) nogil

Expand Down
18 changes: 18 additions & 0 deletions randomgen/rdrand.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from randomgen.common cimport *

DEF BUFFER_SIZE = 256

cdef extern from "src/rdrand/rdrand.h":

struct s_rdrand_state:
uint64_t buffer[BUFFER_SIZE]
int buffer_loc
int status
int retries
uint64_t weyl_seq

ctypedef s_rdrand_state rdrand_state

int rdrand_fill_buffer(rdrand_state *state) nogil
int rdrand_next64(rdrand_state *state, uint64_t *val) nogil
int rdrand_capable()
Loading

0 comments on commit 8c24046

Please sign in to comment.