prrng 1.12.1
Loading...
Searching...
No Matches
prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum > Class Template Reference

Array of generators of which a chunk of random numbers is kept in memory. More...

#include <prrng.h>

Inheritance diagram for prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >:
prrng::pcg32_arrayBase_chunk< pcg32_index_array, Data, Index > prrng::pcg32_arrayBase_chunk< pcg32_index_tensor< N >, Data, Index > prrng::pcg32_arrayBase_cumsum< pcg32_index_array, Data, Index > prrng::pcg32_arrayBase_cumsum< pcg32_index_tensor< N >, Data, Index > prrng::pcg32_array_chunk< Data, Index > prrng::pcg32_tensor_chunk< Data, Index, N > prrng::pcg32_array_cumsum< Data, Index > prrng::pcg32_tensor_cumsum< Data, Index, N >

Public Types

using size_type = typename Data::size_type
 Size type of the data container.
 

Public Member Functions

 pcg32_arrayBase_chunkBase (const pcg32_arrayBase_chunkBase &other)
 Copy constructor.
 
void operator= (const pcg32_arrayBase_chunkBase &other)
 Copy constructor.
 
template<class T >
pcg32_arrayBase_chunkBaseoperator+= (const T &values)
 Add values to each chunk.
 
template<class T >
pcg32_arrayBase_chunkBaseoperator-= (const T &values)
 Subtract values from each chunk.
 
bool is_extendible () const
 true if the chunk is extendible.
 
size_type chunk_size () const
 Size of the chunk per generator.
 
const Generator & generators () const
 Reference to the underlying generators.
 
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.
 
const Index & start () const
 Global index of the first element in the chunk.
 
void set_start (const Index &index)
 Set global index of the first element in the chunk.
 
void align_at (const Index &index)
 Get the index random number, which index specified per generator.
 
Index index_at_align () const
 Global index of target (the last time prrng::pcg32_cumsum::align() was called).
 
const Index & chunk_index_at_align () const
 Index of target relative to the beginning of the chunk (the last time prrng::pcg32_cumsum::align() was called).
 
template<class R >
void left_of_align (R &ret) const
 Return the value of the cumsum left of the target (the last time prrng::pcg32_cumsum::align() was called).
 
template<class R >
void right_of_align (R &ret) const
 Return the value of the cumsum right of the target (the last time prrng::pcg32_cumsum::align() was called).
 
template<class R >
left_of_align () const
 Return the value of the cumsum left of the target (the last time prrng::pcg32_cumsum::align() was called).
 
template<class R >
right_of_align () const
 Return the value of the cumsum right of the target (the last time prrng::pcg32_cumsum::align() was called).
 
template<class R , class T >
state_at (const T &index)
 The current "state" of the generator.
 

Protected Member Functions

template<class S , class T , class U >
void init (const S &shape, const T &initstate, const U &initseq, enum distribution distribution, const std::vector< double > &parameters, const alignment &align=alignment())
 Constructor.
 
void auto_functions ()
 Set draw function.
 
void copy_from (const pcg32_arrayBase_chunkBase &other)
 Copy constructor.
 

Protected Attributes

Generator m_gen
 Array of generators.
 
Data m_data
 Data container.
 
std::vector< std::function< xt::xtensor< double, 1 >(size_t)> > m_draw
 Function to draw the next chunk of n random numbers starting from the curent state of the generator.
 
std::vector< std::function< double(size_t)> > m_sum
 Function to get the cumsum of n random numbers starting from the curent state of the generator (used to skip allocating an list of size n).
 
bool m_extendible
 Signal if the drawing functions are specified, implying that the chunk can be changed.
 
alignment m_align
 alignment settings, see prrng::alignment().
 
distribution m_distro
 Distribution name, see prrng::distribution().
 
std::array< double, 3 > m_param
 Distribution parameters.
 
Index m_start
 Start index of the chunk.
 
Index m_i
 Last known index of target in align.
 
size_t m_n
 Size of the chunk.
 

Detailed Description

template<class Generator, class Data, class Index, bool is_cumsum>
class prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >

Array of generators of which a chunk of random numbers is kept in memory.

