Skip to content

Releases

1.6.0

Choose a tag to compare

@vlad-perevezentsev vlad-perevezentsev released this 21 Oct 11:50
cf9e37d

Overview

This release enables free-threaded (GIL-disabled) CPython builds and adds support for Python 3.15. randint and randint_untyped now accept array-like low/high bounds, as NumPy's RandomState.randint does, and sampling with array-valued distribution parameters and several randint paths is much faster. It also fixes a group of correctness bugs where mkl_random returned uninitialized memory as random values: for out-of-range brng values, for integer generation with WH, MCG31, R250 and MRG32K3A, for degenerate distribution parameters, and for very large requests. geometric now follows the NumPy convention. Several seeded streams change in this release, see Behavior Changes below. Building from source now requires a newer Cython.

Highlights

🧵 Free-Threaded CPython

  • The Cython extension is compiled with freethreading_compatible=True, so importing mkl_random no longer re-enables the GIL. The free-threaded configuration is built and tested in CI on 3.14t
  • Every MKLRandomState serializes access to its MKL stream under its own lock, so one generator can be shared between threads. The how-to guide has a new thread-safety section
  • Removed the python-gil constraint from the conda recipes that pinned mkl_random to GIL-enabled Python 3.14 builds

🐍 Python 3.15 Support

  • Added support for Python 3.15. The free-threaded 3.15t build is not provided yet, since conda-forge has no NumPy build for it

🎲 Array-Like Bounds in randint

  • randint accepts broadcastable low/high arrays, as numpy.random.RandomState.randint does, drawing each element with Lemire's method
  • randint_untyped reuses the randint implementation, so it gains the same array-like bounds and no longer raises OverflowError for bounds outside the C long range (e.g. 2**40 on Windows)

⚡ Performance

  • normal, uniform, exponential, laplace, gumbel, logistic, rayleigh and lognormal with array-valued parameters fill the whole request with one MKL call instead of one call per element
  • Faster randint for power-of-two ranges at or above INT_MAX, for bool, int8, uint8, int16 and uint16, and for array-like bounds
  • shuffle uses its memcpy fast path for multi-dimensional arrays whose first-axis items are contiguous
  • Integer generation with WH, MCG31, R250 and MRG32K3A uses less memory and is faster

🐛 Correctness Fixes

  • An out-of-range integer brng and MKLRandomState(seed, brng=None) no longer read past the generator table and fall back to MT19937; brng=0 now selects MT19937 instead of leaving the state unseeded
  • randint with scalar bounds above INT_MAX, tomaxint and bytes return random data for WH, MCG31, R250 and MRG32K3A, which lack viRngUniformBits support
  • poisson with lam == 0 and negative_binomial with p == 1 return zeros, and geometric rejects NaN, instead of returning the untouched output buffer
  • Very large outputs are now filled completely: integer fills larger than two MKL_INT_MAX chunks, multinomial, multinormal_cholesky when the number of samples times the dimension exceeds MKL_INT_MAX, and 64-bit integers with PHILOX4X32X10 and ARS5
  • randint no longer returns high for 64-bit dtypes when the range is at or above INT_MAX
  • Fixed memory leaks in set_state and logseries

🆕 Other Additions

  • The sampling method ids ICDF, BOXMULLER, BOXMULLER2, POISNORM and PTPE are exported from mkl_random, as the method docstrings already documented
  • Added an ASV benchmark suite under benchmarks/

⚠️ Behavior Changes

  • Seeded streams change for array-valued parameters of the eight distributions listed under Performance (scalar-parameter paths are unchanged), for power-of-two randint ranges at or above INT_MAX, for geometric, and for integer-like method ids such as np.int64(2), which now select the method they name instead of BoxMuller
  • geometric now counts trials, as its docstring and NumPy do: the support starts at 1 and the mean is 1 / p. Samples that fit in int32 are one larger than before, and geometric(p) - 1 gives the old values. The samples are still int32, unlike NumPy's int64
  • Unsupported method values now emit a UserWarning listing the supported methods before falling back to the default method
  • New ValueErrors: negative_binomial with p == 0; NaN parameters to poisson, negative_binomial, geometric and logseries; array-valued parameters of the eight distributions above that do not broadcast to size without adding dimensions; multinormal_cholesky with an empty mean, which used to raise ZeroDivisionError
  • uniform with scalar bounds and size=None returns a Python float instead of a 0-d array; with array-valued bounds it may return high due to floating-point rounding

