mkl_random -- a NumPy-based Python interface to Intel® oneAPI Math Kernel Library (OneMKL) Random Number Generation functionality
mkl_random started as a part of Intel® Distribution for Python optimizations to NumPy.
Per NumPy's community suggestions, voiced in https://github.com/numpy/numpy/pull/8209, it is being released as a stand-alone package.
Prebuilt mkl_random can be installed into conda environment from Intel's channel using:
conda install -c https://software.repos.intel.com/python/conda mkl_random
or from conda forge channel:
conda install -c conda-forge mkl_random
To install mkl_random PyPI package please use following command:
python -m pip install -i https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_random
If command above installs NumPy package from the Pypi, please use following command to install Intel optimized NumPy wheel package from Intel Pypi Cloud:
python -m pip install -i https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_random numpy==<numpy_version>
Where <numpy_version> should be the latest version from https://software.repos.intel.com/python/conda/
mkl_random is not fixed-seed backward compatible drop-in replacement for numpy.random, meaning that it implements sampling from the same distributions as numpy.random.
For distributions directly supported in Intel® OneMKL, method keyword is supported:
mkl_random.standard_normal(size=(10**5, 10**3), method='BoxMuller')
Additionally, mkl_random exposes different basic random number generation algorithms available in MKL. For example to use SFMT19937 use
mkl_random.RandomState(77777, brng='SFMT19937')
For generator families, such that MT2203 and Wichmann-Hill, a particular member of the family can be chosen by specifying brng=('WH', 3), etc.
The list of supported by mkl_random.RandomState constructor brng keywords is as follows:
- 'MT19937'
- 'SFMT19937'
- 'WH' or ('WH', id)
- 'MT2203' or ('MT2203', id)
- 'MCG31'
- 'R250'
- 'MRG32K3A'
- 'MCG59'
- 'PHILOX4X32X10'
- 'NONDETERM'
- 'ARS5'
Patching Mechanisms
mkl_random provides convenient patch methods to enable MKL-accelerated
random operations in NumPy with or without modifying your code.
CLI Quickstart
Persistent patch (all Python sessions)
# Install
python -m mkl_random --patch install
# Status (exit code: 0 = installed, 1 = not installed)
python -m mkl_random --patch status
# Remove
python -m mkl_random --patch uninstall
Verify current random backend
python -c "import numpy; print(f'numpy.random.normal.__module__: {numpy.random.normal.__module__}')"
One-shot patch (single command only)
# Script
python -m mkl_random --with-numpy-patch my_script.py
# Pytest
python -m mkl_random --with-numpy-patch -m pytest tests/
# One-liner
python -m mkl_random --with-numpy-patch -c "import numpy; print(f\"numpy.random.normal.__module__: {numpy.random.normal.__module__}\")"
# Non-Python command
python -m mkl_random --with-numpy-patch -- <command> [args...]
Programmatic Quickstart
import mkl_random
import numpy
mkl_random.patch_numpy_random()
print(mkl_random.is_patched())
# run your accelerated numpy workloads here!
mkl_random.restore_numpy_random()
import mkl_random
import numpy
with mkl_random.mkl_random():
# run your accelerated workloads here!
pass
Building from source
A C++ compiler, Intel® oneAPI Math Kernel Library (oneMKL), and NumPy are required
to build mkl_random from source.
Executing
python -m pip install .
will pull in the required build dependencies, including mkl and numpy, and build mkl_random.
If you already have mkl and numpy installed (from your system or a conda environment)
and want to reuse them instead of pulling fresh copies into an isolated build, first
install the build dependencies:
pip install meson-python cmake ninja cython numpy mkl-devel
then build against the existing installation with:
python -m pip install --no-build-isolation --no-deps .
Metadata
Release files for mkl-random 1.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 3.6 MB
Release files / mkl_random-1.5.0-0-cp314-cp314-win_amd64.whl
| Download URL | mkl_random-1.5.0-0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 309.2 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
04311a6238454a4206a3966449d44484efce6ac40a2ed6457f20896c5d2b9373
|
|
BLAKE2b-256 checksum How to use checksums |
c7f1addce66df856ea250598e9200993e0a83ad6fd0b7e3645f07e260156322b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | mkl_random-1.5.0-0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 399.6 kB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
fa3966ab9145326abb0de98174bb6de1ae941490b3681f6a51f9637c7f26a5a4
|
|
BLAKE2b-256 checksum How to use checksums |
88d766d090dadbc8ab4b2f75b3199630ef312116d2daf5c30ad14781e853675c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp313-cp313-win_amd64.whl
| Download URL | mkl_random-1.5.0-0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 311.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2d883acb4543fdb20fc8ab8fe5a36e7d1995e1411f4f1aa3304b3637ec508f9b
|
|
BLAKE2b-256 checksum How to use checksums |
f5484de0fe05a11b06b158965b6e24c229bbe56ef2bffad4dfe8ecc08a0aacd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | mkl_random-1.5.0-0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 397.2 kB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
bd0a0ce0a6ffb6a9c70d1222e198201df67e0f653ffc0d9f1aa84a3be76c6f24
|
|
BLAKE2b-256 checksum How to use checksums |
a17207bf2a0031b3999be16fb7489c8b36af8f3c225fee0264bdf5b4f7fa8afa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp312-cp312-win_amd64.whl
| Download URL | mkl_random-1.5.0-0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 309.6 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e988feb46c6b6866af07234b805ca5ee706961d334d9e6617c6f7c9371e0f0f3
|
|
BLAKE2b-256 checksum How to use checksums |
d3446867dcbc8e74cc87128eb2eb02e72e4258a752efa4b151920b382ec2d53c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | mkl_random-1.5.0-0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 395.3 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b883aeebccc4549590d3cbdd23f7276bea188cf431d115504a341b32e5d258b2
|
|
BLAKE2b-256 checksum How to use checksums |
d5fac96afffc42b328d9a72e495099e018d9b02f6d5cac2f35b120f0f034a0b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp311-cp311-win_amd64.whl
| Download URL | mkl_random-1.5.0-0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 327.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
72b6625b70c745094d01cd774a6ea738bf39906a9a3ec617130d566f8708818b
|
|
BLAKE2b-256 checksum How to use checksums |
9633d86ad171f1a40f0d1031dcea5ad1a614e072c055d7c1f558ad211c6981a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | mkl_random-1.5.0-0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 401.4 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
eec40130df69032c543522be0213a9320779b9b5e29c5fe0112529db81b1bd68
|
|
BLAKE2b-256 checksum How to use checksums |
ddfe93ed089e5930913c7fde507d32e52ad0f3739703824c39b9847ba1995b58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp310-cp310-win_amd64.whl
| Download URL | mkl_random-1.5.0-0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 328.1 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
41b9c1efee1a087bb01cfce964794a16db6d365b683027b918b6851ee9683f0e
|
|
BLAKE2b-256 checksum How to use checksums |
65f98e169234b470f6a7c3a564e2de8f4a79b7de327d69346ef5211aae3465e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_random-1.5.0-0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | mkl_random-1.5.0-0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 402.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1f2a49d6ea1dd4fec2d1aa8767a198e81d1061cdab2f197a921df639b9ff4a91
|
|
BLAKE2b-256 checksum How to use checksums |
bac43c9f7a477941fb4a21da9738ff7836abed21f2c94d035a273da04eac9b6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|