prrng 1.12.1
Loading...
Searching...
No Matches
prrng::pcg32_cumsum< Data > Class Template Reference

Generator of a random cumulative sum of which a chunk is kept in memory. More...

#include <prrng.h>

Public Member Functions

template<class R , typename T = uint64_t, typename S = uint64_t>
 pcg32_cumsum (const R &shape, T initstate=0x853c49e6748fea9bULL, S initseq=0xda3e39cb94b95bdbULL, enum distribution distribution=distribution::custom, const std::vector< double > &parameters=std::vector< double >{}, const alignment &align=alignment())
 
void set_functions (std::function< Data(size_t)> get_chunk, std::function< double(size_t)> get_cumsum, bool uses_generator=true)
 Use external functions to draw the random numbers.
 
 pcg32_cumsum (const pcg32_cumsum &other)
 Copy constructor.
 
void operator= (const pcg32_cumsum &other)
 Copy constructor.
 
bool is_extendible () const
 true if the chunk is extendible.
 
const pcg32_indexgenerator () const
 Pointer to the generator.
 
const auto & shape () const
 Shape of the chunk.
 
auto size () const
 Size of the chunk.
 
template<class T >
pcg32_cumsumoperator+= (const T &value)
 Add value(s) to the chunk.
 
template<class T >
pcg32_cumsumoperator-= (const T &value)
 Subtract value(s) from the chunk.
 
const Data & data () const
 The current chunk of the cumsum of random numbers.
 
void set_data (const Data &data)
 Overwrite the current chunk of the cumsum of random numbers.
 
ptrdiff_t start () const
 Global index of the first element in the chunk.
 
void set_start (ptrdiff_t index)
 Set global index of the first element in the chunk.
 
ptrdiff_t index_at_align () const
 Global index of target (the last time prrng::pcg32_cumsum::align() was called).
 
ptrdiff_t chunk_index_at_align () const
 Index of target relative to the beginning of the chunk (the last time prrng::pcg32_cumsum::align() was called).
 
double left_of_align () const
 Return the value of the cumsum left of the target (the last time prrng::pcg32_cumsum::align() was called).
 
double right_of_align () const
 Return the value of the cumsum right of the target (the last time prrng::pcg32_cumsum::align() was called).
 
uint64_t state_at (ptrdiff_t index)
 The current "state" of the generator.
 
void restore (uint64_t state, double value, ptrdiff_t index)
 Restore a specific state in the cumulative sum.
 
bool contains (double target) const
 Check if the chunk contains a target.
 
void prev (size_t margin=0)
 Shift chunk left.
 
void next (size_t margin=0)
 Shift chunk right.
 
void align (double target)
 Align the chunk to encompass a target value.
 

Detailed Description

template<class Data>
class prrng::pcg32_cumsum< Data >

Generator of a random cumulative sum of which a chunk is kept in memory.

The random number generated by the pcg32 algorithm.

Suppose that cumsum is the unlimited cumulative of random numbers starting from a seed, then a chunk gen.data() == cumsum[gen.start() : gen.start() + gen.size()] is kept in memory by this class. The chunk that is kept in memory can be changed by calling:

Note that if the current chunk is far away from the seed a quick way to restore it without drawing all random numbers from the seed is to call prrng::pcg32_cumsum::restore(). Note that you need to know one value and its index.

Template Parameters
Storageof the data.

Definition at line 3504 of file prrng.h.

Constructor & Destructor Documentation

◆ pcg32_cumsum() [1/2]

template<class Data >
template<class R , typename T = uint64_t, typename S = uint64_t>
prrng::pcg32_cumsum< Data >::pcg32_cumsum ( const R &  shape,
initstate = 0x853c49e6748fea9bULL,
initseq = 0xda3e39cb94b95bdbULL,
enum distribution  distribution = distribution::custom,
const std::vector< double > &  parameters = std::vector<double>{},
const alignment align = alignment() 
)
inline
Parameters
shapeShape of the chunk.
initstateState initiator.
initseqSequence initiator.
distributionDistribution type, see prrng::distribution().
parametersParameters for the distribution. The following is default (and the expected order):

Warning: if you want to use a custom distribution, you have to call prrng::pcg32_cumsum::set_functions().

Parameters
alignAlignment parameters, see prrng::alignment().

Definition at line 3648 of file prrng.h.

◆ pcg32_cumsum() [2/2]

template<class Data >
prrng::pcg32_cumsum< Data >::pcg32_cumsum ( const pcg32_cumsum< Data > &  other)
inline

Copy constructor.

This function resets all internal pointers.

Parameters
otherObject to copy.

Definition at line 3702 of file prrng.h.

Member Function Documentation

◆ align()

template<class Data >
void prrng::pcg32_cumsum< Data >::align ( double  target)
inline

Align the chunk to encompass a target value.

After this call:

Parameters
targetTarget value.

Definition at line 3945 of file prrng.h.

◆ chunk_index_at_align()

template<class Data >
ptrdiff_t prrng::pcg32_cumsum< Data >::chunk_index_at_align ( ) const
inline

Index of target relative to the beginning of the chunk (the last time prrng::pcg32_cumsum::align() was called).

The currently held chunk of the cumsum of random numbers is is gen.data(). As such,

  • gen.left_of_align() == gen.data()[gen.chunk_index_at_align()] <= target.
  • gen.right_of_align() == gen.data()[gen.chunk_index_at_align() + 1] > target.
Returns
Local index.

Definition at line 3842 of file prrng.h.

◆ contains()

template<class Data >
bool prrng::pcg32_cumsum< Data >::contains ( double  target) const
inline

Check if the chunk contains a target.

Parameters
targetThe target.
Returns
true if the chunk contains the target.

Definition at line 3904 of file prrng.h.

◆ data()

template<class Data >
const Data & prrng::pcg32_cumsum< Data >::data ( ) const
inline

The current chunk of the cumsum of random numbers.

Returns
Reference to the chunk.

Definition at line 3777 of file prrng.h.

◆ generator()

template<class Data >
const pcg32_index & prrng::pcg32_cumsum< Data >::generator ( ) const
inline

Pointer to the generator.

Returns
const pcg32&

Definition at line 3728 of file prrng.h.

◆ index_at_align()

template<class Data >
ptrdiff_t prrng::pcg32_cumsum< Data >::index_at_align ( ) const
inline

Global index of target (the last time prrng::pcg32_cumsum::align() was called).

Suppose that cumsum is the unlimited cumsum of random numbers starting from a seed, then:

  • gen.left_of_align() == cumsum[gen.index_at_align()] <= target.
  • gen.right_of_align() == cumsum[gen.index_at_align() + 1] > target.

Note thought that cumsum is not constructed by this class, that instead only holds a chunk gen.data() == cumsum[gen.start():gen.start() + gen.size()].

Returns
Global index.

Definition at line 3826 of file prrng.h.

◆ is_extendible()

template<class Data >
bool prrng::pcg32_cumsum< Data >::is_extendible ( ) const
inline

true if the chunk is extendible.

Returns
bool

Definition at line 3719 of file prrng.h.

◆ left_of_align()

template<class Data >
double prrng::pcg32_cumsum< Data >::left_of_align ( ) const
inline

Return the value of the cumsum left of the target (the last time prrng::pcg32_cumsum::align() was called).

gen.left_of_align() == gen.data()[gen.chunk_index_at_align()] <= target.

Returns
double

Definition at line 3854 of file prrng.h.

◆ next()

template<class Data >
void prrng::pcg32_cumsum< Data >::next ( size_t  margin = 0)
inline

Shift chunk right.

Parameters
marginOverlap to keep with the current chunk.

Definition at line 3924 of file prrng.h.

◆ operator+=()

template<class Data >
template<class T >
pcg32_cumsum & prrng::pcg32_cumsum< Data >::operator+= ( const T &  value)
inline

