Random sampling (dpnp.random)¶
DPNP draws random numbers on the SYCL device, with the counter-based
Philox4x32x10 generator of the oneMKL device RNG API (oneMath's in a
oneMath build). It provides the Generator API of NumPy,
recommended for new code. The legacy RandomState API and the
module-level functions still use the host-side oneMKL RNG.
import dpnp
rng = dpnp.random.default_rng(seed=42)
x = rng.standard_normal((3, 4)) # on the default device
y = rng.random(5, usm_type="shared")
rng = dpnp.random.default_rng(42, device="cpu")
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
dpnp.ndarray, zero-dimensional when size is None.
Differences from NumPy¶
The streams differ from NumPy's. For a given seed, output size and data type, the raw bits and the uniform floats are the same on every device, while the normal samples agree to a few ULP.
The values depend on the output size: a draw is not a prefix of a larger one, and two draws of
nvalues differ from one draw of2 * n. Code splitting its draws into chunks gets other values.The floating-point distributions take a
dtypekeyword, as in CuPy, which defaults to the default floating-point type of the device, so on a device without double precision the same seed gives other values by default.All methods take a
usm_typekeyword. Withusm_type=None, the 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
dpnp.ndarrayare not, since that would wait for the device. Invalid ones give undefined values, such as NaN.Parameters given as lists or NumPy arrays are copied to the device first, which waits for the work already submitted to the queue. Scalars and
dpnp.ndarrayparameters don't wait.Generators and bit generators cannot be pickled or deep-copied, and the bit generators have no
advanceorjumpedmethod.
Random Generator¶
Construct a new |
|
A container for the bit generator and the distribution samplers. |
Accessing the bit generator and spawning¶
The bit generator used by the generator. |
|
Create new independent child generators on the same SYCL queue. |
|
The SYCL device samples are drawn on. |
|
The SYCL queue samples are drawn on. |
Simple random data¶
Return random floats in the half-open interval [0.0, 1.0). |
Distributions¶
Draw samples from a normal (Gaussian) distribution. |
|
Draw samples from a standard normal distribution. |
|
Draw samples from a uniform distribution over [low, high). |
Bit generators¶
Base class for the bit generators of |
|
The lock guarding the state of the bit generator. |
|
Return raw 64-bit outputs of the bit generator. |
|
The seed sequence used to initialize the bit generator, or |
|
Create new independent child bit generators on the same SYCL queue. |
|
Get or set the state of the bit generator, as a dictionary. |
|
The SYCL device arrays are created on. |
|
The SYCL queue arrays are created on. |
|
A Philox4x32-10 counter-based bit generator on the device. |
|
Get or set the state of the bit generator. |
|
SeedSequence mixes sources of entropy in a reproducible way to set the initial state for independent and very probably non-overlapping BitGenerators. |
Legacy random generation¶
Simple random data¶
Random values in a given shape. |
|
Return a sample (or samples) from the "standard normal" distribution. |
|
Return random integers from low (inclusive) to high (exclusive). |
|
Random integers between low and high, inclusive. |
|
Return random floats in the half-open interval [0.0, 1.0). |
|
Return random floats in the half-open interval [0.0, 1.0). |
|
Return random floats in the half-open interval [0.0, 1.0). |
|
Return random floats in the half-open interval [0.0, 1.0). |
|
Generates a random sample from a given 1-D array. |
|
Return random bytes. |
Permutations¶
Modify a sequence in-place by shuffling its contents. |
|
Randomly permute a sequence, or return a permuted range. |
Distributions¶
Draw samples from a Beta distribution. |
|
Draw samples from a binomial distribution. |
|
Draw samples from a chi-square distribution. |
|
Draw samples from the Dirichlet distribution. |
|
Draw samples from an exponential distribution. |
|
Draw samples from an F distribution. |
|
Draw samples from a Gamma distribution. |
|
Draw samples from the geometric distribution. |
|
Draw samples from a Gumbel distribution. |
|
Draw samples from a Hypergeometric distribution. |
|
Draw samples from the Laplace or double exponential distribution with specified location (or mean) and scale (decay). |
|
Draw samples from a logistic distribution. |
|
Draw samples from a log-normal distribution. |
|
Draw samples from a logarithmic series distribution. |
|
Draw samples from a multinomial distribution. |
|
Draw random samples from a multivariate normal distribution. |
|
Draw samples from a negative binomial distribution. |
|
Draw samples from a non-central chi-square distribution. |
|
Draw samples from the non-central F distribution. |
|
Draw random samples from a normal (Gaussian) distribution. |
|
Draw samples from a Pareto II or Lomax distribution with specified shape. |
|
Draw samples from a Poisson distribution. |
|
Draws samples in [0, 1] from a power distribution with positive exponent a - 1. |
|
Draw samples from a Rayleigh distribution. |
|
Draw samples from a standard Cauchy distribution with mode = 0. |
|
Draw samples from the standard exponential distribution. |
|
Draw samples from a standard Gamma distribution. |
|
Draw samples from a standard Normal distribution |
|
Draw samples from a standard Student’s t distribution with df degrees of freedom. |
|
Draw samples from the triangular distribution over the interval [left, right]. |
|
Draw samples from a uniform distribution. |
|
Draw samples from a von Mises distribution. |
|
Draw samples from a Wald, or inverse Gaussian, distribution. |
|
Draw samples from a Weibull distribution. |
|
Returns an array of samples drawn from the Zipf distribution. |
RandomState¶
A container for the Mersenne Twister pseudo-random number generator. |
|
Reseed a legacy MT19937 random number generator engine. |