Skip to content

Commit a949a2c

Browse files
authored
Merge pull request #92 from IntelPython/feature/add-numpy-random-interface
Implement `mkl_random.interfaces` and update `mkl_random`
2 parents 80210c5 + 33176a2 commit a949a2c

File tree

12 files changed

+1744
-613
lines changed

12 files changed

+1744
-613
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
2+
3+
# Sporadic fixes in test_random.py
4+
e76aa3a5a4b889c0434f0103ec102a50b93ab1ca

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [dev] (MM/DD/YYYY)
88

9+
### Added
10+
* 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](https://github.com/IntelPython/mkl_random/pull/92)
11+
912
### Removed
1013
* Dropped support for Python 3.9 [gh-81](https://github.com/IntelPython/mkl_random/pull/81)
1114

15+
### Deprecated
16+
* Deprecated `mkl_random.RandomState` in favor of `mkl_random.MKLRandomState`, delegating `mkl_random.RandomState` to the `mkl_random.interfaces.numpy_random` interface [gh-92](https://github.com/IntelPython/mkl_random/pull/92)
17+
1218
## [1.3.1] (12/02/2025)
1319

1420
### Added

mkl_random/__init__.py

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without
@@ -28,7 +27,58 @@
2827

2928
from . import _init_helper
3029

31-
from .mklrand import *
30+
from .mklrand import (
31+
MKLRandomState,
32+
RandomState,
33+
seed,
34+
get_state,
35+
set_state,
36+
random_sample,
37+
choice,
38+
randint,
39+
bytes,
40+
uniform,
41+
rand,
42+
randn,
43+
random_integers,
44+
standard_normal,
45+
normal,
46+
beta,
47+
exponential,
48+
standard_exponential,
49+
standard_gamma,
50+
gamma,
51+
f,
52+
noncentral_f,
53+
chisquare,
54+
noncentral_chisquare,
55+
standard_cauchy,
56+
standard_t,
57+
vonmises,
58+
pareto,
59+
weibull,
60+
power,
61+
laplace,
62+
gumbel,
63+
logistic,
64+
lognormal,
65+
rayleigh,
66+
wald,
67+
triangular,
68+
binomial,
69+
negative_binomial,
70+
poisson,
71+
zipf,
72+
geometric,
73+
hypergeometric,
74+
logseries,
75+
multivariate_normal,
76+
multinormal_cholesky,
77+
multinomial,
78+
dirichlet,
79+
shuffle,
80+
permutation,
81+
)
3282
from ._version import __version__
3383

3484
try:
@@ -42,4 +92,60 @@
4292
test = PytestTester(__name__)
4393
del PytestTester
4494

95+
from mkl_random import interfaces
96+
97+
__all__ = [
98+
"MKLRandomState",
99+
"RandomState",
100+
"seed",
101+
"get_state",
102+
"set_state",
103+
"random_sample",
104+
"choice",
105+
"randint",
106+
"bytes",
107+
"uniform",
108+
"rand",
109+
"randn",
110+
"random_integers",
111+
"standard_normal",
112+
"normal",
113+
"beta",
114+
"exponential",
115+
"standard_exponential",
116+
"standard_gamma",
117+
"gamma",
118+
"f",
119+
"noncentral_f",
120+
"chisquare",
121+
"noncentral_chisquare",
122+
"standard_cauchy",
123+
"standard_t",
124+
"vonmises",
125+
"pareto",
126+
"weibull",
127+
"power",
128+
"laplace",
129+
"gumbel",
130+
"logistic",
131+
"lognormal",
132+
"rayleigh",
133+
"wald",
134+
"triangular",
135+
"binomial",
136+
"negative_binomial",
137+
"poisson",
138+
"zipf",
139+
"geometric",
140+
"hypergeometric",
141+
"logseries",
142+
"multivariate_normal",
143+
"multinormal_cholesky",
144+
"multinomial",
145+
"dirichlet",
146+
"shuffle",
147+
"permutation",
148+
"interfaces",
149+
]
150+
45151
del _init_helper

mkl_random/interfaces/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Interfaces
2+
The `mkl_random` package provides interfaces that serve as drop-in replacements for equivalent functions in NumPy.
3+
4+
---
5+
6+
## NumPy interface - `mkl_random.interfaces.numpy_random`
7+
8+
This interface is a drop-in replacement for the legacy portion of the [`numpy.random`](https://numpy.org/devdocs/reference/random/legacy.html) module and includes **all** classes and functions available there:
9+
10+
* random generator: `RandomState`.
11+
12+
* seeding and state functions: `get_state`, `set_state`, and `seed`.
13+
14+
* simple random data: `rand`, `randn`, `randint`, `random_integers`, `random_sample`, `choice` and `bytes`.
15+
16+
* permutations: `shuffle` and `permutation`
17+
18+
* distributions: `beta`, `binomial`, `chisquare`, `dirichlet`, `exponential`, `f`, `gamma`, `geometric`, `gumbel`, `hypergeometric`, `laplace`, `logistic`, `lognormal`, `logseries`, `multinomial`, `multivariate_normal`, `negative_binomial`, `noncentral_chisquare`, `noncentral_f`, `normal`, `pareto`, `poisson`, `power`, `rayleigh`, `standard_cauchy`, `standard_exponential`, `standard_gamma`, `standard_normal`, `standard_t`, `triangular`, `uniform`, `vonmises`, `wald`, `weibull`, and `zipf`.

mkl_random/interfaces/__init__.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) 2017, Intel Corporation
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright notice,
7+
# this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of Intel Corporation nor the names of its contributors
12+
# may be used to endorse or promote products derived from this software
13+
# without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
26+
from . import numpy_random
27+
28+
# submodules
29+
__all__ = ["numpy_random"]

0 commit comments

Comments
 (0)