Skip to content

Commit 6d99306

Browse files
authored
Merge pull request #420 from bashtage/remove-deprecated-mode
MAINT: Remove deprecated mode
2 parents 47c7f49 + af3f647 commit 6d99306

29 files changed

+99
-317
lines changed

doc/source/change-log.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
Change Log
44
----------
5+
v2.3.0
6+
======
7+
- Added the :class:`~randomgen.blabla.BlaBla` PRNG which is based on the Blake 2b
8+
hash function. :class:`~randomgen.blabla.BlaBla` is a counter-based PRNG like
9+
:class:`~randomgen.aes.AESCounter` and supports both :meth:`~randomgen.blabla.BlaBla.advance`
10+
and :meth:`~randomgen.blabla.BlaBla.jumped`.
11+
- Removed ``mode`` from bit generator initialization. This argument has been deprecated since release 2.0.0.
12+
13+
.. warning::
14+
15+
This change is backward incompatible. If ``mode`` is essential, you should continue to use legacy
16+
versions.
17+
18+
- Moved to the build system to meson which improves build time.
19+
- Fixed a breaking change that affected the use of :func:`functools.partial` test suite in
20+
Python 3.14.
21+
22+
.. note::
23+
24+
There was no version 2.2.0.
525

626
v2.1.0
727
======

doc/source/index.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
100100
arbitrary number of steps or generating independent streams. See the
101101
`Random123`_ page for more details about this class of PRNG.
102102
* Other cryptographic-based generators: :class:`~randomgen.aes.AESCounter`,
103-
:class:`~randomgen.speck128.SPECK128`, :class:`~randomgen.chacha.ChaCha`, and
104-
:class:`~randomgen.hc128.HC128`.
103+
:class:`~randomgen.speck128.SPECK128`, :class:`~randomgen.chacha.ChaCha`,
104+
:class:`~randomgen.hc128.HC128`, and :class:`~randomgen.blabla.BlaBla`.
105105
* XoroShiro128+/++ - Improved version of XorShift128+ with better performance
106106
and statistical quality. Like the XorShift generators, it can be jumped
107107
to produce multiple streams in parallel applications. See
@@ -114,6 +114,8 @@ generators, 'in addition' to the standard PRNG in NumPy. The included PRNGs are
114114
:meth:`~randomgen.xorshift1024.Xorshift1024.jumped` for details. More information
115115
about these PRNGs is available at the
116116
`xorshift, xoroshiro and xoshiro authors' page`_.
117+
* Other PRNGs including :class:`~randomgen.romu.Romu`, :class:`~randomgen.tyche.Tyche`,
118+
and :class:`~randomgen.squares.Squares`.
117119

118120
.. _`NumPy's documentation`: https://docs.scipy.org/doc/numpy/reference/routines.random.html
119121
.. _`dSFMT authors' page`: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/

doc/source/performance.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pandas as pd
66

