forpy 2

Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
forpy::SamplingWithoutReplacement< T > Class Template Reference

A lazy evaluation sampling without replacement. More...

`#include <sampling.h>`

## Public Member Functions
| SamplingWithoutReplacement (const T &min, const T &max, const std::shared_ptr< std::mt19937 > &random_engine)
bool | sample_available () const
| Returns true if a sample can be drawn without raising an exception. More...
T | get_next ()
| Gets the next sample. More...
bool | operator== (const SamplingWithoutReplacement< T > &rhs) const

## Private Member Functions
| SamplingWithoutReplacement ()
template<class Archive >
void | serialize (Archive &ar, const uint &)

## Private Attributes
T | min
std::shared_ptr< std::mt19937 > | random_engine
std::uniform_int_distribution< T > | dist
std::vector< T > | indices
size_t | index

## Friends
class | cereal::access
std::ostream & | operator<< (std::ostream &stream, const SamplingWithoutReplacement &self)

## Detailed Description

### template<typename T>
class forpy::SamplingWithoutReplacement< T >

A lazy evaluation sampling without replacement.

Returns a set of num unique numbers in range [min, max].

This needs to be stateful. Hence, it must store for each element whether it has been used yet. This renders it inefficient for use cases where only few instances need to be drawn.

min and max are both inclusive.

Definition at line 62 of file sampling.h.

## Constructor & Destructor Documentation

## ◆ SamplingWithoutReplacement() [1/2]

template<typename T>

forpy::SamplingWithoutReplacement< T >::SamplingWithoutReplacement | ( | const T & | min,
|  | const T & | max,
|  | const std::shared_ptr< std::mt19937 > & | random_engine
| ) |  |
| inline

Definition at line 64 of file sampling.h.

## ◆ SamplingWithoutReplacement() [2/2]

template<typename T>

forpy::SamplingWithoutReplacement< T >::SamplingWithoutReplacement | ( |  | ) |
| inline private

Definition at line 113 of file sampling.h.

## Member Function Documentation

## ◆ get_next()

template<typename T>

T forpy::SamplingWithoutReplacement< T >::get_next | ( |  | ) |
| inline

Gets the next sample.

Definition at line 82 of file sampling.h.

## ◆ operator==()

template<typename T>

bool forpy::SamplingWithoutReplacement< T >::operator== | ( | const SamplingWithoutReplacement< T > & | rhs | ) | const
| inline

Definition at line 107 of file sampling.h.

## ◆ sample_available()

template<typename T>

bool forpy::SamplingWithoutReplacement< T >::sample_available | ( |  | ) | const
| inline

Returns true if a sample can be drawn without raising an exception.

Definition at line 77 of file sampling.h.

## ◆ serialize()

template<typename T>
template<class Archive >

void forpy::SamplingWithoutReplacement< T >::serialize | ( | Archive & | ar,
|  | const uint & |
| ) |  |
| inline private

Definition at line 117 of file sampling.h.

## Friends And Related Function Documentation

## ◆ cereal::access

template<typename T>

friend class cereal::access
| friend

Definition at line 113 of file sampling.h.

## ◆ operator<<

template<typename T>

std::ostream& operator<< | ( | std::ostream & | stream,
|  | const SamplingWithoutReplacement< T > & | self
| ) |  |
| friend

Definition at line 99 of file sampling.h.

## Member Data Documentation

## ◆ dist

template<typename T>

std::uniform_int_distribution<T> forpy::SamplingWithoutReplacement< T >::dist
| private

Definition at line 124 of file sampling.h.

## ◆ index

template<typename T>

size_t forpy::SamplingWithoutReplacement< T >::index
| private

Definition at line 126 of file sampling.h.

## ◆ indices

template<typename T>

std::vector<T> forpy::SamplingWithoutReplacement< T >::indices
| private

Definition at line 125 of file sampling.h.

## ◆ min

template<typename T>

T forpy::SamplingWithoutReplacement< T >::min
| private

Definition at line 120 of file sampling.h.

## ◆ random_engine

template<typename T>

std::shared_ptr<std::mt19937> forpy::SamplingWithoutReplacement< T >::random_engine
| private

Definition at line 123 of file sampling.h.

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

- /Users/classner/git/forpy/include/forpy/util/sampling.h