📦 Build Requirement Changes

  • Minimum build-time Cython raised to 3.1.0 (first release providing the freethreading_compatible directive)

Python Version Support

  • ✅ Python 3.10, 3.11, 3.12, 3.13, 3.14, 3.15 (plus free-threaded 3.14t)

Detailed Changes

Added

  • Added support for array_like (broadcastable) low/high bounds in randint gh-168
  • Added support for free-threaded (GIL-disabled) CPython builds: the Cython extension is compiled with freethreading_compatible=True, so importing mkl_random no longer re-enables the GIL gh-159
  • Added a thread-safety section to the how-to guide for free-threaded Python gh-159
  • Added an ASV benchmark suite under benchmarks/ and a benchmark optional dependency group gh-184
  • Enabled support of Python 3.15 gh-188
  • Exported the sampling method ids ICDF, BOXMULLER, BOXMULLER2, POISNORM and PTPE from mkl_random, as the method docstrings already documented gh-189

Changed

  • Unsupported method values (e.g. a misspelled name, a method the function does not implement, None, bool, float) now emit a UserWarning listing the supported methods before falling back to the function's default method, instead of falling back silently gh-189
  • Sped up normal, uniform, exponential, laplace, gumbel, logistic, rayleigh and lognormal for array-valued parameters. Seeded results change for these array paths; scalar paths are unchanged gh-171
  • Array parameters for these distributions must broadcast to the requested size without adding dimensions; previously accepted mismatches now raise ValueError gh-171
  • uniform with array-valued bounds may return high due to floating-point rounding gh-171
  • Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added coverity/README.md documenting the known Cython-boilerplate false positives and the scan review checklist gh-164
  • Sped up randint for power-of-two ranges at or above INT_MAX gh-172
  • The random streams for power-of-two randint ranges at or above INT_MAX have changed: with a fixed seed these now produce different (but equally valid) samples gh-172
  • Sped up randint for bool, uint8, int8, uint16 and int16; generated values are unchanged gh-172
  • Raised the minimum build-time Cython requirement to 3.1.0, the first release providing the freethreading_compatible directive gh-159
  • Extended the memcpy-based fast path of shuffle to multi-dimensional ndarray inputs whose first-axis items are contiguous, which is also much faster than the previous buffered path gh-159
  • Updated the randint_untyped implementation, which now supports array_like (broadcastable) low/high bounds gh-176
  • Sped up randint with array_like bounds by generating words in cache-sized chunks and by picking the Lemire rejection test by range width gh-173
  • Reduced the memory use and sped up integer generation with WH, MCG31, R250 and MRG32K3A, which lack viRngUniformBits support gh-178
  • Replaced the mklrand_py_helper.h shim with cpython.bytes cimports and dropped the no-op __future__ import, since the project requires Python 3.10+ gh-192
  • negative_binomial now rejects p == 0, which MKL does not support, with a ValueError; the documented range of p is (0, 1] gh-195
  • poisson, negative_binomial, geometric and logseries now reject NaN parameters with a ValueError, as NumPy does, instead of passing them to MKL gh-195
  • geometric samples are now one larger than before for every p whose result fits in int32, so results for a fixed seed change; geometric(p) - 1 reproduces the old values for them gh-196

Fixed

*...

Read more

1.5.0

Choose a tag to compare

@vlad-perevezentsev vlad-perevezentsev released this 13 Aug 14:19
cb12912

Overview

This release migrates mkl_random to a modern Meson-based build system, replacing the legacy setuptools/setup.py pipeline. It also introduces a command-line interface for patching NumPy's random with MKL-accelerated implementations, and adds compatibility with NumPy 2.5.

Highlights

🏗️ New Build System

  • Migrated from setuptools to meson-python, removing setup.py in favor of meson.build, aligning mkl_random with the build system used by NumPy and SciPy
  • MKL is now discovered via CMake, and ninja/cmake are formal build requirements

🆕 NumPy random patching CLI

  • Added python -m mkl_random --patch install/uninstall/status for persistent NumPy random patching across all Python sessions
  • Added python -m mkl_random --with-numpy-patch <command> for one-shot execution of a command with MKL-accelerated random

🔧 NumPy 2.5 compatibility

  • Updated mkl_random and its test suite to work with NumPy 2.5, replacing APIs deprecated upstream

Python Version Support

  • ✅ Python 3.10, 3.11, 3.12, 3.13, 3.14

Detailed Changes

Added

  • Added CLI patch management for NumPy random with persistent install/status/uninstall and one-shot command patching via python -m mkl_random --patch <command> and python -m mkl_random --with-numpy-patch <command> gh-133

Changed

  • Removed numpy-base dependency and USE_NUMPY_BASE environment variable from conda recipe gh-124
  • Migrated the build system from setuptools to meson-python, removing setup.py in favor of meson.build gh-113

Fixed

  • Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array shape assignment with reshape, and by replacing the deprecated numpy.testing.suppress_warnings usage in tests with pytest.warns gh-137
  • Fixed a constant integer overflow in irk_rand_uint32_vec by declaring the shift variable as npy_uint32 instead of npy_int32, so 2**31 no longer overflows a signed 32-bit integer (behavior is unchanged as all downstream uses rely on modulo-2^32 arithmetic) gh-156

Contributors

New Contributors

Full Changelog: 1.4.2...1.5.0

1.4.2

Choose a tag to compare

@antonwolfy antonwolfy released this 01 Jul 08:57
05eacad

Overview

This is a maintenance release focused on compatibility with newer NumPy and a more robust conda build. It restores a green test suite against NumPy 2.5, drops the numpy-base dependency from the conda recipe, and fixes the conda package workflow. There are no API changes — this release is functionally identical to 1.4.1 for end users.

Changed

  • Removed numpy-base dependency and USE_NUMPY_BASE environment variable from conda recipe gh-124

Fixed

  • Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array shape assignment with reshape, and by replacing the deprecated numpy.testing.suppress_warnings usage in tests with pytest.warns gh-137

Contributors

Full Changelog: 1.4.1...1.4.2

1.4.1

Choose a tag to compare

@ndgrigorian ndgrigorian released this 11 May 21:50
d2a6a2d

This release is identical to 1.4.0 in terms of features

This release only changes package metadata to remove mkl as a runtime dependency, preventing pip check failures when mkl_random is installed in an environment.

Fixed

  • Removed mkl as runtime dependency to avoid possible pip check failures gh-126

1.4.0

Choose a tag to compare

@antonwolfy antonwolfy released this 04 May 22:43
ecc4e3c

Overview

This release introduces NumPy compatibility through a new patching system and dedicated interface module. mkl_random can now seamlessly replace NumPy's random number generation while maintaining full API compatibility. The release includes extensive test coverage from NumPy's test suite, numerous bug fixes, and improvements to align with modern NumPy behavior. Python 3.9 support has been dropped.

Highlights

🔄 NumPy Patching System

  • New context manager and explicit patch/restore functions to replace numpy.random with mkl_random implementations
  • Query patching status with is_patched() function
  • Seamless drop-in replacement for NumPy's random number generation

🎯 Strict NumPy API Interface

  • New mkl_random.interfaces.numpy_random module provides pure NumPy-compatible API
  • Aliases mkl_random functionality while dropping non-standard arguments and functions
  • Better alignment with NumPy's API contracts

✅ Enhanced Test Coverage

  • Third-party tests from numpy.random integrated to validate compatibility
  • Additional vendored NumPy tests for comprehensive validation
  • Improved reliability and correctness

