Skip to content

Commit d26d763

Browse files
committed
add documentation for patching utilities and interfaces
1 parent baa6746 commit d26d763

File tree

4 files changed

+145
-1
lines changed

4 files changed

+145
-1
lines changed

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Intel(R) oneAPI Math Kernel Library
3939

4040
.. grid-item-card:: Reference Guide
4141

42-
The reference guide contains a detailed description of class :class:`mkl_random.RandomState` and its methods.
42+
The reference guide contains a detailed description of class :class:`mkl_random.MKLRandomState`,
43+
the :ref:`interfaces <interfaces>` submodule, and :ref:`NumPy patching <patching>` utilities.
4344

4445
+++
4546

docs/source/reference/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ Class RandomState
55

66
.. autoclass:: mkl_random.RandomState
77
:members:
8+
9+
Class MKLRandomState
10+
====================
11+
12+
.. autoclass:: mkl_random.MKLRandomState
13+
:members:
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
.. _interfaces:
2+
3+
:mod:`mkl_random.interfaces`
4+
====================================================
5+
6+
:mod:`mkl_random.interfaces` provides drop-in replacements for supported random number generation
7+
modules using :mod:`mkl_random` implementations. Currently, only a NumPy interface is provided,
8+
but more may be added in the future.
9+
10+
11+
.. _numpy_random_interface:
12+
13+
NumPy interface --- :mod:`mkl_random.interfaces.numpy_random`
14+
-------------------------------------------------------------
15+
16+
:mod:`mkl_random.interfaces.numpy_random` is a drop-in replacement for the legacy portion of
17+
:mod:`numpy.random`.
18+
19+
.. note::
20+
While the API is the same, :mod:`mkl_random.interfaces.numpy_random` is **not** seed-compatible
21+
with :mod:`numpy.random`. Given the same seed, the two modules will produce different sequences.
22+
The output of `get_state` and accepted input to `set_state` may also differ. It is not
23+
recommended to provide the output of `get_state` from one module to `set_state` of the other.
24+
There also may be differences in some edge cases, such as behavior of functions when given specific inputs.
25+
26+
27+
RandomState class
28+
^^^^^^^^^^^^^^^^^
29+
30+
.. autoclass:: mkl_random.interfaces.numpy_random.RandomState
31+
:members:
32+
:undoc-members:
33+
34+
35+
Functions
36+
^^^^^^^^^^^^^^^^^^^^^^
37+
38+
**Seeding and state functions:**
39+
40+
.. autosummary::
41+
42+
mkl_random.interfaces.numpy_random.seed
43+
mkl_random.interfaces.numpy_random.get_state
44+
mkl_random.interfaces.numpy_random.set_state
45+
46+
**Simple random data:**
47+
48+
Similar to NumPy, the methods of :class:`RandomState` are exported as functions in the module.
49+
Their usage is discouraged, as they are implemented from a global instance of :class:`RandomState`,
50+
which means results may change across calls.
51+
52+
.. autosummary::
53+
54+
mkl_random.interfaces.numpy_random.rand
55+
mkl_random.interfaces.numpy_random.randn
56+
mkl_random.interfaces.numpy_random.randint
57+
mkl_random.interfaces.numpy_random.random_integers
58+
mkl_random.interfaces.numpy_random.random_sample
59+
mkl_random.interfaces.numpy_random.random
60+
mkl_random.interfaces.numpy_random.ranf
61+
mkl_random.interfaces.numpy_random.choice
62+
mkl_random.interfaces.numpy_random.bytes
63+
mkl_random.interfaces.numpy_random.sample
64+
65+
**Permutations:**
66+
67+
.. autosummary::
68+
69+
mkl_random.interfaces.numpy_random.shuffle
70+
mkl_random.interfaces.numpy_random.permutation
71+
72+
**Distributions:**
73+
74+
.. autosummary::
75+
76+
mkl_random.interfaces.numpy_random.beta
77+
mkl_random.interfaces.numpy_random.binomial
78+
mkl_random.interfaces.numpy_random.chisquare
79+
mkl_random.interfaces.numpy_random.dirichlet
80+
mkl_random.interfaces.numpy_random.exponential
81+
mkl_random.interfaces.numpy_random.f
82+
mkl_random.interfaces.numpy_random.gamma
83+
mkl_random.interfaces.numpy_random.geometric
84+
mkl_random.interfaces.numpy_random.gumbel
85+
mkl_random.interfaces.numpy_random.hypergeometric
86+
mkl_random.interfaces.numpy_random.laplace
87+
mkl_random.interfaces.numpy_random.logistic
88+
mkl_random.interfaces.numpy_random.lognormal
89+
mkl_random.interfaces.numpy_random.logseries
90+
mkl_random.interfaces.numpy_random.multinomial
91+
mkl_random.interfaces.numpy_random.multivariate_normal
92+
mkl_random.interfaces.numpy_random.negative_binomial
93+
mkl_random.interfaces.numpy_random.noncentral_chisquare
94+
mkl_random.interfaces.numpy_random.noncentral_f
95+
mkl_random.interfaces.numpy_random.normal
96+
mkl_random.interfaces.numpy_random.pareto
97+
mkl_random.interfaces.numpy_random.poisson
98+
mkl_random.interfaces.numpy_random.power
99+
mkl_random.interfaces.numpy_random.rayleigh
100+
mkl_random.interfaces.numpy_random.standard_cauchy
101+
mkl_random.interfaces.numpy_random.standard_exponential
102+
mkl_random.interfaces.numpy_random.standard_gamma
103+
mkl_random.interfaces.numpy_random.standard_normal
104+
mkl_random.interfaces.numpy_random.standard_t
105+
mkl_random.interfaces.numpy_random.triangular
106+
mkl_random.interfaces.numpy_random.uniform
107+
mkl_random.interfaces.numpy_random.vonmises
108+
mkl_random.interfaces.numpy_random.wald
109+
mkl_random.interfaces.numpy_random.weibull
110+
mkl_random.interfaces.numpy_random.zipf

docs/source/reference/patching.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. _patching:
2+
3+
Patching :mod:`numpy.random`
4+
============================
5+
6+
:mod:`mkl_random` can temporarily replace functions and classes in :mod:`numpy.random` with
7+
:mod:`mkl_random`implementations from the :ref:`numpy interface <numpy_random_interface>`.
8+
9+
10+
Functions
11+
---------
12+
13+
.. autofunction:: mkl_random.patch_numpy_random
14+
15+
.. autofunction:: mkl_random.restore_numpy_random
16+
17+
.. autofunction:: mkl_random.is_patched
18+
19+
20+
Context manager
21+
---------------
22+
23+
.. autoclass:: mkl_random.mkl_random
24+
:members:
25+
26+
:class:`mkl_random.mkl_random` is both a context manager and a decorator, making it possible to
27+
scope the patch to a block of code or a function.

0 commit comments

Comments
 (0)