Skip to content

Commit a0e6492

Browse files
authored
Merge pull request numpy#26385 from bmwoodruff/links-random-folder
DOC: Updated remaining links in random folder
2 parents 323d168 + d1a52e3 commit a0e6492

File tree

13 files changed

+105
-103
lines changed

13 files changed

+105
-103
lines changed

doc/source/reference/c-api/coremath.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
NumPy core math library
22
=======================
33

4-
The numpy core math library ('npymath') is a first step in this direction. This
4+
The numpy core math library (``npymath``) is a first step in this direction. This
55
library contains most math-related C99 functionality, which can be used on
66
platforms where C99 is not well supported. The core math functions have the
77
same API as the C99 ones, except for the ``npy_*`` prefix.
@@ -304,7 +304,7 @@ Linking against the core math library in an extension
304304
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305305

306306
To use the core math library that NumPy ships as a static library in your own
307-
Python extension, you need to add the npymath compile and link options to your
307+
Python extension, you need to add the ``npymath`` compile and link options to your
308308
extension. The exact steps to take will depend on the build system you are using.
309309
The generic steps to take are:
310310

doc/source/reference/distutils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Packaging (:mod:`numpy.distutils`)
1414
.. warning::
1515

1616
Note that ``setuptools`` does major releases often and those may contain
17-
changes that break ``numpy.distutils``, which will *not* be updated anymore
17+
changes that break :mod:`numpy.distutils`, which will *not* be updated anymore
1818
for new ``setuptools`` versions. It is therefore recommended to set an
1919
upper version bound in your build configuration for the last known version
2020
of ``setuptools`` that works with your build.

doc/source/reference/random/compatibility.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ outside of NumPy's control that limit our ability to guarantee much more than
2222
this. For example, different CPUs implement floating point arithmetic
2323
differently, and this can cause differences in certain edge cases that cascade
2424
to the rest of the stream. `Generator.multivariate_normal`, for another
25-
example, uses a matrix decomposition from ``numpy.linalg``. Even on the same
25+
example, uses a matrix decomposition from `numpy.linalg`. Even on the same
2626
platform, a different build of ``numpy`` may use a different version of this
2727
matrix decomposition algorithm from the LAPACK that it links to, causing
2828
`Generator.multivariate_normal` to return completely different (but equally

doc/source/reference/random/extending.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
Extending
66
=========
7-
The BitGenerators have been designed to be extendable using standard tools for
8-
high-performance Python -- numba and Cython. The `~Generator` object can also
9-
be used with user-provided BitGenerators as long as these export a small set of
10-
required functions.
7+
The `BitGenerator`\ s have been designed to be extendable using standard tools
8+
for high-performance Python -- numba and Cython. The `Generator` object can
9+
also be used with user-provided `BitGenerator`\ s as long as these export a
10+
small set of required functions.
1111

1212
Numba
1313
-----
1414
Numba can be used with either CTypes or CFFI. The current iteration of the
15-
BitGenerators all export a small set of functions through both interfaces.
15+
`BitGenerator`\ s all export a small set of functions through both interfaces.
1616

1717
This example shows how numba can be used to produce gaussian samples using
1818
a pure Python implementation which is then compiled. The random numbers are
@@ -32,7 +32,7 @@ the `Examples`_ section below.
3232
Cython
3333
------
3434

35-
Cython can be used to unpack the ``PyCapsule`` provided by a BitGenerator.
35+
Cython can be used to unpack the ``PyCapsule`` provided by a `BitGenerator`.
3636
This example uses `PCG64` and the example from above. The usual caveats
3737
for writing high-performance code using Cython -- removing bounds checks and
3838
wrap around, providing array alignment information -- still apply.
@@ -41,7 +41,7 @@ wrap around, providing array alignment information -- still apply.
4141
:language: cython
4242
:end-before: example 2
4343

44-
The BitGenerator can also be directly accessed using the members of the ``bitgen_t``
44+
The `BitGenerator` can also be directly accessed using the members of the ``bitgen_t``
4545
struct.
4646

4747
.. literalinclude:: ../../../../numpy/random/_examples/cython/extending_distributions.pyx
@@ -81,9 +81,9 @@ directly from the ``_generator`` shared object, using the `BitGenerator.cffi` in
8181

8282
New BitGenerators
8383
-----------------
84-
`~Generator` can be used with user-provided `~BitGenerator`\ s. The simplest
85-
way to write a new BitGenerator is to examine the pyx file of one of the
86-
existing BitGenerators. The key structure that must be provided is the
84+
`Generator` can be used with user-provided `BitGenerator`\ s. The simplest
85+
way to write a new `BitGenerator` is to examine the pyx file of one of the
86+
existing `BitGenerator`\ s. The key structure that must be provided is the
8787
``capsule`` which contains a ``PyCapsule`` to a struct pointer of type
8888
``bitgen_t``,
8989

@@ -98,11 +98,11 @@ existing BitGenerators. The key structure that must be provided is the
9898
} bitgen_t;
9999
100100
which provides 5 pointers. The first is an opaque pointer to the data structure
101-
used by the BitGenerators. The next three are function pointers which return
102-
the next 64- and 32-bit unsigned integers, the next random double and the next
103-
raw value. This final function is used for testing and so can be set to
104-
the next 64-bit unsigned integer function if not needed. Functions inside
105-
``Generator`` use this structure as in
101+
used by the `BitGenerator`\ s. The next three are function pointers which
102+
return the next 64- and 32-bit unsigned integers, the next random double and
103+
the next raw value. This final function is used for testing and so can be set
104+
to the next 64-bit unsigned integer function if not needed. Functions inside
105+
`Generator` use this structure as in
106106

107107
.. code-block:: c
108108

doc/source/reference/random/multithreading.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ that does not use an existing array due to array creation overhead.
104104
105105
Out[6]: 125 ms ± 309 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
106106
107-
Note that if `threads` is not set by the user, it will be determined by
108-
`multiprocessing.cpu_count()`.
107+
Note that if ``threads`` is not set by the user, it will be determined by
108+
``multiprocessing.cpu_count()``.
109109

110110
.. code-block:: ipython
111111

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,40 @@ NumPy 1.17.0 introduced `Generator` as an improved replacement for
99
the :ref:`legacy <legacy>` `RandomState`. Here is a quick comparison of the two
1010
implementations.
1111

12-
================== ==================== =============
13-
Feature Older Equivalent Notes
14-
------------------ -------------------- -------------
15-
`~.Generator` `~.RandomState` ``Generator`` requires a stream
16-
source, called a `BitGenerator`
17-
A number of these are provided.
18-
``RandomState`` uses
19-
the Mersenne Twister `~.MT19937` by
20-
default, but can also be instantiated
21-
with any BitGenerator.
22-
------------------ -------------------- -------------
23-
``random`` ``random_sample``, Access the values in a BitGenerator,
24-
``rand`` convert them to ``float64`` in the
25-
interval ``[0.0.,`` `` 1.0)``.
26-
In addition to the ``size`` kwarg, now
27-
supports ``dtype='d'`` or ``dtype='f'``,
28-
and an ``out`` kwarg to fill a user-
29-
supplied array.
30-
31-
Many other distributions are also
32-
supported.
33-
------------------ -------------------- -------------
34-
``integers`` ``randint``, Use the ``endpoint`` kwarg to adjust
35-
``random_integers`` the inclusion or exclusion of the
36-
``high`` interval endpoint
37-
================== ==================== =============
12+
======================= ================== =============
13+
Feature Older Equivalent Notes
14+
----------------------- ------------------ -------------
15+
`Generator` `RandomState` `Generator` requires a stream
16+
source, called a `BitGenerator`
17+
A number of these are provided.
18+
`RandomState` uses the Mersenne
19+
Twister `MT19937` by default,
20+
but can also be instantiated
21+
with any BitGenerator.
22+
----------------------- ------------------ -------------
23+
`~.Generator.random` `random_sample`, Access the values in a
24+
`rand` BitGenerator, convert them to
25+
``float64`` in the interval
26+
``[0.0., 1.0)``. In addition
27+
to the ``size`` kwarg, now
28+
supports ``dtype='d'`` or
29+
``dtype='f'``, and an ``out``
30+
kwarg to fill a user-supplied
31+
array.
32+
33+
Many other distributions are also
34+
supported.
35+
----------------------- ------------------ -------------
36+
`~.Generator.integers` `randint`, Use the ``endpoint`` kwarg to
37+
`random_integers` adjust the inclusion or exclusion
38+
of the ``high`` interval endpoint.
39+
======================= ================== =============
3840

