Skip to content

Commit

Permalink
Merge pull request #375 from bashtage/rls-2
Browse files Browse the repository at this point in the history
FInal changes for NumPy 2 compat
  • Loading branch information
bashtage authored Sep 23, 2024
2 parents 2f25051 + 76f757b commit 6f3d711
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 151 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ the latest commit (unreleased) is available under
## Requirements
Building requires:

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

Testing requires pytest (6+).
Testing requires pytest (7+).

**Note:** it might work with other versions but only tested with these
versions.
Expand Down
24 changes: 13 additions & 11 deletions doc/source/change-log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
Change Log
----------

.. container:: admonition danger

.. raw:: html

<p class="admonition-title"> Deprecated </p>

``Generator`` and ``RandomState`` were **REMOVED** in 1.23.
You should be using :class:`numpy.random.Generator` or
:class:`numpy.random.RandomState` which are maintained.
v2.0.0
======
- Final compatibility with NumPy 2
- Minimum NumPy is now 1.22.3.
- Removed ``"legacy"`` seeding in favor of using :class:`~numpy.random.SeedSequence`.
- Removed the the vendored copy of ``SeedSequence``.
- Deprecated using the ``mode`` keyword argument to set the seed mode, since only ``SeedSequences`` are supported.
- Changed ``ranomgen.common.BitGenerator`` to inherit from ``numpy.random.BitGenerator`` so that
numpy will recognize these as ``BitGenerators``.
- Removed C distribution functions that are available in NumPy (see libnpyrandom)`.
- General code cleanup and modernization.

v1.26.1
=======
Expand Down Expand Up @@ -54,7 +56,7 @@ v1.20.2
:class:`~randomgen.mt19937.MT19937`, :class:`~randomgen.philox.Philox`, and
:class:`~randomgen.sfc.SFC64`. When using this mode, the sequence generated is
guaranteed to match the sequence produced using the NumPy implementations as long as
a :class:`~randomgen.seed_sequence.SeedSequence` or :class:`numpy.random.SeedSequence`
a ``randomgen.seed_sequence.SeedSequence`` or :class:`numpy.random.SeedSequence`
is used with the same initial seed values.
- Added :func:`~randomgen.generator.ExtendedGenerator.random` with support for
``dtype="longdouble"`` to produce extended precision random floats.
Expand Down Expand Up @@ -139,7 +141,7 @@ v1.18.0
=======
- ``choice`` pulled in upstream performance improvement that
use a hash set when choosing without replacement and without user-provided probabilities.
- Added support for :class:`~randomgen.seed_sequence.SeedSequence` (and NumPy's ``SeedSequence``).
- Added support for ``randomgen.seed_sequence.SeedSequence`` (and NumPy's :class:`~numpy.random.SeedSequence`).
- Fixed a bug that affected both ``randomgen.generator.Generator.randint``
in ``Generator`` and ``randint``
in ``RandomState`` when ``high=2**32``. This value is inbounds for
Expand Down
2 changes: 1 addition & 1 deletion doc/source/evolution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ The main changes are
* Change ``jump`` which operated in-place to ``jumped`` which returns a new ``BitGenerator``.
* Rename Basic RNG to bit generator, which impacts the API in multiple places where names
like ``brng`` and ``basic_rng`` have been replaced by ``bitgen`` or ``bit_generator``.
* Support for :class:`~randomgen.seed_sequence.SeedSequence` (also support NumPy ``SeedSequence`` instances)
* Support for ``randomgen.seed_sequence.SeedSequence`` (also support NumPy :class:`~numpy.random.SeedSequence` instances)
* Removed support for Python 2.7
2 changes: 1 addition & 1 deletion doc/source/multithreading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The four core distributions in :class:`~numpy.random.Generator` all allow
existing arrays to be filled using the ``out`` keyword argument.
Existing arrays need to be contiguous and well-behaved (writable and aligned).
Under normal circumstances, arrays created using the common constructors such
as :meth:`numpy.empty` will satisfy these requirements.
as :func:`numpy.empty` will satisfy these requirements.

This example makes use of Python 3 :mod:`concurrent.futures` to fill an array
using multiple threads. Threads are long-lived so that repeated calls do not
Expand Down
90 changes: 0 additions & 90 deletions doc/source/new-or-different.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,96 +63,6 @@ Differences from NumPy (1.17+)
* :class:`~randomgen.xoshiro256.Xoshiro256`
* :class:`~randomgen.xoshiro512.Xoshiro512`

.. container:: admonition danger

.. raw:: html

<p class="admonition-title"> Deprecated </p>

``Generator`` is **deprecated**. You should be using
:class:`numpy.random.Generator`.

* randomgen's ``Generator`` continues to expose legacy
methods ``random_sample``, ``randint``, ``random_integers``, ``rand``, ``randn``,
and ``tomaxint``. **Note**: These should not be used, and their modern replacements are preferred:

* ``random_sample``, ``rand` → ``random``
* ``random_integers``, ``randint`` → ``integers``
* ``randn`` → ``standard_normal``
* ``tomaxint`` → ``integers`` with ``dtype`` set to ``int``