77
from randomgen import (
8-
BlaBla,
98
DSFMT,
109
EFIIX64,
1110
HC128,
@@ -20,6 +19,7 @@
2019
SFMT,
2120
SPECK128,
2221
AESCounter,
22+
BlaBla,
2323
ChaCha,
2424
Philox,
2525
Romu,
@@ -92,6 +92,7 @@ def __init__(self, *args, **kwargs):
9292
kwargs.pop("variant", None)
9393
super().__init__(*args, variant="dxsm-128", **kwargs)
9494

95+
9596
class TycheOpenRand(Tyche):
9697
def __init__(self, *args, **kwargs):
9798
kwargs.pop("original", None)

randomgen/_deprecated_value.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

randomgen/aes.pyx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!python
22
import numpy as np
33

4-
from randomgen._deprecated_value import _DeprecatedValue
5-
64
__all__ = ["AESCounter"]
75

86
cdef uint64_t aes_uint64(void* st) noexcept nogil:
@@ -16,7 +14,7 @@ cdef double aes_double(void* st) noexcept nogil:
1614

1715
cdef class AESCounter(BitGenerator):
1816
"""
19-
AESCounter(seed=None, *, counter=None, key=None, mode="sequence")
17+
AESCounter(seed=None, *, counter=None, key=None)
2018
2119
Container for the AES Counter pseudo-random number generator.
2220
@@ -37,12 +35,6 @@ cdef class AESCounter(BitGenerator):
3735
another RNG before use, the value in key is directly set. Can be either
3836
a Python int in [0, 2**128) or a 2-element uint64 array.
3937
key and seed cannot both be used.
40-
mode : {None, "sequence"}
41-
Deprecated parameter. Do not use.
42-
43-
.. deprecated: 2.0.0
44-
45-
Starting in version 2, only seed sequences are supported.
4638
4739
Attributes
4840
----------
@@ -128,8 +120,8 @@ cdef class AESCounter(BitGenerator):
128120
.. [1] Advanced Encryption Standard. (n.d.). In Wikipedia. Retrieved
129121
June 1, 2019, from https://en.wikipedia.org/wiki/Advanced_Encryption_Standard
130122
"""
131-
def __init__(self, seed=None, *, counter=None, key=None, mode=_DeprecatedValue):
132-
BitGenerator.__init__(self, seed, mode=mode)
123+
def __init__(self, seed=None, *, counter=None, key=None):
124+
BitGenerator.__init__(self, seed)
133125
# Calloc since ctr needs to be 0
134126
self.rng_state = <aesctr_state_t *>PyArray_calloc_aligned(
135127
sizeof(aesctr_state_t), 1

randomgen/blabla.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ cdef double blabla_double(void* st) noexcept nogil:
1414

1515
cdef class BlaBla(BitGenerator):
1616
"""
17-
BlaBla(seed=None, *, counter=None, key=None, rounds=10, mode="sequence")
17+
BlaBla(seed=None, *, counter=None, key=None, rounds=10)
1818
1919
Container for the BlaBla family of counter pseudo-random number generators
2020
@@ -351,12 +351,13 @@ cdef class BlaBla(BitGenerator):
351351

352352
def advance(self, delta):
353353
"""
354-
Advance the state by delta steps
354+
Advance the state by delta steps.
355355
356356
Parameters
357357
----------
358358
delta : int
359-
Number of steps to advance the state.
359+
Number of steps to advance the state. Delta can be any integer value,
360+
but is wrapped to be in [0, 2**128) which is the size of the counter.
360361
"""
361362
# Squeeze with wrap into [0, 2**128)
362363
delta = delta % (1 << 128)

randomgen/chacha.pyx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!python
22
import numpy as np
33

4-
from randomgen._deprecated_value import _DeprecatedValue
5-
64
__all__ = ["ChaCha"]
75

86
cdef uint64_t chacha_uint64(void* st) noexcept nogil:
@@ -16,7 +14,7 @@ cdef double chacha_double(void* st) noexcept nogil:
1614

1715
cdef class ChaCha(BitGenerator):
1816
"""
19-
ChaCha(seed=None, *, counter=None, key=None, rounds=20, mode="sequence")
17+
ChaCha(seed=None, *, counter=None, key=None, rounds=20)
2018
2119
Container for the ChaCha family of Counter pseudo-random number generators
2220
@@ -43,12 +41,6 @@ cdef class ChaCha(BitGenerator):
4341
The standard number of rounds in 20. Smaller values, usually 8 or
4442
more, can be used to reduce security properties of the random stream
4543
while improving performance.
46-
mode : {None, "sequence"}
47-
Deprecated parameter. Do not use.
48-
49-
.. deprecated: 2.0.0
50-
51-
Starting in version 2, only seed sequences are supported.
5244
5345
Attributes
5446
----------
@@ -134,9 +126,9 @@ cdef class ChaCha(BitGenerator):
134126
http://cr.yp.to/papers.html#chacha. 2008.01.28.
135127
"""
136128
def __init__(
137-
self, seed=None, *, counter=None, key=None, rounds=20, mode=_DeprecatedValue
129+
self, seed=None, *, counter=None, key=None, rounds=20
138130
):
139-
BitGenerator.__init__(self, seed, mode=mode)
131+
BitGenerator.__init__(self, seed)
140132
self.rng_state = <chacha_state_t *>PyArray_malloc_aligned(
141133
sizeof(chacha_state_t)
142134
)

randomgen/common.pyx

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ from numpy.random import SeedSequence
1010
cimport numpy as np
1111
from numpy.random.bit_generator cimport BitGenerator as _BitGenerator
1212

13-
from randomgen._deprecated_value import _DeprecatedValue
1413
from randomgen.seed_sequence import ISeedSequence
1514

1615
ISEED_SEQUENCES = (ISeedSequence, np.random.bit_generator.ISeedSequence)
@@ -54,26 +53,8 @@ cdef class BitGenerator(_BitGenerator):
5453
"""
5554
Abstract class for all BitGenerators
5655
"""
57-
def __init__(self, seed, *, numpy_seed=False, mode=_DeprecatedValue):
58-
if mode is not _DeprecatedValue:
59-
msg = ("mode is deprecated and will be removed in a future version. "
60-
"Seeding defaults to a numpy.random.SeedSequence instance.")
61-
if "numpy" in self._supported_modes():
62-
msg += " Use numpy_seed=True to enforce numpy-compatible seeding."
63-
warnings.warn(msg, FutureWarning)
64-
if mode is not _DeprecatedValue and (
65-
not isinstance(mode, str) or mode.lower() not in self._supported_modes()
66-
):
67-
if len(self._supported_modes()) == 1:
68-
msg = f"mode must be {self._supported_modes()[0]}"
69-
else:
70-
msg = (
71-
"mode must be one of: " +
72-
", ".join(f"\"{mode}\"" for mode in self._supported_modes())
73-
)
74-
raise ValueError(msg)
75-
mode = mode.lower() if isinstance(mode, str) else mode
76-
self.mode = "numpy" if (numpy_seed or mode == "numpy") else "sequence"
56+
def __init__(self, seed, *, numpy_seed=False):
57+
self.mode = "numpy" if numpy_seed else "sequence"
7758
super().__init__(seed)
7859
if type(self) is BitGenerator:
7960
raise NotImplementedError(

randomgen/dsfmt.pyx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import numpy as np
44

5-
from randomgen._deprecated_value import _DeprecatedValue
6-
75
__all__ = ["DSFMT"]
86

97
DEF DSFMT_MEXP = 19937
@@ -25,7 +23,7 @@ cdef uint64_t dsfmt_raw(void *st) noexcept nogil:
2523

2624
cdef class DSFMT(BitGenerator):
2725
"""
28-
DSFMT(seed=None, *, mode="sequence")
26+
DSFMT(seed=None)
2927
3028
Container for the SIMD-based Mersenne Twister pseudo RNG.
3129
@@ -38,12 +36,6 @@ cdef class DSFMT(BitGenerator):
3836
``None`` (the default). If `seed` is ``None``, then 764 32-bit unsigned
3937
integers are read from ``/dev/urandom`` (or the Windows analog) if
4038
available. If unavailable, a hash of the time and process ID is used.
41-
mode : {None, "sequence"}
42-
Deprecated parameter. Do not use.
43-
44-
.. deprecated: 2.0.0
45-
46-
Starting in version 2, only seed sequences are supported.
4739
4840
Attributes
4941
----------
@@ -114,8 +106,8 @@ cdef class DSFMT(BitGenerator):
114106
Sequences and Their Applications - SETA, 290--298, 2008.
115107
"""
116108

117-
def __init__(self, seed=None, *, mode=_DeprecatedValue):
118-
BitGenerator.__init__(self, seed, mode=mode)
109+
def __init__(self, seed=None):
110+
BitGenerator.__init__(self, seed)
119111
self.rng_state.state = <dsfmt_t *>PyArray_malloc_aligned(sizeof(dsfmt_t))
120112
self.rng_state.buffered_uniforms = <double *>PyArray_calloc_aligned(
121113
DSFMT_N64, sizeof(double)

randomgen/hc128.pyx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# coding=utf-8
33
import numpy as np
44

5-
from randomgen._deprecated_value import _DeprecatedValue
6-
75
__all__ = ["HC128"]
86

97
cdef uint64_t hc128_uint64(void* st) noexcept nogil:
@@ -18,7 +16,7 @@ cdef double hc128_double(void* st) noexcept nogil:
1816

1917
cdef class HC128(BitGenerator):
2018
"""
21-
HC128(seed=None, *, key=None, mode="sequence")
19+
HC128(seed=None, *, key=None)
2220
2321
Container for the HC-128 cipher-based pseudo-random number generator
2422
@@ -35,12 +33,6 @@ cdef class HC128(BitGenerator):
3533
Key for HC128. The key is a 256-bit integer that contains both the
3634
key (lower 128 bits) and initial values (upper 128-bits) for the
3735
HC-128 cipher. key and seed cannot both be used.
38-
mode : {None, "sequence"}
39-
Deprecated parameter. Do not use.
40-
41-
.. deprecated: 2.0.0
42-
43-
Starting in version 2, only seed sequences are supported.
4436
4537
Attributes
4638
----------
@@ -111,8 +103,8 @@ cdef class HC128(BitGenerator):
111103
.. [2] Wu, Hongjun, "Stream Ciphers HC-128 and HC-256".
112104
https://www.ntu.edu.sg/home/wuhj/research/hc/index.html)
113105
"""
114-
def __init__(self, seed=None, *, key=None, mode=_DeprecatedValue):
115-
BitGenerator.__init__(self, seed, mode=mode)
106+
def __init__(self, seed=None, *, key=None):
107+
BitGenerator.__init__(self, seed)
116108
self.seed(seed, key)
117109

118110
self._bitgen.state = <void *>&self.rng_state

0 commit comments

Comments
 (0)