dpnp.random.RandomState

class dpnp.random.RandomState(seed=None, device=None, sycl_queue=None)[source]

A container for the Mersenne Twister pseudo-random number generator.

For full documentation refer to numpy.random.RandomState.

Parameters:
  • seed ({None, int, array_like}, optional) -- A random seed to initialize the pseudo-random number generator. The seed can be None (the default), an integer scalar, or an array of at most three integer scalars.

  • device ({None, string, SyclDevice, SyclQueue}, optional) -- An array API concept of device where the output array is created. The device can be None (the default), an OneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.dpnp_array.dpnp_array.device property.

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying.

Methods

get_state()[source]

Return an internal state of the generator.

For full documentation refer to numpy.random.RandomState.get_state.

Returns:

out -- An object representing the internal state of the generator.

Return type:

object

get_sycl_device()[source]

Return an instance of dpctl.SyclDevice used within the generator to allocate data on.

Returns:

device -- A SYCL device used to allocate data on.

Return type:

dpctl.SyclDevice

get_sycl_queue()[source]

Return an instance of dpctl.SyclQueue used within the generator for data allocation.

Returns:

queue -- A SYCL queue used for data allocation.

Return type:

dpctl.SyclQueue

normal(loc=0.0, scale=1.0, size=None, dtype=None, usm_type='device')[source]

Draw random samples from a normal (Gaussian) distribution.

For full documentation refer to numpy.random.RandomState.normal.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- Drawn samples from the parameterized normal distribution. Output array data type is the same as input dtype. If dtype is None (the default), dpnp.float64 type will be used if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Limitations

Parameters loc and scale are supported as a scalar. Otherwise, numpy.random.RandomState.normal(loc, scale, size) samples are drawn. Parameter dtype is supported only as dpnp.float32, dpnp.float64 or None.

Examples

>>> s = dpnp.random.RandomState().normal(loc=3.7, scale=2.5, size=(2, 4))
>>> print(s)
[[ 1.58997253 -0.84288406  2.33836967  4.16394577]
 [ 4.40882036  5.39295758  6.48927254  6.74921661]]
rand(*args, usm_type='device')[source]

Draw random values in a given shape.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

For full documentation refer to numpy.random.RandomState.rand.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- Random values in a given shape. Output array data type is dpnp.float64 if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Examples

>>> s = dpnp.random.RandomState().rand(5, 2)
>>> print(s)
[[0.13436424 0.56920387]
 [0.84743374 0.80226506]
 [0.76377462 0.06310682]
 [0.25506903 0.1179187 ]
 [0.49543509 0.76096244]]
randint(low, high=None, size=None, dtype=<class 'int'>, usm_type='device')[source]

Draw random integers from low (inclusive) to high (exclusive).

Return random integers from the “discrete uniform” distribution of the specified type in the “half-open” interval [low, high).

For full documentation refer to numpy.random.RandomState.randint.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- size-shaped array of random integers from the appropriate distribution, or a single such random int if size is not provided. Output array data type is the same as input dtype.

Return type:

dpnp.ndarray

Limitations

Parameters low and high are supported only as a scalar. Parameter dtype is supported only as dpnp.int32 or int, but int value is considered to be exactly equivalent to dpnp.int32. Otherwise, numpy.random.RandomState.randint(low, high, size, dtype) samples are drawn.

Examples

>>> s = dpnp.random.RandomState().randint(2, size=10)
>>> print(s)
[0 1 1 1 1 0 0 0 0 1]

See also

dpnp.random.RandomState.random_integers

similar to randint, only for the closed interval [low, high], and 1 is the lowest value if high is omitted.

randn(*args, usm_type='device')[source]

Return a sample (or samples) from the "standard normal" distribution.

For full documentation refer to numpy.random.RandomState.randn.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied. Output array data type is dpnp.float64 if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Examples

>>> s = dpnp.random.RandomState().randn()
>>> print(s)
-0.84401099

Two-by-four array of samples from the normal distribution with mean 3 and standard deviation 2.5:

>>> s = dpnp.random.RandomState().randn(2, 4)
>>> print(s)
[[ 0.88997253 -1.54288406  1.63836967  3.46394577]
 [ 3.70882036  4.69295758  5.78927254  6.04921661]]
random_sample(size=None, usm_type='device')[source]

Draw random floats in the half-open interval [0.0, 1.0).

Results are from the “continuous uniform” distribution over the interval.

For full documentation refer to numpy.random.RandomState.random_sample.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- Array of random floats of shape size (if size=None, zero dimension array with a single float is returned). Output array data type is dpnp.float64 if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Examples

>>> s = dpnp.random.RandomState().random_sample(size=(4,))
>>> print(s)
[0.13436424 0.56920387 0.84743374 0.80226506]
standard_normal(size=None, usm_type='device')[source]

Draw samples from a standard Normal distribution (mean=0, stdev=1).

For full documentation refer to numpy.random.RandomState.standard_normal.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- A floating-point array of shape size of drawn samples, or a single sample if size was not specified. Output array data type is dpnp.float64 if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Examples

>>> s = dpnp.random.RandomState().standard_normal(size=(3, 5))
>>> print(s)
[[-0.84401099 -1.81715362 -0.54465213  0.18557831  0.28352814]
 [ 0.67718303  1.11570901  1.21968665 -1.18236388  0.08156915]
 [ 0.21941987 -1.24544512  0.63522211 -0.673174    0.        ]]
uniform(low=0.0, high=1.0, size=None, dtype=None, usm_type='device')[source]

Draw samples from a uniform distribution.

Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform.

For full documentation refer to numpy.random.RandomState.uniform.

Parameters:

usm_type ({"device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array.

Returns:

out -- Drawn samples from the parameterized uniform distribution. Output array data type is the same as input dtype. If dtype is None (the default), dpnp.float64 type will be used if device supports it, or dpnp.float32 otherwise.

Return type:

dpnp.ndarray

Limitations

Parameters low and high are supported as a scalar. Otherwise, numpy.random.RandomState.uniform(low, high, size) samples are drawn. Parameter dtype is supported only as dpnp.int32, dpnp.float32, dpnp.float64 or None.

Examples

>>> low, high = 1.23, 10.54    # low and high
>>> s = dpnp.random.RandomState().uniform(low, high, 5)
>>> print(s)
[2.48093112 6.52928804 9.1196081  8.6990877  8.34074171]

See also

dpnp.random.RandomState.randint

Discrete uniform distribution, yielding integers.

dpnp.random.RandomState.random_integers

Discrete uniform distribution over the closed interval [low, high].

dpnp.random.RandomState.random_sample

Floats uniformly distributed over [0, 1).

dpnp.random.RandomState.random

Alias for dpnp.random.RandomState.random_sample.

dpnp.random.RandomState.rand

Convenience function that accepts dimensions as input, e.g., rand(2, 2) would generate a 2-by-2 array of floats, uniformly distributed over [0, 1).

__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.