prrng 1.12.1
Loading...
Searching...
No Matches
prrng.h File Reference

Portable Reconstructible Random Number Generator. More...

#include <array>
#include <xtensor/xarray.hpp>
#include <xtensor/xnoalias.hpp>
#include <xtensor/xtensor.hpp>
#include <boost/math/special_functions/erf.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <xtensor/xvectorize.hpp>

Go to the source code of this file.

Classes

class  prrng::exponential_distribution
 Exponential distribution. More...
 
class  prrng::power_distribution
 Power distribution. More...
 
class  prrng::gamma_distribution
 Gamma distribution. More...
 
class  prrng::pareto_distribution
 Pareto distribution. More...
 
class  prrng::weibull_distribution
 Weibull distribution. More...
 
class  prrng::normal_distribution
 Normal distribution. More...
 
class  prrng::GeneratorBase< Derived >
 Base class of the pseudorandom number generators providing common methods. More...
 
class  prrng::pcg32
 Random number generate using the pcg32 algorithm. More...
 
class  prrng::pcg32_index
 Overload of prrng::pcg32() that keeps track of the current index of the generator in the sequence. More...
 
struct  prrng::alignment
 Structure to assemble the alignment parameters. More...
 
class  prrng::pcg32_cumsum< Data >
 Generator of a random cumulative sum of which a chunk is kept in memory. More...
 
class  prrng::GeneratorBase_array< Derived, M >
 Base class of an array of pseudorandom number generators. More...
 
class  prrng::pcg32_arrayBase< Generator, Shape >
 Base class, see pcg32_array for description. More...
 
class  prrng::pcg32_array
 Array of independent generators. More...
 
class  prrng::pcg32_tensor< N >
 Fixed rank version of pcg32_array. More...
 
class  prrng::pcg32_index_array
 Array of prrng::pcg32_index(). More...
 
class  prrng::pcg32_index_tensor< N >
 Fixed rank version of pcg32_index_array. More...
 
class  prrng::pcg32_arrayBase_chunkBase< Generator, Data, Index, is_cumsum >
 Array of generators of which a chunk of random numbers is kept in memory. More...
 
class  prrng::pcg32_arrayBase_chunk< Generator, Data, Index >
 Array of generators of which a chunk of random numbers is kept in memory. More...
 
class  prrng::pcg32_arrayBase_cumsum< Generator, Data, Index >
 TODO: copydoc. More...
 
class  prrng::pcg32_array_chunk< Data, Index >
 Array of generators of which a chunk of the random sequence is kept in memory. More...
 
class  prrng::pcg32_tensor_chunk< Data, Index, N >
 Array of generators of which a chunk of the random sequence is kept in memory. More...
 
class  prrng::pcg32_array_cumsum< Data, Index >
 Array of generators of a random cumulative sum, see prrng::pcg32_cumsum(). More...
 
class  prrng::pcg32_tensor_cumsum< Data, Index, N >
 Array of generators of a random cumulative sum, see prrng::pcg32_cumsum(). More...
 

Namespaces

namespace  prrng
 Portable Reconstructible (Pseudo!) Random Number Generator.
 

Macros

#define PRRNG_PCG32_INITSTATE   0x853c49e6748fea9bULL
 Default initialisation state for pcg32() (used as constructor parameter that can be overwritten at run-time).
 
#define PRRNG_PCG32_INITSEQ   0xda3e39cb94b95bdbULL
 Default initialisation sequence for pcg32() (used as constructor parameter that can be overwritten at run-time).
 
#define PRRNG_PCG32_MULT   6364136223846793005ULL
 Multiplicative factor for pcg32() (used internally, cannot be overwritten at run-time).
 
#define PRRNG_USE_BOOST   1
 To use prrng without Boost.
 
#define PRRNG_VERSION   "@PROJECT_VERSION@"
 Library version.
 
#define PRRNG_ASSERT(expr)
 All assertions are implementation as:
 
#define PRRNG_DEBUG(expr)
 All debug assertions are implementation as:
 
#define PRRNG_WARNING(message)   PRRNG_WARNING_IMPL(message, __FILE__, __LINE__, __FUNCTION__)
 Warnings are implemented as:
 
#define PRRNG_WARNING_PYTHON(message)
 Warnings specific to the Python API are implemented as:
 

Enumerations

enum  prrng::distribution {
  prrng::random , prrng::delta , prrng::exponential , prrng::power ,
  prrng::gamma , prrng::pareto , prrng::weibull , prrng::normal ,
  prrng::custom
}
 Distribution identifier. More...
 

Functions

std::vector< double > prrng::default_parameters (enum distribution distribution, const std::vector< double > &parameters=std::vector< double >{})
 
std::string prrng::version ()
 Version string, e.g.
 
std::vector< std::string > prrng::version_dependencies ()
 Versions of this library and of all of its dependencies.
 
std::vector< std::string > prrng::version_compiler ()
 Information on the compiler, the platform, the C++ standard, and the compilation date.
 
template<class It , class T , class R = size_t>
prrng::iterator::lower_bound (const It first, const It last, const T &value, R guess=0, R proximity=10)
 Return index of the first element in the range [first, last) such that element < value is false (i.e.
 
template<class T , class V , class R >
void prrng::inplace::lower_bound (const T &matrix, const V &value, R &index, typename R::value_type proximity=10)
 Similar to lower_bound but on the last axis of an nd-array (e.g.
 
template<class V , class I >
void prrng::inplace::cumsum_chunk (V &cumsum, const V &delta, const I &shift)
 Update the chunk of a cumsum computed and stored in chunks.
 
template<class T , class V , class R >
prrng::lower_bound (const T &matrix, const V &value, const R &index, size_t proximity=10)
 Iterating on the last axis of an nd-array (e.g.
 
template<class T , class V , class R >
prrng::lower_bound (const T &matrix, const V &value)
 Iterating on the last axis of an nd-array (e.g.
 
template<class V , class I >
prrng::cumsum_chunk (const V &cumsum, const V &delta, const I &shift)
 Update the chunk of a cumsum computed and stored in chunks.
 
template<class T >
auto prrng::auto_pcg32 (const T &initstate)
 Return a pcg32, a pcg32_array, or a pcg32_tensor based on input.
 
template<class T , class S >
auto prrng::auto_pcg32 (const T &initstate, const S &initseq)
 Return a pcg32, a pcg32_array, or a pcg32_tensor based on input.
 

Detailed Description

Portable Reconstructible Random Number Generator.

The idea is that a random sequence can be restored independent of platform or compiler. In addition, this library allows you to store a point in the sequence, and then later restore the sequence exactly from this point (in both directions actually).

Note that the core of this code is taken from https://github.com/imneme/pcg-c-basic All the credits goes to those developers. This is just a wrapper.

license This project is released under the MIT License.

Definition in file prrng.h.

Macro Definition Documentation

◆ PRRNG_ASSERT

#define PRRNG_ASSERT (   expr)

All assertions are implementation as:

PRRNG_ASSERT(...)

They can be enabled by:

#define PRRNG_ENABLE_ASSERT

(before including prrng). The advantage is that:

  • File and line-number are displayed if the assertion fails.
  • prrng's assertions can be enabled/disabled independently from those of other libraries.
Exceptions
std::runtime_error

Definition at line 129 of file prrng.h.

◆ PRRNG_DEBUG

#define PRRNG_DEBUG (   expr)

All debug assertions are implementation as:

PRRNG_DEBUG(...)

They can be enabled by:

#define PRRNG_ENABLE_DEBUG

(before including prrng). The advantage is that:

  • File and line-number are displayed if the assertion fails.
  • prrng's assertions can be enabled/disabled independently from those of other libraries.
Exceptions
std::runtime_error

Definition at line 152 of file prrng.h.

◆ PRRNG_PCG32_INITSEQ

#define PRRNG_PCG32_INITSEQ   0xda3e39cb94b95bdbULL

Default initialisation sequence for pcg32() (used as constructor parameter that can be overwritten at run-time).

Definition at line 33 of file prrng.h.

◆ PRRNG_PCG32_INITSTATE

#define PRRNG_PCG32_INITSTATE   0x853c49e6748fea9bULL

Default initialisation state for pcg32() (used as constructor parameter that can be overwritten at run-time).

Definition at line 27 of file prrng.h.

◆ PRRNG_PCG32_MULT

#define PRRNG_PCG32_MULT   6364136223846793005ULL

Multiplicative factor for pcg32() (used internally, cannot be overwritten at run-time).

Definition at line 39 of file prrng.h.

◆ PRRNG_USE_BOOST

#define PRRNG_USE_BOOST   1

To use prrng without Boost.

#define PRRNG_USE_BOOST 0
#include <prrng.h>

You will loose the normal and Gamma distributions.

Definition at line 55 of file prrng.h.

◆ PRRNG_VERSION

#define PRRNG_VERSION   "@PROJECT_VERSION@"

Library version.

Either:

  • Configure using CMake at install time. Internally uses:
    python -c "from setuptools_scm import get_version; print(get_version())"
    
  • Define externally using:
    -DPRRNG_VERSION="`python -c "from setuptools_scm import get_version;
    
    print(get_version())"`"
    From the root of this project. This is what ``setup.py`` does.
    
    Note that both CMakeLists.txt and setup.py will construct the version using setuptools_scm. Tip: use the environment variable SETUPTOOLS_SCM_PRETEND_VERSION to overwrite the automatic version.

Definition at line 106 of file prrng.h.

◆ PRRNG_WARNING

#define PRRNG_WARNING (   message)    PRRNG_WARNING_IMPL(message, __FILE__, __LINE__, __FUNCTION__)

Warnings are implemented as:

 PRRNG_WARNING(...)

They can be disabled by:

 #define PRRNG_DISABLE_WARNING

Definition at line 167 of file prrng.h.

◆ PRRNG_WARNING_PYTHON

#define PRRNG_WARNING_PYTHON (   message)

Warnings specific to the Python API are implemented as:

 PRRNG_WARNING_PYTHON(...)

They can be enabled by:

 #define PRRNG_ENABLE_WARNING_PYTHON

Definition at line 182 of file prrng.h.

Function Documentation

◆ cumsum_chunk()

template<class V , class I >
void prrng::inplace::cumsum_chunk ( V &  cumsum,
const V &  delta,
const I &  shift 
)
inline

Update the chunk of a cumsum computed and stored in chunks.

Parameters
cumsumThe current chunk of the cumsum (updated).
deltaThe 'diff's of the next chunk in the cumsum.
shiftThe shift per row.

Definition at line 771 of file prrng.h.

◆ lower_bound() [1/2]

template<class It , class T , class R = size_t>
R prrng::iterator::lower_bound ( const It  first,
const It  last,
const T &  value,
guess = 0,
proximity = 10 
)
inline

Return index of the first element in the range [first, last) such that element < value is false (i.e.

greater or equal to), or last if no such element is found.

Compared to the default function, this function allows for a guess of the index and a proximity search around. This could be efficient for finding items in large arrays.

Parameters
firstIterator defining the beginning of the range to examine (e.g. a.begin()).
lastIterator defining the end of the range to examine (e.g. a.end())
valueValue to find.
guessGuess of the index where to find the value.
proximitySize of the proximity search around guess (use 0 to disable).
Returns
The index of value (i.e. a[index] < value <= a[index + 1]).

Definition at line 694 of file prrng.h.

◆ lower_bound() [2/2]

template<class T , class V , class R >
void prrng::inplace::lower_bound ( const T &  matrix,
const V &  value,
R &  index,
typename R::value_type  proximity = 10 
)
inline

Similar to lower_bound but on the last axis of an nd-array (e.g.

per row of a rank 2 matrix).

Parameters
matrixThe matrix defining a range per row.
valueThe value to find (per row).
indexInitial guess on index (updated).
proximitySize of the proximity search around guess (use 0 to disable proximity search).

Definition at line 736 of file prrng.h.