arrayfire.random module¶
Random engine class and functions to generate random numbers.
-
class
arrayfire.random.
Random_Engine
(engine_type=<RANDOM_ENGINE.PHILOX_4X32_10: 100>, seed=0, engine=None)[source]¶ Bases:
object
Class to handle random number generator engines.
Parameters: engine_type : optional: RANDOME_ENGINE. default: RANDOM_ENGINE.PHILOX
- Specifies the type of random engine to be created. Can be one of:
- RANDOM_ENGINE.PHILOX_4X32_10
- RANDOM_ENGINE.THREEFRY_2X32_16
- RANDOM_ENGINE.MERSENNE_GP11213
- RANDOM_ENGINE.PHILOX (same as RANDOM_ENGINE.PHILOX_4X32_10)
- RANDOM_ENGINE.THREEFRY (same as RANDOM_ENGINE.THREEFRY_2X32_16)
- RANDOM_ENGINE.DEFAULT
- Not used if engine is not None
seed : optional int. default: 0
- Specifies the seed for the random engine
- Not used if engine is not None
engine : optional ctypes.c_void_p. default: None.
- Used a handle created by the C api to create the Random_Engine.
Methods
get_seed
()Get the seed for the random engine. get_type
()Get the type of the random engine. set_seed
(seed)Set the seed for the random engine. set_type
(engine_type)Set the type of the random engine.
-
arrayfire.random.
get_default_random_engine
()[source]¶ Get the default random engine
Returns: The default random engine used by randu and randn
-
arrayfire.random.
get_seed
()[source]¶ Get the seed for the random number generator.
Returns: seed: int.
Seed for the random number generator
-
arrayfire.random.
randn
(d0, d1=None, d2=None, d3=None, dtype=<Dtype.f32: 0>, engine=None)[source]¶ Create a multi dimensional array containing values from a normal distribution.
Parameters: d0 : int.
Length of first dimension.
d1 : optional: int. default: None.
Length of second dimension.
d2 : optional: int. default: None.
Length of third dimension.
d3 : optional: int. default: None.
Length of fourth dimension.
dtype : optional: af.Dtype. default: af.Dtype.f32.
Data type of the array.
engine : optional: Random_Engine. default: None.
If engine is None, uses a default engine created by arrayfire.
Returns: out : af.Array
Multi dimensional array whose elements are sampled from a normal distribution with mean 0 and sigma of 1. - If d1 is None, out is 1D of size (d0,). - If d1 is not None and d2 is None, out is 2D of size (d0, d1). - If d1 and d2 are not None and d3 is None, out is 3D of size (d0, d1, d2). - If d1, d2, d3 are all not None, out is 4D of size (d0, d1, d2, d3).
-
arrayfire.random.
randu
(d0, d1=None, d2=None, d3=None, dtype=<Dtype.f32: 0>, engine=None)[source]¶ Create a multi dimensional array containing values from a uniform distribution.
Parameters: d0 : int.
Length of first dimension.
d1 : optional: int. default: None.
Length of second dimension.
d2 : optional: int. default: None.
Length of third dimension.
d3 : optional: int. default: None.
Length of fourth dimension.
dtype : optional: af.Dtype. default: af.Dtype.f32.
Data type of the array.
engine : optional: Random_Engine. default: None.
If engine is None, uses a default engine created by arrayfire.
Returns: out : af.Array
Multi dimensional array whose elements are sampled uniformly between [0, 1]. - If d1 is None, out is 1D of size (d0,). - If d1 is not None and d2 is None, out is 2D of size (d0, d1). - If d1 and d2 are not None and d3 is None, out is 3D of size (d0, d1, d2). - If d1, d2, d3 are all not None, out is 4D of size (d0, d1, d2, d3).
-
arrayfire.random.
set_default_random_engine_type
(engine_type)[source]¶ Set random engine type for default random engine.
Parameters: engine_type : RANDOME_ENGINE.
- Specifies the type of random engine to be created. Can be one of:
- RANDOM_ENGINE.PHILOX_4X32_10
- RANDOM_ENGINE.THREEFRY_2X32_16
- RANDOM_ENGINE.MERSENNE_GP11213
- RANDOM_ENGINE.PHILOX (same as RANDOM_ENGINE.PHILOX_4X32_10)
- RANDOM_ENGINE.THREEFRY (same as RANDOM_ENGINE.THREEFRY_2X32_16)
- RANDOM_ENGINE.DEFAULT