Celeritas
0.5.0-56+6b053cd
|
On-the-fly selection of a weighted discrete distribution. More...
#include <Selector.hh>
Public Types | |
Type aliases | |
using | value_type = T |
using | real_type = typename std::invoke_result< F, value_type >::type |
Public Member Functions | |
CELER_FUNCTION | Selector (F &&eval, value_type size, real_type total) |
Construct with function, size, and accumulated value. | |
template<class Engine > | |
CELER_FUNCTION T | operator() (Engine &rng) const |
Sample from the distribution. | |
On-the-fly selection of a weighted discrete distribution.
This algorithm encapsulates the loop for sampling from distributions by integer index or by OpaqueId. Edge cases are thoroughly tested (it will never iterate off the end, even for incorrect values of the "total" probability/xs), and it uses one fewer register than the typical accumulation algorithm. When building with debug checking, the constructor asserts that the provided "total" value is consistent.
The given function must return a consistent value for the same given argument.
or