3941
* The normal, exponential and gamma generators use 256-step Ziggurat
4042
methods which are 2-10 times faster than NumPy's default implementation in
4143
`~.Generator.standard_normal`, `~.Generator.standard_exponential` or
4244
`~.Generator.standard_gamma`. Because of the change in algorithms, it is not
43-
possible to reproduce the exact random values using ``Generator`` for these
45+
possible to reproduce the exact random values using `Generator` for these
4446
distributions or any distribution method that relies on them.
4547

4648
.. ipython:: python
@@ -63,8 +65,8 @@ Feature Older Equivalent Notes
6365
6466
* `~.Generator.integers` is now the canonical way to generate integer
6567
random numbers from a discrete uniform distribution. This replaces both
66-
``randint`` and the deprecated ``random_integers``.
67-
* The ``rand`` and ``randn`` methods are only available through the legacy
68+
`randint` and the deprecated `random_integers`.
69+
* The `rand` and `randn` methods are only available through the legacy
6870
`~.RandomState`.
6971
* `Generator.random` is now the canonical way to generate floating-point
7072
random numbers, which replaces `RandomState.random_sample`,

doc/source/reference/random/parallel.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,39 @@ or distributed).
1313
------------------------
1414

1515
NumPy allows you to spawn new (with very high probability) independent
16-
`~BitGenerator` and `~Generator` instances via their ``spawn()`` method.
17-
This spawning is implemented by the `~SeedSequence` used for initializing
16+
`BitGenerator` and `Generator` instances via their ``spawn()`` method.
17+
This spawning is implemented by the `SeedSequence` used for initializing
1818
the bit generators random stream.
1919

20-
`~SeedSequence` `implements an algorithm`_ to process a user-provided seed,
20+
`SeedSequence` `implements an algorithm`_ to process a user-provided seed,
2121
typically as an integer of some size, and to convert it into an initial state for
22-
a `~BitGenerator`. It uses hashing techniques to ensure that low-quality seeds
22+
a `BitGenerator`. It uses hashing techniques to ensure that low-quality seeds
2323
are turned into high quality initial states (at least, with very high
2424
probability).
2525

26-
For example, `MT19937` has a state consisting of 624
27-
`uint32` integers. A naive way to take a 32-bit integer seed would be to just set
26+
For example, `MT19937` has a state consisting of 624 ``uint32``
27+
integers. A naive way to take a 32-bit integer seed would be to just set
2828
the last element of the state to the 32-bit seed and leave the rest 0s. This is
2929
a valid state for `MT19937`, but not a good one. The Mersenne Twister
3030
algorithm `suffers if there are too many 0s`_. Similarly, two adjacent 32-bit
3131
integer seeds (i.e. ``12345`` and ``12346``) would produce very similar
3232
streams.
3333

