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.

class augpy.RandomNumberGenerator(device_id: object = None, seed: object = None)[source]

Bases: augpy._augpy.pybind11_object

A convenient wrapper for cuRAND methods that fill tensors with pseudo-random numbers.

Parameters
__init__(self: augpy._augpy.'RandomNumberGenerator', device_id: object = None, seed: object = None)None[source]
Return type

None

gaussian(self: augpy._augpy.'RandomNumberGenerator', target: augpy._augpy.CudaTensor, mean: float = 0.0, std: float = 1.0, blocks_per_sm: int = 8, threads: int = 0)None[source]

Fill target tensor with Gaussian distributed numbers with specified mean and standard deviation std.

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 (CudaTensor) – tensor to fill

  • mean (float) – Gaussian mean

  • std (float) – Gaussian standard deviation

Return type

None

uniform(self: augpy._augpy.'RandomNumberGenerator', target: augpy._augpy.CudaTensor, vmin: float, vmax: float, blocks_per_sm: int = 8, threads: int = 0)None[source]

Fill target tensor with uniformly distributed number in \([v_{min}, v_{max})\).

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 :math:`

rac{v_{max} + v_{min}}{2}`.

Saturation is not used. \(v_{min}\) and \(v_{max}\) must be representable in the target tensor data type, else values may under or overflow.

Parameters:

target: tensor to fill vmin: minimum value; can occur vmax: maximum value; does not occur

rtype

None