Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Intel(R) oneAPI Math Kernel Library

.. grid-item-card:: Reference Guide

The reference guide contains a detailed description of class :class:`mkl_random.RandomState` and its methods.
The reference guide contains a detailed description of class :class:`mkl_random.MKLRandomState`,
the :ref:`interfaces <interfaces>` submodule, and :ref:`NumPy patching <patching>` utilities.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All links here are referred on documentation/reference/index.html page, but I guess, it should be on specific section with detailed description.


+++

Expand Down
8 changes: 8 additions & 0 deletions docs/source/reference/api.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
.. _fullapi:

Class MKLRandomState
====================

.. autoclass:: mkl_random.MKLRandomState
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rendered page has # no-cython-lint. Is there a way to suppress the linter warning without being shown on the generated page?

:members:
:inherited-members:

Class RandomState
=================

.. autoclass:: mkl_random.RandomState
:members:
:inherited-members:
23 changes: 20 additions & 3 deletions docs/source/reference/index.rst
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.

The list of supported basic random number generators is as follows (also see `oneMKL Engines <oneMKLBRNG_>`_):

Expand All @@ -22,10 +22,27 @@ 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 :mod:`numpy.random` module


Patching
--------

:mod:`mkl_random` can :ref:`patch numpy.random <patching>` so that existing code calling :mod:`numpy.random`
functions can use :mod:`mkl_random` implementations.

.. toctree::
:hidden:

api
interfaces
patching
mt19937
sfmt19937
r250
Expand Down
110 changes: 110 additions & 0 deletions docs/source/reference/interfaces.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
.. _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.


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we updat examples in brngs description with MKLRandomState? (I mean pages, like: rendered%20documentation/reference/mt19937.html)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is about example on How-to guide (documentation/how_to.html)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And Beginner's guide (documentation/tutorials.html)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, yes, we should

.. _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
:mod:`numpy.random`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be a ref on numpy.random page?


.. note::
While the API is the same, :mod:`mkl_random.interfaces.numpy_random` is **not** seed-compatible
with :mod:`numpy.random`. Given the same seed, the two modules will produce different sequences.
The output of `get_state` and accepted input to `set_state` may also differ. It is not
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should here be a ref on functions?

Suggested change
The output of `get_state` and accepted input to `set_state` may also differ. It is not
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 `get_state` from one module to `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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here: # noqa: E501,W505

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link on numpy.random.RandomState is not clicable:

For full documentation refer to numpy.random.RandomState.



Functions
^^^^^^^^^^^^^^^^^^^^^^

**Seeding and state functions:**

.. autosummary::

mkl_random.interfaces.numpy_random.seed
mkl_random.interfaces.numpy_random.get_state
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The out parameter is badly formated

mkl_random.interfaces.numpy_random.set_state
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be clickable to go from the table to the function description?


**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.

.. autosummary::

mkl_random.interfaces.numpy_random.rand
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link on page with numpy corresponding functions are not working.

mkl_random.interfaces.numpy_random.randn
mkl_random.interfaces.numpy_random.randint
mkl_random.interfaces.numpy_random.random_integers
mkl_random.interfaces.numpy_random.random_sample
mkl_random.interfaces.numpy_random.random
mkl_random.interfaces.numpy_random.ranf
mkl_random.interfaces.numpy_random.choice
mkl_random.interfaces.numpy_random.bytes
mkl_random.interfaces.numpy_random.sample

**Permutations:**

.. autosummary::

mkl_random.interfaces.numpy_random.shuffle
mkl_random.interfaces.numpy_random.permutation

**Distributions:**

.. autosummary::

mkl_random.interfaces.numpy_random.beta
mkl_random.interfaces.numpy_random.binomial
mkl_random.interfaces.numpy_random.chisquare
mkl_random.interfaces.numpy_random.dirichlet
mkl_random.interfaces.numpy_random.exponential
mkl_random.interfaces.numpy_random.f
mkl_random.interfaces.numpy_random.gamma
mkl_random.interfaces.numpy_random.geometric
mkl_random.interfaces.numpy_random.gumbel
mkl_random.interfaces.numpy_random.hypergeometric
mkl_random.interfaces.numpy_random.laplace
mkl_random.interfaces.numpy_random.logistic
mkl_random.interfaces.numpy_random.lognormal
mkl_random.interfaces.numpy_random.logseries
mkl_random.interfaces.numpy_random.multinomial
mkl_random.interfaces.numpy_random.multivariate_normal
mkl_random.interfaces.numpy_random.negative_binomial
mkl_random.interfaces.numpy_random.noncentral_chisquare
mkl_random.interfaces.numpy_random.noncentral_f
mkl_random.interfaces.numpy_random.normal
mkl_random.interfaces.numpy_random.pareto
mkl_random.interfaces.numpy_random.poisson
mkl_random.interfaces.numpy_random.power
mkl_random.interfaces.numpy_random.rayleigh
mkl_random.interfaces.numpy_random.standard_cauchy
mkl_random.interfaces.numpy_random.standard_exponential
mkl_random.interfaces.numpy_random.standard_gamma
mkl_random.interfaces.numpy_random.standard_normal
mkl_random.interfaces.numpy_random.standard_t
mkl_random.interfaces.numpy_random.triangular
mkl_random.interfaces.numpy_random.uniform
mkl_random.interfaces.numpy_random.vonmises
mkl_random.interfaces.numpy_random.wald
mkl_random.interfaces.numpy_random.weibull
mkl_random.interfaces.numpy_random.zipf
27 changes: 27 additions & 0 deletions docs/source/reference/patching.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.. _patching:

Patching :mod:`numpy.random`
============================

:mod:`mkl_random` can temporarily replace functions and classes in :mod:`numpy.random` with
:mod:`mkl_random`implementations from the :ref:`numpy interface <numpy_random_interface>`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:mod:`mkl_random`implementations from the :ref:`numpy interface <numpy_random_interface>`.
:mod:`mkl_random` implementations from the :ref:`numpy interface <numpy_random_interface>`.



Functions
---------

.. autofunction:: mkl_random.patch_numpy_random

.. autofunction:: mkl_random.restore_numpy_random

.. autofunction:: mkl_random.is_patched


Context manager
---------------

.. 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.
Loading