34-
`~SeedSequence` avoids these problems by using successions of integer hashes
34+
`SeedSequence` avoids these problems by using successions of integer hashes
3535
with good `avalanche properties`_ to ensure that flipping any bit in the input
3636
has about a 50% chance of flipping any bit in the output. Two input seeds that
3737
are very close to each other will produce initial states that are very far
3838
from each other (with very high probability). It is also constructed in such
3939
a way that you can provide arbitrary-sized integers or lists of integers.
40-
`~SeedSequence` will take all of the bits that you provide and mix them
41-
together to produce however many bits the consuming `~BitGenerator` needs to
40+
`SeedSequence` will take all of the bits that you provide and mix them
41+
together to produce however many bits the consuming `BitGenerator` needs to
4242
initialize itself.
4343

4444
These properties together mean that we can safely mix together the usual
45-
user-provided seed with simple incrementing counters to get `~BitGenerator`
45+
user-provided seed with simple incrementing counters to get `BitGenerator`
4646
states that are (to very high probability) independent of each other. We can
4747
wrap this together into an API that is easy to use and difficult to misuse.
48-
Note that while `~SeedSequence` attempts to solve many of the issues related to
48+
Note that while `SeedSequence` attempts to solve many of the issues related to
4949
user-provided small seeds, we still :ref:`recommend<recommend-secrets-randbits>`
5050
using :py:func:`secrets.randbits` to generate seeds with 128 bits of entropy to
5151
avoid the remaining biases introduced by human-chosen seeds.
@@ -62,7 +62,7 @@ avoid the remaining biases introduced by human-chosen seeds.
6262
6363
.. end_block
6464
65-
For convenience the direct use of `~SeedSequence` is not necessary.
65+
For convenience the direct use of `SeedSequence` is not necessary.
6666
The above ``streams`` can be spawned directly from a parent generator
6767
via `~Generator.spawn`:
6868

@@ -74,7 +74,7 @@ via `~Generator.spawn`:
7474
.. end_block
7575
7676
Child objects can also spawn to make grandchildren, and so on.
77-
Each child has a `~SeedSequence` with its position in the tree of spawned
77+
Each child has a `SeedSequence` with its position in the tree of spawned
7878
child objects mixed in with the user-provided seed to generate independent
7979
(with very high probability) streams.
8080

@@ -92,7 +92,7 @@ Python has increasingly-flexible mechanisms for parallelization available, and
9292
this scheme fits in very well with that kind of use.
9393

9494
Using this scheme, an upper bound on the probability of a collision can be
95-
estimated if one knows the number of streams that you derive. `~SeedSequence`
95+
estimated if one knows the number of streams that you derive. `SeedSequence`
9696
hashes its inputs, both the seed and the spawn-tree-path, down to a 128-bit
9797
pool by default. The probability that there is a collision in
9898
that pool, pessimistically-estimated ([1]_), will be about :math:`n^2*2^{-128}` where
@@ -110,7 +110,7 @@ territory ([2]_).
110110
.. [2] In this calculation, we can mostly ignore the amount of numbers drawn from each
111111
stream. See :ref:`upgrading-pcg64` for the technical details about
112112
`PCG64`. The other PRNGs we provide have some extra protection built in
113-
that avoids overlaps if the `~SeedSequence` pools differ in the
113+
that avoids overlaps if the `SeedSequence` pools differ in the
114114
slightest bit. `PCG64DXSM` has :math:`2^{127}` separate cycles
115115
determined by the seed in addition to the position in the
116116
:math:`2^{128}` long period for each cycle, so one has to both get on or
@@ -133,7 +133,7 @@ territory ([2]_).
133133
Sequence of integer seeds
134134
-------------------------
135135

136-
As discussed in the previous section, `~SeedSequence` can not only take an
136+
As discussed in the previous section, `SeedSequence` can not only take an
137137
integer seed, it can also take an arbitrary-length sequence of (non-negative)
138138
integers. If one exercises a little care, one can use this feature to design
139139
*ad hoc* schemes for getting safe parallel PRNG streams with similar safety
@@ -164,7 +164,7 @@ integer in a list.
164164
This can be used to replace a number of unsafe strategies that have been used
165165
in the past which try to combine the root seed and the ID back into a single
166166
integer seed value. For example, it is common to see users add the worker ID to
167-
the root seed, especially with the legacy `~RandomState` code.
167+
the root seed, especially with the legacy `RandomState` code.
168168

169169
.. code-block:: python
170170
@@ -253,13 +253,13 @@ are listed below.
253253
+-----------------+-------------------------+-------------------------+-------------------------+
254254
| BitGenerator | Period | Jump Size | Bits per Draw |
255255
+=================+=========================+=========================+=========================+
256-
| MT19937 | :math:`2^{19937}-1` | :math:`2^{128}` | 32 |
256+
| `MT19937` | :math:`2^{19937}-1` | :math:`2^{128}` | 32 |
257257
+-----------------+-------------------------+-------------------------+-------------------------+
258-
| PCG64 | :math:`2^{128}` | :math:`~2^{127}` ([3]_) | 64 |
258+
| `PCG64` | :math:`2^{128}` | :math:`~2^{127}` ([3]_) | 64 |
259259
+-----------------+-------------------------+-------------------------+-------------------------+
260-
| PCG64DXSM | :math:`2^{128}` | :math:`~2^{127}` ([3]_) | 64 |
260+
| `PCG64DXSM` | :math:`2^{128}` | :math:`~2^{127}` ([3]_) | 64 |
261261
+-----------------+-------------------------+-------------------------+-------------------------+
262-
| Philox | :math:`2^{256}` | :math:`2^{128}` | 64 |
262+
| `Philox` | :math:`2^{256}` | :math:`2^{128}` | 64 |
263263
+-----------------+-------------------------+-------------------------+-------------------------+
264264

265265
.. [3] The jump size is :math:`(\phi-1)*2^{128}` where :math:`\phi` is the

doc/source/reference/random/performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ even on 32-bit processes, this is your choice.
2424

2525
`MT19937` `fails some statistical tests`_ and is not especially
2626
fast compared to modern PRNGs. For these reasons, we mostly do not recommend
27-
using it on its own, only through the legacy `~.RandomState` for
27+
using it on its own, only through the legacy `RandomState` for
2828
reproducing old results. That said, it has a very long history as a default in
2929
many systems.
3030

doc/source/reference/random/upgrading-pcg64.rst

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

33
.. currentmodule:: numpy.random
44

5-
Upgrading ``PCG64`` with ``PCG64DXSM``
5+
Upgrading `PCG64` with `PCG64DXSM`
66
======================================
77

88
Uses of the `PCG64` `BitGenerator` in a massively-parallel context have been

numpy/random/_mt19937.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ cdef class MT19937(BitGenerator):
6767
6868
Notes
6969
-----
70-
``MT19937`` provides a capsule containing function pointers that produce
70+
`MT19937` provides a capsule containing function pointers that produce
7171
doubles, and unsigned 32 and 64- bit integers [1]_. These are not
72-
directly consumable in Python and must be consumed by a ``Generator``
72+
directly consumable in Python and must be consumed by a `Generator`
7373
or similar object that supports low-level access.
7474
7575
The Python stdlib module "random" also contains a Mersenne Twister
7676
pseudo-random number generator.
7777
7878
**State and Seeding**
7979
80-
The ``MT19937`` state vector consists of a 624-element array of
80+
The `MT19937` state vector consists of a 624-element array of
8181
32-bit unsigned integers plus a single integer value between 0 and 624
8282
that indexes the current position within the main array.
8383
@@ -111,7 +111,7 @@ cdef class MT19937(BitGenerator):
111111
112112
**Compatibility Guarantee**
113113
114-
``MT19937`` makes a guarantee that a fixed seed will always produce
114+
`MT19937` makes a guarantee that a fixed seed will always produce
115115
the same random integer stream.
116116
117117
References

0 commit comments

Comments
 (0)