Random Number Generation¶
Classes for random number generation. augpy’s speciality is that all dtypes are supported for all distributions. For example, it is possible to fill an integer tensor with approximately Gaussian distributed numbers.
-
using
augpy
::
rng_t
= curandStateXORWOW_t¶
-
class
augpy
::
RandomNumberGenerator
¶ A convenient wrapper for cuRAND methods that fill tensors with pseudo-random numbers.
Public Functions
-
RandomNumberGenerator
(py::object *device_id, py::object *seed)¶ Create a new RNG instance.
device_id
andseed
may both be PythonNone
. The behavior is identical to RandomNumberGenerator(int*, unsigned long long*) withNULL
pointers.
-
RandomNumberGenerator
(int *device_id, unsigned long long *seed)¶ Create a new RNG instance.
- Parameters
device_id
: GPU device ID; ifNULL
, current_device is usedseed
: random seed; ifNULL
, read values from std::random_device to create a random seed.
-
void
uniform
(CudaTensor *target, double vmin, double vmax, unsigned int blocks_per_sm = BLOCKS_PER_SM, unsigned int num_threads = 0)¶ Fill
target
tensor with uniformly distributed numbers in \( [v_{min}, v_{max}) \).- Note
This is supported for integer tensors. Values are cast from float or double down to the integer type. The mean of the values is approximately \( \frac{v_{max} + v_{min}}{2} \).
- Warning
Saturation is not used. \( v_{min} \) and \( v_{max} \) must be representable in the target tensor data type.
- Parameters
target
: tensor to fillvmin
: minimum value; can occurvmax
: maximum value; does not occurblocks_per_sm
: number of blocks per SMnum_threads
: number of threads per block
-
void
gaussian
(CudaTensor *target, double mean, double std, unsigned int blocks_per_sm = BLOCKS_PER_SM, unsigned int num_threads = 0)¶ Fill
target
tensor with Gaussian distributed numbers with specifiedmean
and standard deviationstd
.- Note
This is supported for integer tensors. Values are drawn from the given distribution, then rounded and cast to the data type of the tensor with saturation. The values in an integer tensor are thus only approximately Gaussian distributed.
- Parameters
target
: tensor to fillmean
: Gaussian meanstd
: Gaussian standard deviationblocks_per_sm
: number of blocks per SMnum_threads
: number of threads per block
-