Repository navigation
Reimplement dpnp.random.RandomState on the device RNG
#3162
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: feature/device-rng-bit-generators
Are you sure you want to change the base?
Changes from all commits
76ad5e7
aba0610
5d9a6c4
33668d2
18baecd
04bf103
9ffdd4e
4240f72
2b5a19c
442da12
4b810b4
469fb1c
64e37fe
ff5edaa
46d8cc7
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 |
|---|---|---|
|
|
@@ -9,9 +9,9 @@ DPNP draws random numbers on the SYCL device, by default with the | |
| counter-based Philox4x32x10 generator of the oneMKL device RNG API, or with | ||
| NumPy's PCG64DXSM generator or the MRG32k3a generator of the oneMKL device | ||
| RNG API. A oneMath build takes Philox4x32x10 and MRG32k3a from oneMath's | ||
| device RNG API instead. It provides the :class:`Generator` API of NumPy, | ||
| recommended for new code. The legacy :class:`RandomState` API and the | ||
| module-level functions still use the host-side oneMKL RNG. | ||
| device RNG API instead. It provides both NumPy random APIs: the | ||
| :class:`Generator` API recommended for new code, and the legacy | ||
| :class:`RandomState` API with the module-level functions built on it. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
|
|
@@ -27,6 +27,8 @@ A generator draws all its samples on one SYCL queue, chosen with the | |
| ``device`` or ``sycl_queue`` keyword when it is created. All samples are | ||
| :class:`dpnp.ndarray`, zero-dimensional when ``size`` is ``None``. | ||
|
|
||
| .. _random-differences: | ||
|
|
||
| Differences from NumPy | ||
| ---------------------- | ||
|
|
||
|
|
@@ -52,8 +54,8 @@ Differences from NumPy | |
| default, the samples take the USM type of the array parameters, or | ||
| ``"device"`` when there are none. | ||
| * Parameters on the host (Python scalars, lists and NumPy arrays) are | ||
| checked as in NumPy. Parameters in :class:`dpnp.ndarray` are | ||
| not, since that would wait for the device. | ||
| checked as in NumPy. In :class:`Generator`, parameters in | ||
| :class:`dpnp.ndarray` are not, since that would wait for the device. | ||
| Invalid ones give undefined values, such as NaN or the smallest ``int64``, | ||
| but the kernels handle them safely: they never loop without end or access | ||
| memory out of bounds. Floating-point arrays given for integer parameters | ||
|
|
@@ -72,15 +74,21 @@ Differences from NumPy | |
| * ``zipf`` follows the Zipf distribution truncated to the largest ``int64``. | ||
| NumPy's rejection test rounds to accepting every sample above ``2**53``, | ||
| which makes its tail too heavy for ``a`` close to 1. | ||
| * ``hypergeometric`` requires ``ngood`` and ``nbad`` below ``10**9``, and | ||
| ``multivariate_hypergeometric`` requires ``sum(colors)`` below ``10**9`` | ||
| for the ``"count"`` method too. | ||
| * :meth:`RandomState.randint` and :func:`randint` return ``int64`` values by | ||
| default, as do :meth:`RandomState.random_integers`, | ||
| :func:`random_integers` and :meth:`RandomState.tomaxint`, whose values | ||
| reach the largest ``int64``. NumPy returns a C ``long`` instead, which is | ||
| ``int32`` on Windows. | ||
|
Comment on lines
+77
to
+81
Contributor
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: On Windows, NumPy's legacy |
||
| * ``hypergeometric`` requires ``ngood`` and ``nbad`` below ``10**9``, also in | ||
| :class:`RandomState`, and ``multivariate_hypergeometric`` requires | ||
| ``sum(colors)`` below ``10**9`` for the ``"count"`` method too. | ||
| * ``choice`` always returns a sample without replacement in random order, | ||
| so its ``shuffle`` parameter has no effect. | ||
| * ``p`` of ``choice`` and ``pvals`` of ``multinomial`` are only checked when | ||
| they are on the host, as the other parameters are. | ||
| * :meth:`Generator.shuffle` only accepts an array on the device, a | ||
| :class:`dpnp.ndarray` or :class:`dpnp.tensor.usm_ndarray`, as in CuPy. | ||
| * :meth:`Generator.shuffle` and :func:`shuffle` only accept an array on the | ||
| device, a :class:`dpnp.ndarray` or :class:`dpnp.tensor.usm_ndarray`, as in | ||
| CuPy. | ||
| * Generators and bit generators cannot be pickled or deep-copied, | ||
| and :class:`Philox4x3210` and :class:`MRG32k3a` have no ``advance`` or | ||
| ``jumped`` method. | ||
|
|
@@ -201,6 +209,24 @@ Legacy random generation | |
|
|
||
| .. hint:: `NumPy API Reference: Legacy random generation <https://numpy.org/doc/stable/reference/random/legacy.html>`_ | ||
|
|
||
| :class:`RandomState` keeps the parameter checks of NumPy's legacy one, also | ||
| for parameters in :class:`dpnp.ndarray`, as CuPy's does, so that a call with | ||
| such parameters waits for the device to check them. The module-level | ||
| functions use one :class:`RandomState` per SYCL queue: the | ||
| queue given by the ``device`` or ``sycl_queue`` keyword, or else the queue of | ||
| a :class:`dpnp.ndarray` parameter, or else the default queue. | ||
|
|
||
| .. autosummary:: | ||
| :toctree: generated/ | ||
| :nosignatures: | ||
|
|
||
| RandomState | ||
| seed | ||
| get_state | ||
| set_state | ||
| get_bit_generator | ||
| set_bit_generator | ||
|
|
||
| Simple random data | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
|
||
|
|
@@ -271,15 +297,3 @@ Distributions | |
| wald | ||
| weibull | ||
| zipf | ||
|
|
||
| RandomState | ||
| ^^^^^^^^^^^ | ||
|
|
||
| .. autosummary:: | ||
| :toctree: generated/ | ||
| :nosignatures: | ||
|
|
||
| RandomState | ||
| seed | ||
| get_random_state | ||
| set_random_state | ||
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.
Nit: Missed in my earlier rounds: on master
RandomStatehad onlynormal,rand,randint,randn,random_sample,standard_normalanduniform. So the twoFixedlines should name only thedpnp.randomfunctions, and thisAddedline could say thatRandomStatenow has the other methods of NumPy's (betatozipf,choice,permutation,shuffle,bytes,tomaxint).