Add value(s) to the chunk.

Parameters
valueValue(s) to add.

Definition at line 3756 of file prrng.h.

◆ operator-=()

template<class Data >
template<class T >
pcg32_cumsum & prrng::pcg32_cumsum< Data >::operator-= ( const T &  value)
inline

Subtract value(s) from the chunk.

Parameters
valueValue(s) to subtract.

Definition at line 3767 of file prrng.h.

◆ operator=()

template<class Data >
void prrng::pcg32_cumsum< Data >::operator= ( const pcg32_cumsum< Data > &  other)
inline

Copy constructor.

This function resets all internal pointers.

Parameters
otherObject to copy.

Definition at line 3710 of file prrng.h.

◆ prev()

template<class Data >
void prrng::pcg32_cumsum< Data >::prev ( size_t  margin = 0)
inline

Shift chunk left.

Parameters
marginOverlap to keep with the current chunk.

Definition at line 3913 of file prrng.h.

◆ restore()

template<class Data >
void prrng::pcg32_cumsum< Data >::restore ( uint64_t  state,
double  value,
ptrdiff_t  index 
)
inline

Restore a specific state in the cumulative sum.

Parameters
stateThe state at the beginning of the new chunk.
valueThe value of the first entry of the new chunk.
indexThe index of the first entry of the new chunk.

Definition at line 3886 of file prrng.h.

◆ right_of_align()

template<class Data >
double prrng::pcg32_cumsum< Data >::right_of_align ( ) const
inline

Return the value of the cumsum right of the target (the last time prrng::pcg32_cumsum::align() was called).

gen.right_of_align() == gen.data()[gen.chunk_index_at_align() + 1] > target.

Returns
double

Definition at line 3866 of file prrng.h.

◆ set_data()

template<class Data >
void prrng::pcg32_cumsum< Data >::set_data ( const Data &  data)
inline

Overwrite the current chunk of the cumsum of random numbers.

Please check if set_state() or set_start() should be called too.

Parameters
dataThe chunk.

Definition at line 3788 of file prrng.h.

◆ set_functions()

template<class Data >
void prrng::pcg32_cumsum< Data >::set_functions ( std::function< Data(size_t)>  get_chunk,
std::function< double(size_t)>  get_cumsum,
bool  uses_generator = true 
)
inline

Use external functions to draw the random numbers.

Parameters
get_chunkFunction to draw the random numbers, called as get_chunk(n).
get_cumsumFunction to get the cumsum of random numbers, called: get_cumsum(n).
uses_generatorSet true is the random generator is used by the functions.

Definition at line 3682 of file prrng.h.

◆ set_start()

template<class Data >
void prrng::pcg32_cumsum< Data >::set_start ( ptrdiff_t  index)
inline

Set global index of the first element in the chunk.

Parameters
indexGlobal index.

Definition at line 3807 of file prrng.h.

◆ shape()

template<class Data >
const auto & prrng::pcg32_cumsum< Data >::shape ( ) const
inline

Shape of the chunk.

Returns
const auto&

Definition at line 3737 of file prrng.h.

◆ size()

template<class Data >
auto prrng::pcg32_cumsum< Data >::size ( ) const
inline

Size of the chunk.

Returns
auto

Definition at line 3746 of file prrng.h.

◆ start()

template<class Data >
ptrdiff_t prrng::pcg32_cumsum< Data >::start ( ) const
inline

Global index of the first element in the chunk.

Returns
Global index.

Definition at line 3798 of file prrng.h.

◆ state_at()

template<class Data >
uint64_t prrng::pcg32_cumsum< Data >::state_at ( ptrdiff_t  index)
inline

The current "state" of the generator.

If the same initseq() is used, this exact point in the sequence can be restored with restore().

Returns
State of the generator.
Template Parameters
Ruse a different return-type. There are some internal checks if the type is able to store the internal state of type uint64_t.

Definition at line 3874 of file prrng.h.


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