Repository navigation
Releases
1.6.0
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 importingmkl_randomno longer re-enables the GIL. The free-threaded configuration is built and tested in CI on 3.14t - Every
MKLRandomStateserializes 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-gilconstraint from the conda recipes that pinnedmkl_randomto 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
randintaccepts broadcastablelow/higharrays, asnumpy.random.RandomState.randintdoes, drawing each element with Lemire's methodrandint_untypedreuses therandintimplementation, so it gains the same array-like bounds and no longer raisesOverflowErrorfor bounds outside the Clongrange (e.g.2**40on Windows)
⚡ Performance
normal,uniform,exponential,laplace,gumbel,logistic,rayleighandlognormalwith array-valued parameters fill the whole request with one MKL call instead of one call per element- Faster
randintfor power-of-two ranges at or aboveINT_MAX, forbool,int8,uint8,int16anduint16, and for array-like bounds shuffleuses itsmemcpyfast path for multi-dimensional arrays whose first-axis items are contiguous- Integer generation with
WH,MCG31,R250andMRG32K3Auses less memory and is faster
🐛 Correctness Fixes
- An out-of-range integer
brngandMKLRandomState(seed, brng=None)no longer read past the generator table and fall back toMT19937;brng=0now selectsMT19937instead of leaving the state unseeded randintwith scalar bounds aboveINT_MAX,tomaxintandbytesreturn random data forWH,MCG31,R250andMRG32K3A, which lackviRngUniformBitssupportpoissonwithlam == 0andnegative_binomialwithp == 1return zeros, andgeometricrejectsNaN, instead of returning the untouched output buffer- Very large outputs are now filled completely: integer fills larger than two
MKL_INT_MAXchunks,multinomial,multinormal_choleskywhen the number of samples times the dimension exceedsMKL_INT_MAX, and 64-bit integers withPHILOX4X32X10andARS5 randintno longer returnshighfor 64-bit dtypes when the range is at or aboveINT_MAX- Fixed memory leaks in
set_stateandlogseries
🆕 Other Additions
- The sampling method ids
ICDF,BOXMULLER,BOXMULLER2,POISNORMandPTPEare exported frommkl_random, as themethoddocstrings already documented - Added an ASV benchmark suite under
benchmarks/
- Seeded streams change for array-valued parameters of the eight distributions listed under Performance (scalar-parameter paths are unchanged), for power-of-two
randintranges at or aboveINT_MAX, forgeometric, and for integer-likemethodids such asnp.int64(2), which now select the method they name instead ofBoxMuller geometricnow counts trials, as its docstring and NumPy do: the support starts at1and the mean is1 / p. Samples that fit inint32are one larger than before, andgeometric(p) - 1gives the old values. The samples are stillint32, unlike NumPy'sint64- Unsupported
methodvalues now emit aUserWarninglisting the supported methods before falling back to the default method - New
ValueErrors:negative_binomialwithp == 0;NaNparameters topoisson,negative_binomial,geometricandlogseries; array-valued parameters of the eight distributions above that do not broadcast tosizewithout adding dimensions;multinormal_choleskywith an emptymean, which used to raiseZeroDivisionError uniformwith scalar bounds andsize=Nonereturns a Pythonfloatinstead of a 0-d array; with array-valued bounds it may returnhighdue to floating-point rounding
📦 Build Requirement Changes
- Minimum build-time
Cythonraised to3.1.0(first release providing thefreethreading_compatibledirective)
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/highbounds inrandintgh-168 - Added support for free-threaded (GIL-disabled) CPython builds: the Cython extension is compiled with
freethreading_compatible=True, so importingmkl_randomno 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 abenchmarkoptional dependency group gh-184 - Enabled support of Python 3.15 gh-188
- Exported the sampling method ids
ICDF,BOXMULLER,BOXMULLER2,POISNORMandPTPEfrommkl_random, as themethoddocstrings already documented gh-189
Changed
- Unsupported
methodvalues (e.g. a misspelled name, a method the function does not implement,None,bool,float) now emit aUserWarninglisting 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,rayleighandlognormalfor 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
sizewithout adding dimensions; previously accepted mismatches now raiseValueErrorgh-171 uniformwith array-valued bounds may returnhighdue to floating-point rounding gh-171- Pinned Cython in the Coverity Scan workflow so generated code stays stable between scans, and added
coverity/README.mddocumenting the known Cython-boilerplate false positives and the scan review checklist gh-164 - Sped up
randintfor power-of-two ranges at or aboveINT_MAXgh-172 - The random streams for power-of-two
randintranges at or aboveINT_MAXhave changed: with a fixed seed these now produce different (but equally valid) samples gh-172 - Sped up
randintforbool,uint8,int8,uint16andint16; generated values are unchanged gh-172 - Raised the minimum build-time
Cythonrequirement to3.1.0, the first release providing thefreethreading_compatibledirective gh-159 - Extended the
memcpy-based fast path ofshuffleto multi-dimensionalndarrayinputs whose first-axis items are contiguous, which is also much faster than the previous buffered path gh-159 - Updated the
randint_untypedimplementation, which now supportsarray_like(broadcastable)low/highbounds gh-176 - Sped up
randintwitharray_likebounds 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,R250andMRG32K3A, which lackviRngUniformBitssupport gh-178 - Replaced the
mklrand_py_helper.hshim withcpython.bytescimports and dropped the no-op__future__import, since the project requires Python 3.10+ gh-192 negative_binomialnow rejectsp == 0, which MKL does not support, with aValueError; the documented range ofpis(0, 1]gh-195poisson,negative_binomial,geometricandlogseriesnow rejectNaNparameters with aValueError, as NumPy does, instead of passing them to MKL gh-195geometricsamples are now one larger than before for everypwhose result fits inint32, so results for a fixed seed change;geometric(p) - 1reproduces the old values for them gh-196
Fixed
*...
1.5.0
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
setuptoolstomeson-python, removingsetup.pyin favor ofmeson.build, aligningmkl_randomwith the build system used by NumPy and SciPy - MKL is now discovered via CMake, and
ninja/cmakeare formal build requirements
🆕 NumPy random patching CLI
- Added
python -m mkl_random --patch install/uninstall/statusfor 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_randomand 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>andpython -m mkl_random --with-numpy-patch <command>gh-133
Changed
- Removed
numpy-basedependency andUSE_NUMPY_BASEenvironment variable from conda recipe gh-124 - Migrated the build system from
setuptoolstomeson-python, removingsetup.pyin favor ofmeson.buildgh-113
Fixed
- Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array
shapeassignment withreshape, and by replacing the deprecatednumpy.testing.suppress_warningsusage in tests withpytest.warnsgh-137 - Fixed a constant integer overflow in
irk_rand_uint32_vecby declaring theshiftvariable asnpy_uint32instead ofnpy_int32, so2**31no longer overflows a signed 32-bit integer (behavior is unchanged as all downstream uses rely on modulo-2^32 arithmetic) gh-156
Contributors
- Nikita Grigorian (@ndgrigorian)
- Anton Volkov (@antonwolfy)
- Jordan Harlow (@jharlow-intel)
New Contributors
- Vladislav Perevezentsev (@vlad-perevezentsev)
Full Changelog: 1.4.2...1.5.0
1.4.2
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-basedependency andUSE_NUMPY_BASEenvironment variable from conda recipe gh-124
Fixed
- Fixed compatibility with NumPy 2.5 by replacing the deprecated in-place array
shapeassignment withreshape, and by replacing the deprecatednumpy.testing.suppress_warningsusage in tests withpytest.warnsgh-137
Contributors
- Anton Volkov (@antonwolfy)
- Jordan Harlow (@jharlow-intel)
- Nikita Grigorian (@ndgrigorian)
Full Changelog: 1.4.1...1.4.2
1.4.1
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
mklas runtime dependency to avoid possiblepip checkfailures gh-126
1.4.0
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.randomwithmkl_randomimplementations - 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_randommodule 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.randomintegrated to validate compatibility - Additional vendored NumPy tests for comprehensive validation
- Improved reliability and correctness
🐛 Bug Fixes & Improvements
- Fixed hang in
zipfwhen called withnp.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_BASEenvironment variable
- Python 3.9 support dropped - Minimum supported version is now Python 3.10+
mkl_random.RandomStatedeprecated - Usemkl_random.MKLRandomStateinstead.RandomStatenow delegates to thenumpy_randominterface 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_randompatching for NumPy, withmkl_randomcontext manager,is_patchedquery, andpatch_numpy_randomandrestore_numpy_randomcalls to replacenumpy.randomcalls with calls frommkl_random.interfaces.numpy_randomgh-90 -
Added
mkl_random.interfaceswithmkl_random.interfaces.numpy_randominterface, which aliasesmkl_randomfunctionality 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.randomwhich tests themkl_random.interfaces.numpy_randominterface gh-103
Changed
- Updates to
mkl_randomimplementations to better align with newer versions ofnumpy.randomgh-103, gh-115 - Made conda recipe dependency on numpy configurable through
USE_NUMPY_BASEenvironment variable gh-105
Fixed
- Various bugfixes including a hang in
zipfwhen called withnp.nanand 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.RandomStatein favor ofmkl_random.MKLRandomState, delegatingmkl_random.RandomStateto themkl_random.interfaces.numpy_randominterface gh-92
Contributors
- Anton Volkov (@antonwolfy)
- Nikita Grigorian (@ndgrigorian)
New Contributors
- Jordan Harlow (@jharlow-intel)
Full Changelog: v1.3.1...v1.4.0
1.3.1
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
What's Changed
- Used
GIT_DESCRIBE_TAGandGIT_DESCRIBE_NUMBERinmeta.yamlinstead of manual stepping the numbers gh-75 - Extended conda build scripts with the use of
WHEELS_OUTPUT_FOLDERvariable to build wheel packages gh-74 - Updated
meta.yamlto have a run dependency onnumpy-basepackage gh-73
Contributors
Full Changelog: v1.2.11...1.3.0
v1.2.10
This release
- Adds support for
mkl_randomout-of-the-box from virtual environment on Windows
v1.2.8
Incremental bug fix release: updated installation instructions, reverted work-around for a problem in MKL 2024.2.0
v1.2.7
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 recommendedcimport numpy. This resolved the warning of changes struct size for Cython classbroadcast. - Fixed warnings from
clangcompiler - Corrected data types for allocation made in Cython which were responsible for test failures with NumPy 2.0 on Windows.