template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
tk::RNGSSE class

RNGSSE-based random number generator used polymorphically with tk::RNG.

Constructors, destructors, conversion operators

RNGSSE(SeqNumType n, InitFn fnShort, ctr::RNGSSESeqLenType seqlen = ctr::RNGSSESeqLenType::SHORT, InitFn fnLong = nullptr, InitFn fnMed = nullptr) explicit
RNGSSE(const RNGSSE& x)
Copy constructor: in terms of copy assignment.
RNGSSE(RNGSSE&& x)
Move constructor: in terms of move assignment.

Public functions

void uniform(int tid, ncomp_t num, double* r) const
void gaussian(int tid, ncomp_t num, double* r) const
void gaussianmv(int tid, ncomp_t num, ncomp_t d, const double*const mean, const double*const cov, double* r) const
Multi-variate Gaussian RNG: Generate multi-variate Gaussian random numbers.
void beta(int tid, ncomp_t num, double p, double q, double a, double b, double* r) const
void gamma(int tid, ncomp_t num, double a, double b, double* r) const
auto operator=(const RNGSSE& x) -> RNGSSE&
Copy assignment.
auto operator=(RNGSSE&& x) -> RNGSSE&
Move assignment.
auto nthreads() const -> SeqNumType noexcept
Accessor to the number of threads we operate on.

Function documentation

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
tk::RNGSSE<State, SeqNumType, Generate>::RNGSSE(SeqNumType n, InitFn fnShort, ctr::RNGSSESeqLenType seqlen = ctr::RNGSSESeqLenType::SHORT, InitFn fnLong = nullptr, InitFn fnMed = nullptr) explicit

Parameters
in Initialize RNG using this many independent streams
fnShort in RNG initializer function for short streams
seqlen in Sequence length enum: short, medium or long
fnLong in RNG initializer function for long streams
fnMed in RNG initializer function for medium streams

Constructor

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk::RNGSSE<State, SeqNumType, Generate>::uniform(int tid, ncomp_t num, double* r) const

Parameters
tid in Thread (or more precisely) stream ID
num in Number of RNGs to generate
in/out Pointer to memory to write the random numbers to

Uniform RNG: Generate uniform random numbers

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk::RNGSSE<State, SeqNumType, Generate>::gaussian(int tid, ncomp_t num, double* r) const

Parameters
tid in Thread (or more precisely stream) ID
num in Number of RNGs to generate
in/out Pointer to memory to write the random numbers to

Gaussian RNG: Generate Gaussian random numbers Generating Gaussian random numbers is implemented via an adaptor, modeling std::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to Gaussian ones, to the standard library. The adaptor is instantiated here because a standard distribution, such as e.g., std::normal_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state. Even though creating the adaptor seems like a potentially costly operation for every call, using the standard library implementation is still faster than a hand-coded implementation of the Box-Muller algorithm. Note that libc++ uses a cache, as Box-Muller, implemented using the polar algorithm generates 2 Gaussian numbers for each pair of uniform ones, caching every 2nd.

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk::RNGSSE<State, SeqNumType, Generate>::gaussianmv(int tid, ncomp_t num, ncomp_t d, const double*const mean, const double*const cov, double* r) const

Multi-variate Gaussian RNG: Generate multi-variate Gaussian random numbers.

Parameters
tid in Thread (or more precisely stream) ID
num in Number of RNGs to generate
in Dimension d ( d ≥ 1) of output random vectors
mean in Mean vector of dimension d
cov in Lower triangle of covariance matrix, stored as a vector of length d(d+1)/2
in/out Pointer to memory to write the random numbers to

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk::RNGSSE<State, SeqNumType, Generate>::beta(int tid, ncomp_t num, double p, double q, double a, double b, double* r) const

Parameters
tid in Thread (or more precisely stream) ID
num in Number of RNGs to generate
in First beta shape parameter
in Second beta shape parameter
in Beta displacement parameter
in Beta scale factor
in/out Pointer to memory to write the random numbers to

Beta RNG: Generate beta random numbers Generating beta-distributed random numbers is implemented via an adaptor, modeling boost::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to beta-distributed ones, to boost::random. The adaptor is instantiated here because a boost random number distribution, such as e.g., boost::random::beta_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state.

template<class State, typename SeqNumType, unsigned int(*)(State*) Generate>
void tk::RNGSSE<State, SeqNumType, Generate>::gamma(int tid, ncomp_t num, double a, double b, double* r) const

Parameters
tid in Thread (or more precisely stream) ID
num in Number of RNGs to generate
in Gamma shape parameter
in Gamma scale factor
in/out Pointer to memory to write the random numbers to

Gamma RNG: Generate gamma random numbers Generating gamma-distributed random numbers is implemented via an adaptor, modeling boost::UniformRandomNumberGenerator, outsourcing the transformation of uniform random numbers to gamma-distributed ones, to boost::random. The adaptor is instantiated here because a boost random number distribution, such as e.g., boost::random::gamma_distribution, generates numbers using operator() with no arguments, thus the RNG state and the thread ID (this latter only known here) must be stored in the adaptor functor's state.