Repository navigation
Add documentation for patching utilities and interfaces
#107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8798c60
9456716
3fca0b6
f06e30d
85b3c4d
ac526c1
5aabff2
98eedcc
c157fd6
cc9274c
dfc9210
8e84bf9
0524b26
42f9b70
f98e9d5
0c4d814
d168cdf
0dfb2db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| .. _fullapi: | ||
|
|
||
| Class MKLRandomState | ||
| ==================== | ||
|
|
||
| .. autoclass:: mkl_random.MKLRandomState | ||
|
ndgrigorian marked this conversation as resolved.
|
||
| :members: | ||
| :inherited-members: | ||
|
|
||
| Class RandomState | ||
| ================= | ||
|
|
||
| .. autoclass:: mkl_random.RandomState | ||
| :members: | ||
| :inherited-members: | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,10 @@ | ||||||
| :mod:`mkl_random` APIs | ||||||
| :mod:`mkl_random` Overview | ||||||
| ====================== | ||||||
|
|
||||||
| The class :doc:`mkl_random.RandomState <./api>` exposes sampling from probability distributions while supporting | ||||||
| The class :doc:`mkl_random.MKLRandomState <./api>` exposes sampling from probability distributions while supporting | ||||||
| different streams of randomness, also known as basic random number generators. | ||||||
|
|
||||||
| The basic random number generator is chosen by specifying :code:`brng` keyword argument to the constructor of :code:`mkl.RandomState` class. | ||||||
| The basic random number generator is chosen by specifying :code:`brng` keyword argument to the constructor of :code:`mkl.MKLRandomState` class. | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit:
Suggested change
|
||||||
|
|
||||||
| The list of supported basic random number generators is as follows (also see `oneMKL Engines <oneMKLBRNG_>`_): | ||||||
|
|
||||||
|
|
@@ -22,10 +22,26 @@ The list of supported basic random number generators is as follows (also see `on | |||||
|
|
||||||
| .. _oneMKLBRNG: https://spec.oneapi.io/versions/1.0-rev-2/elements/oneMKL/source/domains/rng/engines-basic-random-number-generators.html | ||||||
|
|
||||||
|
|
||||||
| Drop-in interfaces | ||||||
| ------------------ | ||||||
|
|
||||||
| The :mod:`mkl_random.interfaces` submodule provides drop-in replacements for standard random modules: | ||||||
|
|
||||||
| * :ref:`mkl_random.interfaces.numpy_random <numpy_random_interface>` - a drop-in replacement for the legacy `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_ module | ||||||
|
|
||||||
|
|
||||||
| Patching | ||||||
| -------- | ||||||
|
|
||||||
| :mod:`mkl_random` can :ref:`patch numpy.random <patching>` so that existing code calling `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_ functions can use :mod:`mkl_random` implementations. | ||||||
|
|
||||||
| .. toctree:: | ||||||
| :hidden: | ||||||
|
|
||||||
| api | ||||||
| interfaces | ||||||
| patching | ||||||
| mt19937 | ||||||
| sfmt19937 | ||||||
| r250 | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| .. _interfaces: | ||
|
|
||
| :mod:`mkl_random.interfaces` | ||
| ==================================================== | ||
|
|
||
| :mod:`mkl_random.interfaces` provides drop-in replacements for supported random number generation | ||
| modules using :mod:`mkl_random` implementations. Currently, only a NumPy interface is provided, | ||
| but more may be added in the future. | ||
|
|
||
|
|
||
|
ndgrigorian marked this conversation as resolved.
|
||
| .. _numpy_random_interface: | ||
|
|
||
| NumPy interface --- :mod:`mkl_random.interfaces.numpy_random` | ||
| ------------------------------------------------------------- | ||
|
|
||
| :mod:`mkl_random.interfaces.numpy_random` is a drop-in replacement for the legacy portion of | ||
| `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_. | ||
|
|
||
| .. currentmodule:: mkl_random.interfaces.numpy_random | ||
|
|
||
| .. note:: | ||
| While the API is the same, :mod:`mkl_random.interfaces.numpy_random` is **not** seed-compatible | ||
| with `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_. Given the same seed, the two modules | ||
| will produce different sequences. The output of :func:`get_state` and accepted input to :func:`set_state` may also differ. | ||
| It is not recommended to provide the output of :func:`get_state` from one module to :func:`set_state` of the other. | ||
| There also may be differences in some edge cases, such as behavior of functions when given specific inputs. | ||
|
|
||
|
|
||
| RandomState class | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. autoclass:: mkl_random.interfaces.numpy_random.RandomState | ||
| :members: | ||
| :undoc-members: | ||
|
ndgrigorian marked this conversation as resolved.
ndgrigorian marked this conversation as resolved.
|
||
|
|
||
|
|
||
| Functions | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| **Seeding and state functions:** | ||
|
|
||
| .. autofunction:: mkl_random.interfaces.numpy_random.seed | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.get_state | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.set_state | ||
|
|
||
| **Simple random data:** | ||
|
|
||
| Similar to NumPy, the methods of :class:`RandomState` are exported as functions in the module. | ||
| Their usage is discouraged, as they are implemented from a global instance of :class:`RandomState`, | ||
| which means results may change across calls. | ||
|
|
||
| .. autofunction:: mkl_random.interfaces.numpy_random.rand | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.randn | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.randint | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.random_integers | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.random_sample | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.random | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.ranf | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.choice | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.bytes | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.sample | ||
|
|
||
| **Permutations:** | ||
|
|
||
| .. autofunction:: mkl_random.interfaces.numpy_random.shuffle | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.permutation | ||
|
|
||
| **Distributions:** | ||
|
|
||
| .. autofunction:: mkl_random.interfaces.numpy_random.beta | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.binomial | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.chisquare | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.dirichlet | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.exponential | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.f | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.gamma | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.geometric | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.gumbel | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.hypergeometric | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.laplace | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.logistic | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.lognormal | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.logseries | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.multinomial | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.multivariate_normal | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.negative_binomial | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.noncentral_chisquare | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.noncentral_f | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.normal | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.pareto | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.poisson | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.power | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.rayleigh | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.standard_cauchy | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.standard_exponential | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.standard_gamma | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.standard_normal | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.standard_t | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.triangular | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.uniform | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.vonmises | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.wald | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.weibull | ||
| .. autofunction:: mkl_random.interfaces.numpy_random.zipf | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| .. _patching: | ||
|
|
||
| Patching `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_ | ||
| ============================ | ||
|
|
||
| :mod:`mkl_random` can temporarily replace functions and classes in `numpy.random <https://numpy.org/doc/stable/reference/random/legacy.html>`_ with | ||
| :mod:`mkl_random` implementations from the :ref:`numpy interface <numpy_random_interface>`. | ||
|
|
||
|
|
||
| Functions | ||
| --------- | ||
|
|
||
| .. autofunction:: mkl_random.patch_numpy_random | ||
|
ndgrigorian marked this conversation as resolved.
|
||
|
|
||
| .. autofunction:: mkl_random.restore_numpy_random | ||
|
|
||
| .. autofunction:: mkl_random.is_patched | ||
|
|
||
|
|
||
| Context manager | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also cover the command-line patching here? On master, |
||
| --------------- | ||
|
|
||
| .. autoclass:: mkl_random.mkl_random | ||
| :members: | ||
|
|
||
| :class:`mkl_random.mkl_random` is both a context manager and a decorator, making it possible to | ||
| scope the patch to a block of code or a function. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#165 also reworks
api.rst(autosummary tables plus numpydoc) and removes the# no-cython-lintmarkers that this hook strips, and both PRs touch the samemklrand.pyxdocstrings. Would it make sense to land #165 first and rebase this on top, keeping the new interfaces and patching pages and dropping the overlappingapi.rst/conf.pychanges?