Template Parameters
GeneratorStorage of the generator array, e.g. prrng::pcg32_tensor<N>.
DataStorage of the data, e.g. xt::xtensor<double, N + n>.
IndexStorage of the index, e.g. xt::xtensor<ptrdiff_t, N>.

Definition at line 5795 of file prrng.h.

Member Typedef Documentation

◆ size_type

template<class Generator , class Data , class Index , bool is_cumsum>
using prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::size_type = typename Data::size_type

Size type of the data container.

Definition at line 5799 of file prrng.h.

Constructor & Destructor Documentation

◆ pcg32_arrayBase_chunkBase()

template<class Generator , class Data , class Index , bool is_cumsum>
prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::pcg32_arrayBase_chunkBase ( const pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum > &  other)
inline

Copy constructor.

This function resets all internal pointers.

Parameters
otherObject to copy.

Definition at line 6060 of file prrng.h.

Member Function Documentation

◆ align_at()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::align_at ( const Index &  index)
inline

Get the index random number, which index specified per generator.

Note
alignment::min_margin and alignment::strict are not relevant: alignment is always exact.
Template Parameters
RReturn type.
Parameters
indexIndex of the random number.

Definition at line 6165 of file prrng.h.

◆ auto_functions()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::auto_functions ( )
inlineprotected

Set draw function.

Definition at line 5896 of file prrng.h.

◆ chunk_index_at_align()

template<class Generator , class Data , class Index , bool is_cumsum>
const Index & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::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 6209 of file prrng.h.

◆ chunk_size()

template<class Generator , class Data , class Index , bool is_cumsum>
size_type prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::chunk_size ( ) const
inline

Size of the chunk per generator.

Returns
Unsigned integer.

Definition at line 6108 of file prrng.h.

◆ copy_from()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::copy_from ( const pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum > &  other)
inlineprotected

Copy constructor.

This function resets all internal pointers.

Parameters
otherObject to copy.

Definition at line 6041 of file prrng.h.

◆ data()

template<class Generator , class Data , class Index , bool is_cumsum>
const Data & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::data ( ) const
inline

The current chunk of the cumsum of random numbers.

Returns
Reference to the chunk.

Definition at line 6125 of file prrng.h.

◆ generators()

template<class Generator , class Data , class Index , bool is_cumsum>
const Generator & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::generators ( ) const
inline

Reference to the underlying generators.

Returns
Reference to generator array.

Definition at line 6117 of file prrng.h.

◆ index_at_align()

template<class Generator , class Data , class Index , bool is_cumsum>
Index prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::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 6201 of file prrng.h.

◆ init()

template<class Generator , class Data , class Index , bool is_cumsum>
template<class S , class T , class U >
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::init ( const S &  shape,
const T &  initstate,
const U &  initseq,
enum distribution  distribution,
const std::vector< double > &  parameters,
const alignment align = alignment() 
)
inlineprotected

Constructor.

Parameters
shapeShape of the chunk to keep in memory per generator.
initstateState initiator for every item.
initseqSequence initiator for every item.
Parameters
distributionDistribution.
parametersParameters for the distribution: appended by the following defaults if needed.

Definition at line 5842 of file prrng.h.

◆ is_extendible()

template<class Generator , class Data , class Index , bool is_cumsum>
bool prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::is_extendible ( ) const
inline

true if the chunk is extendible.

Returns
bool

Definition at line 6099 of file prrng.h.

◆ left_of_align() [1/2]

template<class Generator , class Data , class Index , bool is_cumsum>
template<class R >
R prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::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 6248 of file prrng.h.

◆ left_of_align() [2/2]

template<class Generator , class Data , class Index , bool is_cumsum>
template<class R >
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::left_of_align ( R &  ret) const
inline

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

Parameters
retArray to store the result in.

Definition at line 6219 of file prrng.h.

◆ operator+=()

template<class Generator , class Data , class Index , bool is_cumsum>
template<class T >
pcg32_arrayBase_chunkBase & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::operator+= ( const T &  values)
inline

Add values to each chunk.

Parameters
valuesValues to add.

Definition at line 6078 of file prrng.h.

◆ operator-=()

template<class Generator , class Data , class Index , bool is_cumsum>
template<class T >
pcg32_arrayBase_chunkBase & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::operator-= ( const T &  values)
inline

Subtract values from each chunk.

Parameters
valuesValues to subtract.

Definition at line 6089 of file prrng.h.

◆ operator=()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::operator= ( const pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum > &  other)
inline

Copy constructor.

This function resets all internal pointers.

Parameters
otherObject to copy.

Definition at line 6068 of file prrng.h.

◆ right_of_align() [1/2]

template<class Generator , class Data , class Index , bool is_cumsum>
template<class R >
R prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::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 6259 of file prrng.h.

◆ right_of_align() [2/2]

template<class Generator , class Data , class Index , bool is_cumsum>
template<class R >
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::right_of_align ( R &  ret) const
inline

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

Parameters
retArray to store the result in.

Definition at line 6234 of file prrng.h.

◆ set_data()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::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 6133 of file prrng.h.

◆ set_start()

template<class Generator , class Data , class Index , bool is_cumsum>
void prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::set_start ( const Index &  index)
inline

Set global index of the first element in the chunk.

Parameters
indexGlobal index.

Definition at line 6150 of file prrng.h.

◆ start()

template<class Generator , class Data , class Index , bool is_cumsum>
const Index & prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::start ( ) const
inline

Global index of the first element in the chunk.

Returns
Global index.

Definition at line 6142 of file prrng.h.

◆ state_at()

template<class Generator , class Data , class Index , bool is_cumsum>
template<class R , class T >
R prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::state_at ( const 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 6270 of file prrng.h.

Member Data Documentation

◆ m_align

template<class Generator , class Data , class Index , bool is_cumsum>
alignment prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_align
protected

alignment settings, see prrng::alignment().

Definition at line 5824 of file prrng.h.

◆ m_data

template<class Generator , class Data , class Index , bool is_cumsum>
Data prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_data
protected

Data container.

Definition at line 5803 of file prrng.h.

◆ m_distro

template<class Generator , class Data , class Index , bool is_cumsum>
distribution prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_distro
protected

Distribution name, see prrng::distribution().

Definition at line 5825 of file prrng.h.

◆ m_draw

template<class Generator , class Data , class Index , bool is_cumsum>
std::vector<std::function<xt::xtensor<double, 1>(size_t)> > prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_draw
protected

Function to draw the next chunk of n random numbers starting from the curent state of the generator.

The functions of all generators are collected in a vector (flat storage).

Definition at line 5810 of file prrng.h.

◆ m_extendible

template<class Generator , class Data , class Index , bool is_cumsum>
bool prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_extendible
protected

Signal if the drawing functions are specified, implying that the chunk can be changed.

Definition at line 5822 of file prrng.h.

◆ m_gen

template<class Generator , class Data , class Index , bool is_cumsum>
Generator prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_gen
protected

Array of generators.

Definition at line 5802 of file prrng.h.

◆ m_i

template<class Generator , class Data , class Index , bool is_cumsum>
Index prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_i
protected

Last known index of target in align.

Definition at line 5828 of file prrng.h.

◆ m_n

template<class Generator , class Data , class Index , bool is_cumsum>
size_t prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_n
protected

Size of the chunk.

Definition at line 5829 of file prrng.h.

◆ m_param

template<class Generator , class Data , class Index , bool is_cumsum>
std::array<double, 3> prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_param
protected

Distribution parameters.

Definition at line 5826 of file prrng.h.

◆ m_start

template<class Generator , class Data , class Index , bool is_cumsum>
Index prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_start
protected

Start index of the chunk.

Definition at line 5827 of file prrng.h.

◆ m_sum

template<class Generator , class Data , class Index , bool is_cumsum>
std::vector<std::function<double(size_t)> > prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >::m_sum
protected

Function to get the cumsum of n random numbers starting from the curent state of the generator (used to skip allocating an list of size n).

The functions of all generators are collected in a vector (flat storage).

Definition at line 5817 of file prrng.h.


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