Skip to content

Commit 76f757b

Browse files
committed
FInal changes for NumPy 2 compat
1 parent 2f25051 commit 76f757b

25 files changed

+43
-151
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ the latest commit (unreleased) is available under
120120
## Requirements
121121
Building requires:
122122

123-
* Python (3.6, 3.7, 3.8, 3.9, 3.10)
124-
* NumPy (1.17+)
125-
* Cython (0.29+)
126-
* tempita (0.5+), if not provided by Cython
123+
* Python (3.9, 3.10, 3.11, 3.12, 3.13)
124+
* NumPy (1.22.3+, runtime, 2.0.0+, building)
125+
* Cython (3.0.10+)
127126

128-
Testing requires pytest (6+).
127+
Testing requires pytest (7+).
129128

130129
**Note:** it might work with other versions but only tested with these
131130
versions.

doc/source/change-log.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
Change Log
44
----------
55

6-
.. container:: admonition danger
7-
8-
.. raw:: html
9-
10-
<p class="admonition-title"> Deprecated </p>
11-
12-
``Generator`` and ``RandomState`` were **REMOVED** in 1.23.
13-
You should be using :class:`numpy.random.Generator` or
14-
:class:`numpy.random.RandomState` which are maintained.
6+
v2.0.0
7+
======
8+
- Final compatibility with NumPy 2
9+
- Minimum NumPy is now 1.22.3.
10+
- Removed ``"legacy"`` seeding in favor of using :class:`~numpy.random.SeedSequence`.
11+
- Removed the the vendored copy of ``SeedSequence``.
12+
- Deprecated using the ``mode`` keyword argument to set the seed mode, since only ``SeedSequences`` are supported.
13+
- Changed ``ranomgen.common.BitGenerator`` to inherit from ``numpy.random.BitGenerator`` so that
14+
numpy will recognize these as ``BitGenerators``.
15+
- Removed C distribution functions that are available in NumPy (see libnpyrandom)`.
16+
- General code cleanup and modernization.
1517

1618
v1.26.1
1719
=======
@@ -54,7 +56,7 @@ v1.20.2
5456
:class:`~randomgen.mt19937.MT19937`, :class:`~randomgen.philox.Philox`, and
5557
:class:`~randomgen.sfc.SFC64`. When using this mode, the sequence generated is
5658
guaranteed to match the sequence produced using the NumPy implementations as long as
57-
a :class:`~randomgen.seed_sequence.SeedSequence` or :class:`numpy.random.SeedSequence`
59+
a ``randomgen.seed_sequence.SeedSequence`` or :class:`numpy.random.SeedSequence`
5860
is used with the same initial seed values.
5961
- Added :func:`~randomgen.generator.ExtendedGenerator.random` with support for
6062
``dtype="longdouble"`` to produce extended precision random floats.
@@ -139,7 +141,7 @@ v1.18.0
139141
=======
140142
- ``choice`` pulled in upstream performance improvement that
141143
use a hash set when choosing without replacement and without user-provided probabilities.
142-
- Added support for :class:`~randomgen.seed_sequence.SeedSequence` (and NumPy's ``SeedSequence``).
144+
- Added support for ``randomgen.seed_sequence.SeedSequence`` (and NumPy's :class:`~numpy.random.SeedSequence`).
143145
- Fixed a bug that affected both ``randomgen.generator.Generator.randint``
144146
in ``Generator`` and ``randint``
145147
in ``RandomState`` when ``high=2**32``. This value is inbounds for

doc/source/evolution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ The main changes are
4848
* Change ``jump`` which operated in-place to ``jumped`` which returns a new ``BitGenerator``.
4949
* Rename Basic RNG to bit generator, which impacts the API in multiple places where names
5050
like ``brng`` and ``basic_rng`` have been replaced by ``bitgen`` or ``bit_generator``.
51-
* Support for :class:`~randomgen.seed_sequence.SeedSequence` (also support NumPy ``SeedSequence`` instances)
51+
* Support for ``randomgen.seed_sequence.SeedSequence`` (also support NumPy :class:`~numpy.random.SeedSequence` instances)
5252
* Removed support for Python 2.7

doc/source/multithreading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The four core distributions in :class:`~numpy.random.Generator` all allow
55
existing arrays to be filled using the ``out`` keyword argument.
66
Existing arrays need to be contiguous and well-behaved (writable and aligned).
77
Under normal circumstances, arrays created using the common constructors such
8-
as :meth:`numpy.empty` will satisfy these requirements.
8+
as :func:`numpy.empty` will satisfy these requirements.
99

1010
This example makes use of Python 3 :mod:`concurrent.futures` to fill an array
1111
using multiple threads. Threads are long-lived so that repeated calls do not

doc/source/new-or-different.rst

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -63,96 +63,6 @@ Differences from NumPy (1.17+)
6363
* :class:`~randomgen.xoshiro256.Xoshiro256`
6464
* :class:`~randomgen.xoshiro512.Xoshiro512`
6565

66-
.. container:: admonition danger
67-
68-
.. raw:: html
69-
70-
<p class="admonition-title"> Deprecated </p>
71-
72-
``Generator`` is **deprecated**. You should be using
73-
:class:`numpy.random.Generator`.
74-
75-
* randomgen's ``Generator`` continues to expose legacy
76-
methods ``random_sample``, ``randint``, ``random_integers``, ``rand``, ``randn``,
77-
and ``tomaxint``. **Note**: These should not be used, and their modern replacements are preferred:
78-
79-
* ``random_sample``, ``rand` → ``random``
80-
* ``random_integers``, ``randint`` → ``integers``
81-
* ``randn`` → ``standard_normal``
82-
* ``tomaxint`` → ``integers`` with ``dtype`` set to ``int``
83-
84-
* randomgen's bit generators remain seedable and the convenience function
85-
``seed` is exposed as part of``Generator``. Additionally, the convenience
86-
property ``state`` is available to get or set the state of the underlying bit generator.
87-
88-
* :func:`numpy.random.Generator.multivariate_hypergeometric` was added after
89-
``Generator`` was merged into NumPy and will not be ported over.
90-
91-
* :func:`numpy.random.Generator.shuffle` and :func:`numpy.random.Generator.permutation`
92-
support ``axis`` keyword to operator along an axis other than 0.
93-
94-
* ``integers`` supports the keyword argument ``use_masked`` to switch between masked
95-
generation of bounded integers and Lemire's superior method.
96-
97-
Differences from NumPy before 1.17
98-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99-
* The normal, exponential and gamma generators use 256-step Ziggurat
100-
methods which are 2-10 times faster than NumPy's default implementation in
101-
``standard_normal``, ``standard_exponential`` or ``standard_gamma``.
102-
103-
* The Box-Muller used to produce NumPy's normals is no longer available.
104-
* All bit generators functions to produce doubles, uint64s and
105-
uint32s via CTypes (:meth:`~randomgen.xoroshiro128.Xoroshiro128.ctypes`)
106-
and CFFI (:meth:`~randomgen.xoroshiro128.Xoroshiro128.cffi`). This allows
107-
the bit generators to be used in numba or in other low-level applications
108-
* The bit generators can be used in downstream projects via Cython.
109-
* Optional ``dtype`` argument that accepts ``np.float32`` or ``np.float64``
110-
to produce either single or double prevision uniform random variables for
111-
select core distributions
112-
113-
* Uniforms (``random`` and ``rand``)
114-
* Normals (``standard_normal`` and ``randn``)
115-
* Standard Gammas (``standard_gamma``)
116-
* Standard Exponentials (``standard_exponential``)
117-
118-
* Optional ``out`` argument that allows existing arrays to be filled for
119-
select core distributions
120-
121-
* Uniforms (``random``)
122-
* Normals (``standard_normal``)
123-
* Standard Gammas (``standard_gamma``)
124-
* Standard Exponentials (``standard_exponential``)
125-
126-
This allows multithreading to fill large arrays in chunks using suitable
127-
PRNGs in parallel.
128-
129-
130-
* ``integers`` supports broadcasting inputs.
131-
132-
* ``integers`` supports drawing from open (default, ``[low, high)``) or closed
133-
(``[low, high]``) intervals using the keyword argument
134-
``endpoint``. Closed intervals are simpler to use when the
135-
distribution may include the maximum value of a given integer type.
136-
137-
138-
* The closed interval is particularly helpful when using arrays since
139-
it avoids object-dtype arrays when sampling from the full range.
140-
141-
142-
* Support for Lemire’s method of generating uniform integers on an
143-
arbitrary interval by setting ``use_masked=True`` in
144-
(``integers``).
145-
146-
147-
* ``multinomial`` supports multidimensional values of ``n``
148-
149-
150-
* ``choice`` is much faster when sampling small amounts from large arrays
151-
152-
153-
* ``choice`` supports the ``axis`` keyword to work with multidimensional arrays.
154-
155-
15666
* For changes since the previous release, see the :ref:`change-log`
15767

15868
.. _the demonstration notebook: custom-bit-generators.ipynb

doc/source/seed_sequence.rst

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
Seed Sequences
22
--------------
33

4-
.. module:: randomgen._seed_sequence
5-
6-
.. currentmodule:: randomgen._seed_sequence
7-
84
.. note::
95

10-
randomgen imports ``SeedSequece`` from NumPy if available, and only falls back to a vendored
11-
copy if not. The correct import location is ``randomgen.seed_sequence`` which handles to
12-
selection of the correct ``SeedSequence``.
13-
14-
.. autoclass:: SeedSequence
15-
16-
Using a SeedSequence
17-
====================
18-
19-
.. autosummary::
20-
:toctree: generated/
21-
22-
~SeedSequence.generate_state
23-
~SeedSequence.spawn
24-
25-
State
26-
=====
6+
randomgen imports :class:`~numpy.random.SeedSequence` from NumPy. As of version 2.0.0, randomgen does not provide
7+
a vendored copy of ``SeedSequence``.
278

28-
.. autosummary::
29-
:toctree: generated/
9+
.. deprecated:: 2.0.0
3010

31-
~SeedSequence.state
11+
``SeedSequence`` is now available in NumPy. Use :class:`~numpy.random.SeedSequence`
12+
instead. Importing ``SeedSequence`` from randomgen will be removed in a future version.

randomgen/aes.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cdef double aes_double(void* st) noexcept nogil:
1717

1818
cdef class AESCounter(BitGenerator):
1919
"""
20-
AESCounter(seed=None, *, counter=None, key=None, mode=<deprecated>)
20+
AESCounter(seed=None, *, counter=None, key=None, mode="sequence")
2121
2222
Container for the AES Counter pseudo-random number generator.
2323

randomgen/chacha.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cdef double chacha_double(void* st) noexcept nogil:
1818

1919
cdef class ChaCha(BitGenerator):
2020
"""
21-
ChaCha(seed=None, *, counter=None, key=None, rounds=20, mode=<deprecated>)
21+
ChaCha(seed=None, *, counter=None, key=None, rounds=20, mode="sequence")
2222
2323
Container for the ChaCha family of Counter pseudo-random number generators
2424

randomgen/dsfmt.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cdef uint64_t dsfmt_raw(void *st) noexcept nogil:
2727

2828
cdef class DSFMT(BitGenerator):
2929
"""
30-
DSFMT(seed=None, *, mode=<deprecated>)
30+
DSFMT(seed=None, *, mode="sequence")
3131
3232
Container for the SIMD-based Mersenne Twister pseudo RNG.
3333

randomgen/generator.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ cdef class ExtendedGenerator:
255255
256256
Returns
257257
-------
258-
out : integer or ndarray
258+
out : int or ndarray
259259
Drawn samples.
260260
261261
Notes

0 commit comments

Comments
 (0)