cuRAND¶
Provides pseudo-random number generator (PRNG) and quasi-random generator (QRNG). See NVIDIA cuRAND.
class PRNG¶
-
class
pyculib.rand.
PRNG
(rndtype=100, seed=None, offset=None, stream=None)¶ cuRAND pseudo random number generator
Parameters: - rndtype – Algorithm type. All possible values are listed as class attributes of this class, e.g. TEST, DEFAULT, XORWOW, MRG32K3A, MTGP32.
- seed – Seed for the RNG.
- offset – Offset to the random number stream.
- stream – CUDA stream.
Example:
>>> from pyculib import rand >>> from numpy import empty >>> prng = rand.PRNG(rndtype=rand.PRNG.XORWOW) >>> r = empty(10) >>> prng.uniform(r) >>> r array([ ... ])
-
lognormal
(ary, mean, sigma, size=None)¶ - Generate floating point random number sampled
- from a log-normal distribution and fill into ary.
Parameters: - ary – Numpy array or cuda device array.
- mean – Center of the distribution.
- sigma – Standard deviation of the distribution.
- size – Number of samples. Default to array size.
-
normal
(ary, mean, sigma, size=None)¶ Generate floating point random number sampled from a normal distribution and fill into ary.
Parameters: - ary – Numpy array or cuda device array.
- mean – Center of the distribution.
- sigma – Standard deviation of the distribution.
- size – Number of samples. Default to array size.
-
poisson
(ary, lmbd, size=None)¶ Generate floating point random number sampled from a poisson distribution and fill into ary.
Parameters: - ary – Numpy array or cuda device array.
- lmbda – Lambda for the distribution.
- size – Number of samples. Default to array size.
-
seed
¶ Mutatable attribute for the seed for the RNG
-
uniform
(ary, size=None)¶ - Generate floating point random number sampled
- from a uniform distribution and fill into ary.
Parameters: - ary – Numpy array or cuda device array.
- size – Number of samples. Default to array size.
class QRNG¶
-
class
pyculib.rand.
QRNG
(rndtype=200, ndim=None, offset=None, stream=None)¶ cuRAND quasi random number generator
Parameters: - rndtype – Algorithm type. Also control output data type. All possible values are listed as class attributes of this class, e.g. TEST, DEFAULT, SOBOL32, SCRAMBLED_SOBOL32, SOBOL64, SCRAMABLED_SOBOL64.
- ndim – Number of dimension for the QRNG.
- offset – Offset to the random number stream.
- stream – CUDA stream.
-
generate
(ary, size=None)¶ Generate quasi random number in ary.
Parameters: - ary – Numpy array or cuda device array.
- size – Number of samples; Default to array size. Must be multiple of ndim.
-
ndim
¶ Mutatable attribute for number of dimension for the QRNG.
Top Level PRNG Functions¶
Simple interface to the PRNG methods.
Note
This methods automatically create a PRNG object.
-
pyculib.rand.
uniform
(size, dtype=<class 'float'>, device=False)¶ Generate floating point random number sampled from a uniform distribution
Parameters: - size – Number of samples.
- dtype – np.float32 or np.float64.
- device – Set to True to return a device array instead or numpy array.
Returns: A numpy array or a device array.
>>> from pyculib import rand >>> rand.uniform(size=10) array([...])
See also
-
pyculib.rand.
normal
(mean, sigma, size, dtype=<class 'float'>, device=False)¶ Generate floating point random number sampled from a normal distribution
Parameters: - mean – Center point of the distribution.
- sigma – Standard deviation of the distribution.
- size – — Number of samples.
- dtype – np.float32 or np.float64.
- device – Set to True to return a device array instead or ndarray.
Returns: A numpy array or a device array.
>>> from pyculib import rand >>> rand.normal(mean=0, sigma=1, size=10) array([...])
See also
-
pyculib.rand.
lognormal
(mean, sigma, size, dtype=<class 'float'>, device=False)¶ Generate floating point random number sampled from a log-normal distribution.
Parameters: - mean – Center point of the distribution.
- sigma – Standard deviation of the distribution.
- size – Number of samples.
- dtype – np.float32 or np.float64.
- device – set to True to return a device array instead or ndarray.
Returns: A numpy array or a device array.
>>> from pyculib import rand >>> rand.lognormal(mean=0, sigma=1, size=10) array([...])
See also
-
pyculib.rand.
poisson
(lmbd, size, device=False)¶ Generate int32 random number sampled from a poisson distribution.
Parameters: - lmbda – Lambda of the distribution.
- size – Number of samples
- device – Set to True to return a device array instead or ndarray.
Returns: A numpy array or a device array.
>>> from pyculib import rand >>> rand.poisson(lmbd=1, size=10) array([...], dtype=uint32)
See also
Top Level QRNG Functions¶
Simple interface to the QRNG methods.
Note
This methods automatically create a QRNG object.
-
pyculib.rand.
quasi
(size, bits=32, nd=1, device=False)¶ Generate quasi random number using SOBOL{bits} RNG type.
Parameters: - size – Number of samples.
- bits – Bit length of output element; e.g. 32 or 64.
- nd – Number of dimension .
- device – Set to True to return a device array instead or ndarray.
Returns: A numpy array or a device array.
>>> from pyculib import rand >>> rand.quasi(10) array([...], dtype=uint32)
See also