🐛 Bug Fixes & Improvements

  • Fixed hang in zipf when called with np.nan
  • Fixed size-1 1D arrays being incorrectly cast to scalars
  • Multiple implementation updates to align with newer NumPy versions

📦 Flexible Build Configuration

  • Conda recipe now supports configurable NumPy dependency via USE_NUMPY_BASE environment variable

⚠️ Breaking Changes

  • Python 3.9 support dropped - Minimum supported version is now Python 3.10+
  • mkl_random.RandomState deprecated - Use mkl_random.MKLRandomState instead. RandomState now delegates to the numpy_random interface for compatibility.

Python Version Support

  • ✅ Python 3.10, 3.11, 3.12, 3.13, 3.14
  • ❌ Python 3.9 and earlier

Detailed Changes

Added

  • Added mkl_random patching for NumPy, with mkl_random context manager, is_patched query, and patch_numpy_random and restore_numpy_random calls to replace numpy.random calls with calls from mkl_random.interfaces.numpy_random gh-90

  • Added mkl_random.interfaces with mkl_random.interfaces.numpy_random interface, which aliases mkl_random functionality to more strictly adhere to NumPy's API (i.e., drops arguments and functions which are not part of standard NumPy) gh-92

  • Added third-party tests from numpy.random which tests the mkl_random.interfaces.numpy_random interface gh-103

Changed

  • Updates to mkl_random implementations to better align with newer versions of numpy.random gh-103, gh-115
  • Made conda recipe dependency on numpy configurable through USE_NUMPY_BASE environment variable gh-105

Fixed

  • Various bugfixes including a hang in zipf when called with np.nan and size-1 1D arrays being cast to scalars gh-103, gh-115

Removed

  • Dropped support for Python 3.9 gh-81

Deprecated

  • Deprecated mkl_random.RandomState in favor of mkl_random.MKLRandomState, delegating mkl_random.RandomState to the mkl_random.interfaces.numpy_random interface gh-92

Contributors

New Contributors

Full Changelog: v1.3.1...v1.4.0

1.3.1

Choose a tag to compare

@ndgrigorian ndgrigorian released this 17 Dec 03:51
7573490

This release is identical to 1.3.0 in terms of features

This release only changes conda recipes and package metadata to release the mkl_random package with Python 3.14.

Added

  • Enabled support of Python 3.14 gh-79

v1.3.0

Choose a tag to compare

@antonwolfy antonwolfy released this 06 Oct 18:51
851daa2

What's Changed

  • Used GIT_DESCRIBE_TAG and GIT_DESCRIBE_NUMBER in meta.yaml instead of manual stepping the numbers gh-75
  • Extended conda build scripts with the use of WHEELS_OUTPUT_FOLDER variable to build wheel packages gh-74
  • Updated meta.yaml to have a run dependency on numpy-base package gh-73

Contributors

Full Changelog: v1.2.11...1.3.0

v1.2.10

Choose a tag to compare

@ndgrigorian ndgrigorian released this 09 Apr 21:20
9cab66c

This release

  • Adds support for mkl_random out-of-the-box from virtual environment on Windows

v1.2.8

Choose a tag to compare

@oleksandr-pavlyk oleksandr-pavlyk released this 12 Oct 00:48
0df7d04

Incremental bug fix release: updated installation instructions, reverted work-around for a problem in MKL 2024.2.0

v1.2.7

Choose a tag to compare

@oleksandr-pavlyk oleksandr-pavlyk released this 05 Aug 11:22
e1ed130

This release addresses technical debt, and fixes the project to work with NumPy 2.0 on both Windows and Linux.

  • Removed use of vendored numpy.pxd, replaced with recommended cimport numpy. This resolved the warning of changes struct size for Cython class broadcast.
  • Fixed warnings from clang compiler
  • Corrected data types for allocation made in Cython which were responsible for test failures with NumPy 2.0 on Windows.