Skip to content

Commit a513351

Browse files
committed
BUG: adjust docs and doctests for namespace transition
1 parent ab080cf commit a513351

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

doc/source/reference/randomgen/extending.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
.. currentmodule:: numpy.random.randomgen
2+
13
Extending
24
---------
35
The basic RNGs have been designed to be extendable using standard tools for
46
high-performance Python -- numba and Cython.
5-
The :class:`randomgen.generator.RandomGenerator` object can also be used with
7+
The `~RandomGenerator` object can also be used with
68
user-provided basic RNGs as long as these export a small set of required
79
functions.
810

@@ -65,7 +67,7 @@ Cython
6567
======
6668

6769
Cython can be used to unpack the ``PyCapsule`` provided by a basic RNG.
68-
This example uses :class:`~randomgen.xoroshiro128.Xoroshiro128` and
70+
This example uses `~xoroshiro128.Xoroshiro128` and
6971
``random_gauss_zig``, the Ziggurat-based generator for normals, to fill an
7072
array. The usual caveats for writing high-performance code using Cython --
7173
removing bounds checks and wrap around, providing array alignment information
@@ -137,7 +139,7 @@ examples folder.
137139

138140
New Basic RNGs
139141
==============
140-
:class:`~randomgen.generator.RandomGenerator` can be used with other
142+
`~RandomGenerator` can be used with other
141143
user-provided basic RNGs. The simplest way to write a new basic RNG is to
142144
examine the pyx file of one of the existing basic RNGs. The key structure
143145
that must be provided is the ``capsule`` which contains a ``PyCapsule`` to a
@@ -158,7 +160,7 @@ used by the basic RNG. The next three are function pointers which return the
158160
next 64- and 32-bit unsigned integers, the next random double and the next
159161
raw value. This final function is used for testing and so can be set to
160162
the next 64-bit unsigned integer function if not needed. Functions inside
161-
:class:`~randomgen.generator.RandomGenerator` use this structure as in
163+
``RandomGenerator`` use this structure as in
162164

163165
.. code-block:: c
164166

doc/source/reference/randomgen/generator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Random Generator
44
----------------
5-
The :class:`~RandomGenerator` provides access to
5+
The `~RandomGenerator` provides access to
66
a wide range of distributions, and served as a replacement for
77
:class:`~numpy.random.RandomState`. The main difference between
88
the two is that ``RandomGenerator`` relies on an additional basic RNG to

doc/source/reference/randomgen/new-or-different.rst

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
.. _new-or-different:
22

3+
.. currentmodule:: numpy.random.randomgen
4+
35
What's New or Different
46
-----------------------
57

68
.. warning::
79

810
The Box-Muller method used to produce NumPy's normals is no longer available
9-
in :class:`~randomgen.generator.RandomGenerator`. It is not possible to
10-
reproduce the random values using :class:`~randomgen.generator.RandomGenerator`
11-
for the normal distribution or any other distribution that relies on the
12-
normal such as the gamma or student's t. If you require backward compatibility, a
13-
legacy generator, :class:`~randomgen.legacy.LegacyGenerator`, has been created
14-
which can fully reproduce the sequence produced by NumPy.
11+
in `~.RandomGenerator`. It is not possible to
12+
reproduce the exact random values using ``RandomGenerator`` for the normal
13+
distribution or any other distribution that relies on the normal such as the
14+
`numpy.random.gamma` or `numpy.random.standard_t`. If you require backward
15+
compatibility, a legacy generator, `~.legacy.
16+
LegacyGenerator`, has been created which can fully reproduce the exact byte
17+
sequence produced by legacy code.
1518

1619