* randomgen's bit generators remain seedable and the convenience function
``seed` is exposed as part of``Generator``. Additionally, the convenience
property ``state`` is available to get or set the state of the underlying bit generator.

* :func:`numpy.random.Generator.multivariate_hypergeometric` was added after
``Generator`` was merged into NumPy and will not be ported over.

* :func:`numpy.random.Generator.shuffle` and :func:`numpy.random.Generator.permutation`
support ``axis`` keyword to operator along an axis other than 0.

* ``integers`` supports the keyword argument ``use_masked`` to switch between masked
generation of bounded integers and Lemire's superior method.

Differences from NumPy before 1.17
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* The normal, exponential and gamma generators use 256-step Ziggurat
methods which are 2-10 times faster than NumPy's default implementation in
``standard_normal``, ``standard_exponential`` or ``standard_gamma``.

* The Box-Muller used to produce NumPy's normals is no longer available.
* All bit generators functions to produce doubles, uint64s and
uint32s via CTypes (:meth:`~randomgen.xoroshiro128.Xoroshiro128.ctypes`)
and CFFI (:meth:`~randomgen.xoroshiro128.Xoroshiro128.cffi`). This allows
the bit generators to be used in numba or in other low-level applications
* The bit generators can be used in downstream projects via Cython.
* Optional ``dtype`` argument that accepts ``np.float32`` or ``np.float64``
to produce either single or double prevision uniform random variables for
select core distributions

* Uniforms (``random`` and ``rand``)
* Normals (``standard_normal`` and ``randn``)
* Standard Gammas (``standard_gamma``)
* Standard Exponentials (``standard_exponential``)

* Optional ``out`` argument that allows existing arrays to be filled for
select core distributions

* Uniforms (``random``)
* Normals (``standard_normal``)
* Standard Gammas (``standard_gamma``)
* Standard Exponentials (``standard_exponential``)

This allows multithreading to fill large arrays in chunks using suitable
PRNGs in parallel.


* ``integers`` supports broadcasting inputs.

* ``integers`` supports drawing from open (default, ``[low, high)``) or closed
(``[low, high]``) intervals using the keyword argument
``endpoint``. Closed intervals are simpler to use when the
distribution may include the maximum value of a given integer type.


* The closed interval is particularly helpful when using arrays since
it avoids object-dtype arrays when sampling from the full range.


* Support for Lemire’s method of generating uniform integers on an
arbitrary interval by setting ``use_masked=True`` in
(``integers``).


* ``multinomial`` supports multidimensional values of ``n``


* ``choice`` is much faster when sampling small amounts from large arrays


* ``choice`` supports the ``axis`` keyword to work with multidimensional arrays.


* For changes since the previous release, see the :ref:`change-log`

.. _the demonstration notebook: custom-bit-generators.ipynb
29 changes: 5 additions & 24 deletions doc/source/seed_sequence.rst
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
Seed Sequences
--------------

.. module:: randomgen._seed_sequence

.. currentmodule:: randomgen._seed_sequence

.. note::

randomgen imports ``SeedSequece`` from NumPy if available, and only falls back to a vendored
copy if not. The correct import location is ``randomgen.seed_sequence`` which handles to
selection of the correct ``SeedSequence``.

.. autoclass:: SeedSequence

Using a SeedSequence
====================

.. autosummary::
:toctree: generated/

~SeedSequence.generate_state
~SeedSequence.spawn

State
=====
randomgen imports :class:`~numpy.random.SeedSequence` from NumPy. As of version 2.0.0, randomgen does not provide
a vendored copy of ``SeedSequence``.

.. autosummary::
:toctree: generated/
.. deprecated:: 2.0.0

~SeedSequence.state
``SeedSequence`` is now available in NumPy. Use :class:`~numpy.random.SeedSequence`
instead. Importing ``SeedSequence`` from randomgen will be removed in a future version.
2 changes: 1 addition & 1 deletion randomgen/aes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cdef double aes_double(void* st) noexcept nogil:

cdef class AESCounter(BitGenerator):
"""
AESCounter(seed=None, *, counter=None, key=None, mode=<deprecated>)
AESCounter(seed=None, *, counter=None, key=None, mode="sequence")
Container for the AES Counter pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/chacha.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cdef double chacha_double(void* st) noexcept nogil:

cdef class ChaCha(BitGenerator):
"""
ChaCha(seed=None, *, counter=None, key=None, rounds=20, mode=<deprecated>)
ChaCha(seed=None, *, counter=None, key=None, rounds=20, mode="sequence")

Container for the ChaCha family of Counter pseudo-random number generators

Expand Down
2 changes: 1 addition & 1 deletion randomgen/dsfmt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cdef uint64_t dsfmt_raw(void *st) noexcept nogil:

cdef class DSFMT(BitGenerator):
"""
DSFMT(seed=None, *, mode=<deprecated>)
DSFMT(seed=None, *, mode="sequence")

Container for the SIMD-based Mersenne Twister pseudo RNG.

Expand Down
2 changes: 1 addition & 1 deletion randomgen/generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ cdef class ExtendedGenerator:
Returns
-------
out : integer or ndarray
out : int or ndarray
Drawn samples.
Notes
Expand Down
2 changes: 1 addition & 1 deletion randomgen/hc128.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef double hc128_double(void* st) noexcept nogil:

cdef class HC128(BitGenerator):
"""
HC128(seed=None, *, key=None, mode=<deprecated>)
HC128(seed=None, *, key=None, mode="sequence")

Container for the HC-128 cipher-based pseudo-random number generator

Expand Down
2 changes: 1 addition & 1 deletion randomgen/jsf.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cdef uint64_t jsf32_raw(void* st) noexcept nogil:

cdef class JSF(BitGenerator):
"""
JSF(seed=None, *, seed_size=1, size=64, p=None, q=None, r=None, mode=<deprecated>)
JSF(seed=None, *, seed_size=1, size=64, p=None, q=None, r=None, mode="sequence")

Container for Jenkins's Fast Small (JSF) pseudo-random number generator

Expand Down
2 changes: 1 addition & 1 deletion randomgen/mt19937.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cdef uint64_t mt19937_raw(void *st) noexcept nogil:

cdef class MT19937(BitGenerator):
"""
MT19937(seed=None, *, numpy_seed=False, mode=_DeprecatedValue)
MT19937(seed=None, *, numpy_seed=False, mode="sequence")

Container for the Mersenne Twister pseudo-random number generator.

Expand Down
2 changes: 1 addition & 1 deletion randomgen/mt64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cdef uint64_t mt64_raw(void *st) noexcept nogil:

cdef class MT64(BitGenerator):
"""
MT64(seed=None, *, mode=<deprecated>)
MT64(seed=None, *, mode="sequence")

Container for the 64-bit Mersenne Twister pseudo-random number generator

Expand Down
2 changes: 1 addition & 1 deletion randomgen/pcg32.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cdef uint64_t pcg32_raw(void* st) noexcept nogil:

cdef class PCG32(BitGenerator):
"""
PCG32(seed=None, inc=0, *, mode=<deprecates>)
PCG32(seed=None, inc=0, *, mode="sequence")

Container for the PCG-32 pseudo-random number generator.

Expand Down
2 changes: 1 addition & 1 deletion randomgen/pcg64.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cdef double lcg128mix_double(void* st) noexcept nogil:

cdef class PCG64(BitGenerator):
"""
PCG64(seed=None, inc=0, *, variant="xsl-rr", numpy_seed=False, mode=_DeprecatedValue)
PCG64(seed=None, inc=0, *, variant="xsl-rr", numpy_seed=False, mode="sequence")
Container for the PCG-64 pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/philox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cdef uint64_t philox2x32_raw(void *st) noexcept nogil:

cdef class Philox(BitGenerator):
"""
Philox(seed=None, *, counter=None, key=None, number=4, width=64, *, numpy_seed=False, mode=_DeprecatedValue)
Philox(seed=None, *, counter=None, key=None, number=4, width=64, numpy_seed=False, mode="sequence")

Container for the Philox family of pseudo-random number generators.

Expand Down
2 changes: 1 addition & 1 deletion randomgen/sfc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cdef uint64_t choosek(uint64_t k):

cdef class SFC64(BitGenerator):
"""
SFC64(seed=None, w=1, k=1, *, numpy_seed=False, mode=_DeprecatedValue)
SFC64(seed=None, w=1, k=1, *, numpy_seed=False, mode="sequence")
Chris Doty-Humphrey's Small Fast Chaotic PRNG with optional Weyl Sequence
Expand Down
2 changes: 1 addition & 1 deletion randomgen/sfmt.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cdef double sfmt_double(void* st) noexcept nogil:

cdef class SFMT(BitGenerator):
"""
SFMT(seed=None, *, mode=<deprecated>)
SFMT(seed=None, *, mode="sequence")
Container for the SIMD-based Mersenne Twister pseudo RNG.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/speck128.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cdef double speck_double(void* st) noexcept nogil:

cdef class SPECK128(BitGenerator):
"""
SPECK128(seed=None, *, counter=None, key=None, rounds=34, mode=<deprecated>)
SPECK128(seed=None, *, counter=None, key=None, rounds=34, mode="sequence")
Container for the SPECK (128 x 256) pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/threefry.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cdef uint64_t threefry2x32_raw(void *st) noexcept nogil:

cdef class ThreeFry(BitGenerator):
"""
ThreeFry(seed=None, *, counter=None, key=None, number=4, width=64, mode=<deprecated>)
ThreeFry(seed=None, *, counter=None, key=None, number=4, width=64, mode="sequence")

Container for the ThreeFry family of pseudo-random number generators.

Expand Down
2 changes: 1 addition & 1 deletion randomgen/xoroshiro128.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cdef double xoroshiro128plusplus_double(void* st) noexcept nogil:

cdef class Xoroshiro128(BitGenerator):
"""
Xoroshiro128(seed=None, *, plusplus=False, mode=<deprecated>)
Xoroshiro128(seed=None, *, plusplus=False, mode="sequence")
Container for the xoroshiro128+/++ pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/xorshift1024.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef double xorshift1024_double(void* st) noexcept nogil:

cdef class Xorshift1024(BitGenerator):
"""
Xorshift1024(seed=None, *, mode=<deprecated>)
Xorshift1024(seed=None, *, mode="sequence")
Container for the xorshift1024*φ pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/xoshiro256.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef double xoshiro256_double(void* st) noexcept nogil:

cdef class Xoshiro256(BitGenerator):
"""
Xoshiro256(seed=None, *, mode=<deprecated>)
Xoshiro256(seed=None, *, mode="sequence")
Container for the xoshiro256** pseudo-random number generator.
Expand Down
2 changes: 1 addition & 1 deletion randomgen/xoshiro512.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cdef double xoshiro512_double(void* st) noexcept nogil:

cdef class Xoshiro512(BitGenerator):
"""
Xoshiro512(seed=None, *, mode=<deprecated>)
Xoshiro512(seed=None, *, mode="sequence")
Container for the xoshiro512** pseudo-random number generator.
Expand Down

0 comments on commit 6f3d711

Please sign in to comment.