prrng 1.12.1
Loading...
Searching...
No Matches
prrng::pcg32_array Class Reference

Array of independent generators. More...

#include <prrng.h>

Inheritance diagram for prrng::pcg32_array:
prrng::pcg32_arrayBase< pcg32, std::vector< size_t > > prrng::GeneratorBase_array< Derived, M >

Public Types

using size_type = size_t
 Size type.
 
using shape_type = std::vector< size_t >
 Shape type.
 
- Public Types inherited from prrng::pcg32_arrayBase< pcg32, std::vector< size_t > >
using size_type = typename Shape::value_type
 Size type.
 
using shape_type = std::vector< size_t >
 Shape type.
 
- Public Types inherited from prrng::GeneratorBase_array< Derived, M >
using shape_type = M
 Type of the shape and strides lists.
 
using size_type = typename M::value_type
 Type of sizes.
 

Public Member Functions

template<class T >
 pcg32_array (const T &initstate)
 Constructor.
 
template<class T , class U >
 pcg32_array (const T &initstate, const U &initseq)
 Constructor.
 
- Public Member Functions inherited from prrng::pcg32_arrayBase< pcg32, std::vector< size_t > >
pcg32operator() (Args... args)
 Return a reference to one generator, using an array index.
 
const pcg32operator() (Args... args) const
 Return a constant reference to one generator, using an array index.
 
pcg32operator[] (size_t i)
 Return a reference to one generator, using a flat index.
 
const pcg32operator[] (size_t i) const
 Return a constant reference to one generator, using a flat index.
 
pcg32flat (size_t i)
 Return a reference to one generator, using a flat index.
 
const pcg32flat (size_t i) const
 Return a constant reference to one generator, using a flat index.
 
auto state () -> typename detail::return_type< uint64_t, std::vector< size_t > >::type
 Return the state of all generators.
 
state ()
 Return the state of all generators.
 
auto initstate () -> typename detail::return_type< uint64_t, std::vector< size_t > >::type
 Return the state initiator of all generators.
 
initstate ()
 Return the state initiator of all generators.
 
auto initseq () -> typename detail::return_type< uint64_t, std::vector< size_t > >::type
 Return the sequence initiator of all generators.
 
initseq ()
 Return the sequence initiator of all generators.
 
auto distance (const T &arg) -> typename detail::return_type< int64_t, std::vector< size_t > >::type
 Distance between two states.
 
distance (const T &arg)
 Distance between two states.
 
void advance (const T &arg)
 Advance generators.
 
void restore (const T &arg)
 Restore generators from a state.
 
- Public Member Functions inherited from prrng::GeneratorBase_array< Derived, M >
size_type size () const
 Return the size of the array of generators.
 
const shape_typestrides () const
 Return the strides of the array of generators.
 
const shape_typeshape () const
 Return the shape of the array of generators.
 
template<class T >
auto shape (T axis) const
 Return the shape of the array of generators along a specific axis.
 
template<class T >
auto flat_index (const T &index) const
 Return a flat index based on an array index specified as a list.
 
template<class T >
bool inbounds (const T &index) const
 Check if an index is in bounds (and of the correct rank).
 
template<class S >
auto random (const S &ishape) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers \( 0 \leq r \leq 1 \).
 
template<class R , class S >
random (const S &ishape)
 Per generator, generate an nd-array of random numbers \( 0 \leq r \leq 1 \).
 
template<class I , std::size_t L>
auto random (const I(&ishape)[L]) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers \( 0 \leq r \leq 1 \).
 
template<class R , class I , std::size_t L>
random (const I(&ishape)[L])
 Per generator, generate an nd-array of random numbers \( 0 \leq r \leq 1 \).
 
template<class S , typename T >
auto randint (const S &ishape, T high) -> typename detail::composite_return_type< T, M, S >::type
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class R , class S , typename T >
randint (const S &ishape, T high)
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class I , std::size_t L, typename T >
auto randint (const I(&ishape)[L], T high) -> typename detail::composite_return_type< T, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class R , class I , std::size_t L, typename T >
randint (const I(&ishape)[L], T high)
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class S , typename T , typename U >
auto randint (const S &ishape, T low, U high) -> typename detail::composite_return_type< T, M, S >::type
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class R , class S , typename T , typename U >
randint (const S &ishape, T low, U high)
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class I , std::size_t L, typename T , typename U >
auto randint (const I(&ishape)[L], T low, U high) -> typename detail::composite_return_type< T, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class R , class I , std::size_t L, typename T , typename U >
randint (const I(&ishape)[L], T low, U high)
 Per generator, generate an nd-array of random integers \( 0 \leq r \leq bound \).
 
