random.rst 2.89 KB
Newer Older
root's avatar
root committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
.. module:: cupy.random

Random sampling (:mod:`cupy.random`)
====================================

Differences between :mod:`cupy.random` and :mod:`numpy.random`:

* Most functions under :mod:`cupy.random` support the ``dtype`` option, which do not exist in the corresponding NumPy APIs.
  This option enables generation of float32 values directly without any space overhead.
* :func:`cupy.random.default_rng` uses XORWOW bit generator by default.
* Random states cannot be serialized. See the description below for details.
* CuPy does not guarantee that the same number generator is used across major versions.
  This means that numbers generated by :mod:`cupy.random` by new major version may not be the same as the previous one, even if the same seed and distribution are used.

.. currentmodule:: cupy.random

New Random Generator API
------------------------

.. Hint:: `NumPy API Reference: Random sampling (numpy.random) <https://numpy.org/doc/stable/reference/random/>`_

Random Generator
~~~~~~~~~~~~~~~~

.. Hint:: `NumPy API Reference: Random Generator <https://numpy.org/doc/stable/reference/random/generator.html>`_

.. autosummary::
   :toctree: generated/

   default_rng
   Generator

Bit Generators
~~~~~~~~~~~~~~

.. Hint:: `NumPy API Reference: Bit Generators <https://numpy.org/doc/stable/reference/random/bit_generators/index.html>`_

.. autosummary::
   :toctree: generated/

   BitGenerator

CuPy provides the following bit generator implementations:

.. autosummary::
   :toctree: generated/

   XORWOW
   MRG32k3a
   Philox4x3210

Legacy Random Generation
------------------------

.. Hint::
   * `NumPy API Reference: Legacy Random Generation <https://numpy.org/doc/stable/reference/random/legacy.html>`_
   * `NumPy 1.16 Reference <https://numpy.org/doc/1.16/reference/routines.random.html>`_

.. autosummary::
   :toctree: generated/

   RandomState

Functions in :mod:`cupy.random`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autosummary::
   :toctree: generated/

   beta
   binomial
   bytes
   chisquare
   choice
   dirichlet
   exponential
   f
   gamma
   geometric
   gumbel
   hypergeometric
   laplace
   logistic
   lognormal
   logseries
   multinomial
   multivariate_normal
   negative_binomial
   noncentral_chisquare
   noncentral_f
   normal
   pareto
   permutation
   poisson
   power
   rand
   randint
   randn
   random
   random_integers
   random_sample
   ranf
   rayleigh
   sample
   seed
   shuffle
   standard_cauchy
   standard_exponential
   standard_gamma
   standard_normal
   standard_t
   triangular
   uniform
   vonmises
   wald
   weibull
   zipf

CuPy does not provide ``cupy.random.get_state`` nor ``cupy.random.set_state`` at this time.
Use the following CuPy-specific APIs instead.
Note that these functions use :class:`cupy.random.RandomState` instance to represent the internal state, which cannot be serialized.

.. autosummary::
   :toctree: generated/

   get_random_state
   set_random_state