Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::Selector< F, T > Class Template Reference

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_FUNCTIONoperator() (Engine &rng) const
 Sample from the distribution.
 

Detailed Description

template<class F, class T>
class celeritas::Selector< F, T >

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.

auto select_el = make_selector(
[](ElementId i) { return xs[i.get()]; },
ElementId{num_elements()},
tot_xs);
ElementId el = select_el(rng);
@ el
Elastic cross section.
CELER_FUNCTION Selector< F, T > make_selector(F &&func, T size, decltype(func(size)) total=1)
Create a selector object from a function and total accumulated value.
Definition: Selector.hh:83
OpaqueId< struct ElementRecord > ElementId
Opaque index to ElementRecord in the global vector of elements.
Definition: celeritas/Types.hh:30

or

auto select_val = make_selector([](size_type i) { return pdf[i]; },
pdf.size());
size_type idx = select_val(rng);
unsigned int size_type
Standard type for container sizes, optimized for GPU use.
Definition: corecel/Types.hh:28

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