template<class S >
auto delta (const S &ishape, double scale=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of numbers that are delta distribution.
 
template<class R , class S >
delta (const S &ishape, double scale=1)
 Per generator, generate an nd-array of numbers that are delta distribution.
 
template<class I , std::size_t L>
auto delta (const I(&ishape)[L], double scale=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of numbers that are delta distribution.
 
template<class R , class I , std::size_t L>
delta (const I(&ishape)[L], double scale=1)
 Per generator, generate an nd-array of numbers that are delta distribution.
 
template<class S >
auto exponential (const S &ishape, double scale=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to an exponential distribution.
 
template<class R , class S >
exponential (const S &ishape, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to an exponential distribution.
 
template<class I , std::size_t L>
auto exponential (const I(&ishape)[L], double scale=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to an exponential distribution.
 
template<class R , class I , std::size_t L>
exponential (const I(&ishape)[L], double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to an exponential distribution.
 
template<class S >
auto power (const S &ishape, double k=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to an power distribution.
 
template<class R , class S >
power (const S &ishape, double k=1)
 Per generator, generate an nd-array of random numbers distributed according to an power distribution.
 
template<class I , std::size_t L>
auto power (const I(&ishape)[L], double k=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to an power distribution.
 
template<class R , class I , std::size_t L>
power (const I(&ishape)[L], double k=1)
 Per generator, generate an nd-array of random numbers distributed according to an power distribution.
 
template<class S >
auto gamma (const S &ishape, double k=1, double scale=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to a Gamma distribution.
 
template<class R , class S >
gamma (const S &ishape, double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Gamma distribution.
 
template<class I , std::size_t L>
auto gamma (const I(&ishape)[L], double k=1, double scale=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to a Gamma distribution.
 
template<class R , class I , std::size_t L>
gamma (const I(&ishape)[L], double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Gamma distribution.
 
template<class S >
auto pareto (const S &ishape, double k=1, double scale=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to a Pareto distribution.
 
template<class R , class S >
pareto (const S &ishape, double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Pareto distribution.
 
template<class I , std::size_t L>
auto pareto (const I(&ishape)[L], double k=1, double scale=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to a Pareto distribution.
 
template<class R , class I , std::size_t L>
pareto (const I(&ishape)[L], double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Pareto distribution.
 
template<class S >
auto weibull (const S &ishape, double k=1, double scale=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to a Weibull distribution.
 
template<class R , class S >
weibull (const S &ishape, double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Weibull distribution.
 
template<class I , std::size_t L>
auto weibull (const I(&ishape)[L], double k=1, double scale=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to a Weibull distribution.
 
template<class R , class I , std::size_t L>
weibull (const I(&ishape)[L], double k=1, double scale=1)
 Per generator, generate an nd-array of random numbers distributed according to a Weibull distribution.
 
template<class S >
auto normal (const S &ishape, double mu=0, double sigma=1) -> typename detail::composite_return_type< double, M, S >::type
 Per generator, generate an nd-array of random numbers distributed according to a normal distribution.
 
template<class R , class S >
normal (const S &ishape, double mu=0, double sigma=1)
 Per generator, generate an nd-array of random numbers distributed according to a normal distribution.
 
template<class I , std::size_t L>
auto normal (const I(&ishape)[L], double mu=0, double sigma=1) -> typename detail::composite_return_type< double, M, std::array< size_t, L > >::type
 Per generator, generate an nd-array of random numbers distributed according to a normal distribution.
 
template<class R , class I , std::size_t L>
normal (const I(&ishape)[L], double mu=0, double sigma=1)
 Per generator, generate an nd-array of random numbers distributed according to a normal distribution.
 
template<class T >
auto cumsum_random (const T &n) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers.
 
template<class R , class T >
cumsum_random (const T &n)
 Per generator, return the result of the cumulative sum of n random numbers.
 
template<class T >
auto cumsum_delta (const T &n, double scale=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a delta distribution,.
 
template<class R , class T >
cumsum_delta (const T &n, double scale=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a delta distribution,.
 
template<class T >
auto cumsum_exponential (const T &n, double scale=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to an exponential distribution, see exponential_distribution(),.
 
template<class R , class T >
cumsum_exponential (const T &n, double scale=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to an exponential distribution, see exponential_distribution(),.
 
template<class T >
auto cumsum_power (const T &n, double k=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to an power distribution, see power_distribution(),.
 
template<class R , class T >
cumsum_power (const T &n, double k=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to an power distribution, see power_distribution(),.
 
template<class T >
auto cumsum_gamma (const T &n, double k=1, double scale=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a gamma distribution, see gamma_distribution(),.
 
template<class R , class T >
cumsum_gamma (const T &n, double k=1, double scale=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a gamma distribution, see gamma_distribution(),.
 
template<class T >
auto cumsum_pareto (const T &n, double k=1, double scale=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a pareto distribution, see pareto_distribution(),.
 
template<class R , class T >
cumsum_pareto (const T &n, double k=1, double scale=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a pareto distribution, see pareto_distribution(),.
 
template<class T >
auto cumsum_weibull (const T &n, double k=1, double scale=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a weibull distribution, see weibull_distribution(),.
 
template<class R , class T >
cumsum_weibull (const T &n, double k=1, double scale=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a weibull distribution, see weibull_distribution(),.
 
template<class T >
auto cumsum_normal (const T &n, double mu=0, double sigma=1) -> typename detail::return_type< double, M >::type
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a normal distribution, see normal_distribution(),.
 
template<class R , class T >
cumsum_normal (const T &n, double mu=0, double sigma=1)
 Per generator, return the result of the cumulative sum of n random numbers, distributed according to a normal distribution, see normal_distribution(),.
 
template<class P >
auto decide (const P &p) -> typename detail::return_type< bool, P >::type
 Decide based on probability per generator.
 
template<class P , class R >
decide (const P &p)
 Decide based on probability per generator.
 
template<class P , class R >
void decide (const P &p, R &ret)
 Decide based on probability per generator.
 
template<class P , class T >
auto decide_masked (const P &p, const T &mask) -> typename detail::return_type< bool, P >::type
 Decide based on probability per generator.
 
template<class P , class T , class R >
decide_masked (const P &p, const T &mask)
 Decide based on probability per generator.
 
template<class P , class T , class R >
void decide_masked (const P &p, const T &mask, R &ret)
 Decide based on probability per generator.
 

Additional Inherited Members

- Protected Member Functions inherited from prrng::pcg32_arrayBase< pcg32, std::vector< size_t > >
void init (const T &initstate)
 Constructor alias.
 
void init (const T &initstate, const U &initseq)
 Constructor alias.
 
void decide_impl (const double *p, bool *ret)
 For each p take a decision.
 
void decide_masked_impl (const double *p, const bool *mask, bool *ret)
 For each p take a decision.
 
void cumsum_random_impl (double *ret, const size_t *n)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_exponential_impl (double *ret, const size_t *n, double scale)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_power_impl (double *ret, const size_t *n, double k)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_gamma_impl (double *ret, const size_t *n, double k, double scale)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_pareto_impl (double *ret, const size_t *n, double k, double scale)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_weibull_impl (double *ret, const size_t *n, double k, double scale)
 Return the result of the cumulative sum of n random numbers.
 
void cumsum_normal_impl (double *ret, const size_t *n, double mu, double sigma)
 Return the result of the cumulative sum of n random numbers.
 
void draw_list_double (double *data, size_t n)
 Draw n random numbers per array item, and write them to the correct position in data (assuming row-major storage!).
 
void draw_list_positive_double (double *data, size_t n)
 Draw n random numbers per array item, and write them to the correct position in data (assuming row-major storage!).
 
void draw_list_uint32 (uint32_t *data, uint32_t bound, size_t n)
 Draw n random numbers per array item, and write them to the correct position in data (assuming row-major storage!).
 
- Protected Attributes inherited from prrng::pcg32_arrayBase< pcg32, std::vector< size_t > >
std::vector< pcg32m_gen
 Underlying storage: one generator per array item.
 
- Protected Attributes inherited from prrng::GeneratorBase_array< Derived, M >
size_type m_size = 0
 See size().
 
shape_type m_shape
 See shape().
 
shape_type m_strides
 The strides of the array of generators.
 

Detailed Description

Array of independent generators.

The idea is that each array-entry has its own random sequence, initiated by its own seed. An array of random numbers can then be generated whose shape if composed of the shape, the shape of the array of generators, followed by the desired shape of the random sequence draw per generator. Let us consider an example. Suppose that we have a list of n = 5 generators, and we want to generate i = 8 random numbers for each generator. Then the output will be collected in a matrix of shape [n, i] = [5, 8] where each row corresponds to a generator and the columns for that row are the random sequence generated by that generator. Since this class is general, you can also imagine an array of [m, n, o, p] generators with a random sequence reshaped in a (row-major) array of shape [a, b, c, d, e]. The output is then collected in an array of shape [m, n, o, p, a, b, c, d, e].

Note that a reference to each generator can be obtained using the [] and () operators, e.g. generators[flat_index] and generators(i, j, k, ...). All functions of pcg32() can be used for each reference. In addition, convenience functions state(), initstate(), initseq(), restore() are provided here to store/restore the state of the entire array of generators.

Definition at line 5558 of file prrng.h.

Member Typedef Documentation

◆ shape_type

using prrng::pcg32_array::shape_type = std::vector<size_t>

Shape type.

Definition at line 5564 of file prrng.h.

◆ size_type

Size type.

Definition at line 5563 of file prrng.h.

Constructor & Destructor Documentation

◆ pcg32_array() [1/2]

template<class T >
prrng::pcg32_array::pcg32_array ( const T &  initstate)
inline

Constructor.

Parameters
initstateState initiator for every item (accept default sequence initiator). The shape of the argument determines the shape of the generator array.

Definition at line 5575 of file prrng.h.

◆ pcg32_array() [2/2]

template<class T , class U >
prrng::pcg32_array::pcg32_array ( const T &  initstate,
const U &  initseq 
)
inline

Constructor.

Parameters
initstateState initiator for every item.
initseqSequence initiator for every item. The shape of these argument determines the shape of the generator array.

Definition at line 5590 of file prrng.h.


The documentation for this class was generated from the following file: