All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
util::UniformSequence< T > Class Template Reference

Samples the interval [ 0, 1 ] in sequence, cyclically. More...

#include <FastAndPoorGauss.h>

Public Types

using Data_t = T
 Type of data required. More...
 

Public Member Functions

 UniformSequence (unsigned int N)
 Initializes a sequence of N steps. More...
 
void reset ()
 Restarts the sequence. More...
 
Data_t extract ()
 Returns the next number in the sequence. More...
 
Data_t operator() ()
 

Private Member Functions

unsigned int next ()
 Returns the current point and prepares for the next one. More...
 

Private Attributes

unsigned int const fN
 The number of points the interval is split into. More...
 
Data_t const fStep
 Size of each step. More...
 
Data_t const fOffset
 Offset of the values (half step). More...
 
unsigned int fNext = 0U
 The next point to be delivered. More...
 

Detailed Description

template<typename T>
class util::UniformSequence< T >

Samples the interval [ 0, 1 ] in sequence, cyclically.

Template Parameters
T(default: double) type of number returned

This object extract()s in sequence numbers in the interval [ 0 ; 1 ]. The interval is split in equally sized bins, and each time extract() returns the center of the next bin, starting with the first one. After reaching the last bin, it restarts the cycle.

Example of usage:

std::array<double, 100N> seq1, seq2;
for (auto& v: seq) v = extract();
std::generate(seq.begin(), seq.end(), util::UniformSequence<>{ 100 });

(the two sequences are identical).

Definition at line 52 of file FastAndPoorGauss.h.

Member Typedef Documentation

template<typename T >
using util::UniformSequence< T >::Data_t = T

Type of data required.

Definition at line 194 of file FastAndPoorGauss.h.

Constructor & Destructor Documentation

template<typename T >
util::UniformSequence< T >::UniformSequence ( unsigned int  N)
inline

Initializes a sequence of N steps.

Definition at line 197 of file FastAndPoorGauss.h.

198  : fN(N), fStep(Data_t{ 1 }/fN), fOffset(fStep/Data_t{ 2 })
199  {}
unsigned int const fN
The number of points the interval is split into.
Data_t const fOffset
Offset of the values (half step).
T Data_t
Type of data required.
process_name largeant stream1 can override from command line with o or output physics producers generator N
Data_t const fStep
Size of each step.

Member Function Documentation

template<typename T >
Data_t util::UniformSequence< T >::extract ( )
inline

Returns the next number in the sequence.

Definition at line 203 of file FastAndPoorGauss.h.

203 { return fOffset + next() * fStep; }
Data_t const fOffset
Offset of the values (half step).
unsigned int next()
Returns the current point and prepares for the next one.
Data_t const fStep
Size of each step.
template<typename T >
unsigned int util::UniformSequence< T >::next ( )
private

Returns the current point and prepares for the next one.

Definition at line 261 of file FastAndPoorGauss.h.

261  {
262  unsigned int i = fNext;
263  if (++fNext == fN) reset();
264  return i;
265 } // util::UniformSequence<T>::next()
unsigned int const fN
The number of points the interval is split into.
unsigned int fNext
The next point to be delivered.
void reset()
Restarts the sequence.
template<typename T >
Data_t util::UniformSequence< T >::operator() ( )
inline

Definition at line 204 of file FastAndPoorGauss.h.

204 { return extract(); }
Data_t extract()
Returns the next number in the sequence.
template<typename T >
void util::UniformSequence< T >::reset ( )
inline

Restarts the sequence.

Definition at line 208 of file FastAndPoorGauss.h.

208 { fNext = 0U; }
unsigned int fNext
The next point to be delivered.

Member Data Documentation

template<typename T >
unsigned int const util::UniformSequence< T >::fN
private

The number of points the interval is split into.

Definition at line 211 of file FastAndPoorGauss.h.

template<typename T >
unsigned int util::UniformSequence< T >::fNext = 0U
private

The next point to be delivered.

Definition at line 216 of file FastAndPoorGauss.h.

template<typename T >
Data_t const util::UniformSequence< T >::fOffset
private

Offset of the values (half step).

Definition at line 214 of file FastAndPoorGauss.h.

template<typename T >
Data_t const util::UniformSequence< T >::fStep
private

Size of each step.

Definition at line 213 of file FastAndPoorGauss.h.


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