17-
* :func:`~randomgen.entropy.random_entropy` provides access to the system
20+
* `~.entropy.random_entropy` provides access to the system
1821
source of randomness that is used in cryptographic applications (e.g.,
1922
``/dev/urandom`` on Unix).
2023
* Simulate from the complex normal distribution
21-
(:meth:`~randomgen.generator.RandomGenerator.complex_normal`)
24+
(`~.RandomGenerator.complex_normal`)
2225
* The normal, exponential and gamma generators use 256-step Ziggurat
2326
methods which are 2-10 times faster than NumPy's default implementation in
24-
:meth:`~randomgen.generator.RandomGenerator.standard_normal`,
25-
:meth:`~randomgen.generator.RandomGenerator.standard_exponential` or
26-
:meth:`~randomgen.generator.RandomGenerator.standard_gamma`.
27+
`~.RandomGenerator.standard_normal`,
28+
`~.RandomGenerator.standard_exponential` or
29+
`~.RandomGenerator.standard_gamma`.
2730
* The Box-Muller used to produce NumPy's normals is no longer available.
2831
* All basic random generators functions to produce doubles, uint64s and
29-
uint32s via CTypes (:meth:`~randomgen.xoroshiro128.Xoroshiro128.ctypes`)
30-
and CFFI (:meth:`~randomgen.xoroshiro128.Xoroshiro128.cffi`). This allows
31-
these basic RNGs to be used in numba.
32+
uint32s via CTypes (`~.xoroshiro128.Xoroshiro128.
33+
ctypes`) and CFFI (`~.xoroshiro128.Xoroshiro128.cffi`).
34+
This allows these basic RNGs to be used in numba.
3235
* The basic random number generators can be used in downstream projects via
3336
Cython.
3437

3538

3639
.. ipython:: python
3740
38-
from numpy.random.randomgen import Xoroshiro128
41+
from numpy.random.randomgen import Xoroshiro128
3942
import numpy.random
4043
rg = Xoroshiro128().generator
4144
%timeit rg.standard_normal(100000)
@@ -55,12 +58,12 @@ What's New or Different
5558
to produce either single or double prevision uniform random variables for
5659
select distributions
5760

58-
* Uniforms (:meth:`~randomgen.generator.RandomGenerator.random_sample` and
59-
:meth:`~randomgen.generator.RandomGenerator.rand`)
60-
* Normals (:meth:`~randomgen.generator.RandomGenerator.standard_normal` and
61-
:meth:`~randomgen.generator.RandomGenerator.randn`)
62-
* Standard Gammas (:meth:`~randomgen.generator.RandomGenerator.standard_gamma`)
63-
* Standard Exponentials (:meth:`~randomgen.generator.RandomGenerator.standard_exponential`)
61+
* Uniforms (`~.RandomGenerator.random_sample` and
62+
`~.RandomGenerator.rand`)
63+
* Normals (`~.RandomGenerator.standard_normal` and
64+
`~.RandomGenerator.randn`)
65+
* Standard Gammas (`~.RandomGenerator.standard_gamma`)
66+
* Standard Exponentials (`~.RandomGenerator.standard_exponential`)
6467

6568
.. ipython:: python
6669
@@ -72,10 +75,10 @@ What's New or Different
7275
* Optional ``out`` argument that allows existing arrays to be filled for
7376
select distributions
7477

75-
* Uniforms (:meth:`~randomgen.generator.RandomGenerator.random_sample`)
76-
* Normals (:meth:`~randomgen.generator.RandomGenerator.standard_normal`)
77-
* Standard Gammas (:meth:`~randomgen.generator.RandomGenerator.standard_gamma`)
78-
* Standard Exponentials (:meth:`~randomgen.generator.RandomGenerator.standard_exponential`)
78+
* Uniforms (`~.RandomGenerator.random_sample`)
79+
* Normals (`~.RandomGenerator.standard_normal`)
80+
* Standard Gammas (`~.RandomGenerator.standard_gamma`)
81+
* Standard Exponentials (`~.RandomGenerator.standard_exponential`)
7982

8083
This allows multithreading to fill large arrays in chunks using suitable
8184
PRNGs in parallel.
@@ -90,7 +93,7 @@ What's New or Different
9093
9194
* Support for Lemire’s method of generating uniform integers on an
9295
arbitrary interval by setting ``use_masked=True`` in
93-
(:meth:`~randomgen.generator.RandomGenerator.randint`).
96+
(`~.RandomGenerator.randint`).
9497

9598
.. ipython:: python
9699

numpy/random/dsfmt.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ cdef class DSFMT:
102102
generators should be initialized with the same seed to ensure that the
103103
segments come from the same sequence.
104104
105-
>>> from numpy.random.randomgen.entropy import random_entropy
106-
>>> from numpy.random.randomgen import RandomGenerator, DSFMT
105+
>>> from numpy.random.entropy import random_entropy
106+
>>> from numpy.random import RandomGenerator, DSFMT
107107
>>> seed = random_entropy()
108108
>>> rs = [RandomGenerator(DSFMT(seed)) for _ in range(10)]
109109
# Advance rs[i] by i jumps

0 commit comments

Comments
 (0)