alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
alpaka::rand::distribution::UniformReal< T_Result, T_Interval > Struct Template Reference

Select a floating-point value from a uniform interval. More...

#include <UniformReal.hpp>

Inheritance diagram for alpaka::rand::distribution::UniformReal< T_Result, T_Interval >:

Public Types

using Base = internal::UniformRealBase<T_Result, T_Interval>
Public Types inherited from alpaka::rand::distribution::internal::UniformRealBase< T_Result, interval::CO >
using Interval_type
using result_type

Public Member Functions

constexpr UniformReal (T_Interval interval=T_Interval{})
constexpr UniformReal (T_Result min, T_Result max, T_Interval interval=T_Interval{})
template<concepts::UniformRandomEngine T_Engine>
constexpr auto operator() (T_Engine &engine) const -> T_Result
 Selects a value from a uniform distribution over the configured (min, max) interval, respecting the specified interval bounds.
Public Member Functions inherited from alpaka::rand::distribution::internal::UniformRealBase< T_Result, interval::CO >
constexpr UniformRealBase (T_Floating min, T_Floating max, T_Interval)

Static Public Member Functions

template<std::integral T_Value>
static consteval void checkValueConformity ()

Private Member Functions

template<concepts::UniformVectorEngine T_Engine>
constexpr auto engineDispatch (T_Engine &engine) const -> T_Result
 Dispatch for vector engines (uniform bit generators that return a vector (e.g Philox4x32x10Vector) to enable efficient double precision uniform_real generation (reducing the number of invocations).
template<concepts::UniformStdEngine T_Engine>
constexpr auto engineDispatch (T_Engine &engine) const -> T_Result
 Dispatch for std engines and alpaka abbreviations conforming to the std::uniform_random_bit_generator concept (e.g.
constexpr auto scaleInterval (T_Result const &normalizedVal) const -> T_Result
 For open bounds, the normalized value in (0, 1) may (still) hit the lower or upper bound due to floating-point rounding (after scaling is applied).

Additional Inherited Members

Protected Attributes inherited from alpaka::rand::distribution::internal::UniformRealBase< T_Result, interval::CO >
T_Floating const m_max
T_Floating const m_min
T_Floating const m_range

Detailed Description

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
struct alpaka::rand::distribution::UniformReal< T_Result, T_Interval >

Select a floating-point value from a uniform interval.

This generator produces floating-point values of type T_Result drawn from a uniform interval [a, b) or (a, b], depending on the interval type specified via Interval_v: default case is CO ->[a,b). The interface mirrors std::uniform_real_distribution, and can be invoked with any engine adhering to the 'UniformRandomEngine' concept, which includes std uniform engines.

Supported result types: float, double Supported engine result widths: 32-bit and 64-bit unsigned integers.

Note
This distribution is subject to a small non-uniform bias; see UniformReal::operator() for details.

Definition at line 258 of file UniformReal.hpp.

Member Typedef Documentation

◆ Base

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
using alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::Base = internal::UniformRealBase<T_Result, T_Interval>

Definition at line 269 of file UniformReal.hpp.

Constructor & Destructor Documentation

◆ UniformReal() [1/2]

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::UniformReal ( T_Interval interval = T_Interval{})
inlineexplicitconstexpr

Definition at line 271 of file UniformReal.hpp.

◆ UniformReal() [2/2]

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::UniformReal ( T_Result min,
T_Result max,
T_Interval interval = T_Interval{} )
inlineconstexpr

Definition at line 275 of file UniformReal.hpp.

Member Function Documentation

◆ checkValueConformity()

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
template<std::integral T_Value>
consteval void alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::checkValueConformity ( )
inlinestaticconsteval

Definition at line 263 of file UniformReal.hpp.

◆ engineDispatch() [1/2]

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
template<concepts::UniformVectorEngine T_Engine>
auto alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::engineDispatch ( T_Engine & engine) const -> T_Result
inlineconstexprprivate

Dispatch for vector engines (uniform bit generators that return a vector (e.g Philox4x32x10Vector) to enable efficient double precision uniform_real generation (reducing the number of invocations).

Definition at line 319 of file UniformReal.hpp.

◆ engineDispatch() [2/2]

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
template<concepts::UniformStdEngine T_Engine>
auto alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::engineDispatch ( T_Engine & engine) const -> T_Result
inlineconstexprprivate

Dispatch for std engines and alpaka abbreviations conforming to the std::uniform_random_bit_generator concept (e.g.

Philox4x32x10)

Definition at line 306 of file UniformReal.hpp.

◆ operator()()

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
template<concepts::UniformRandomEngine T_Engine>
auto alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::operator() ( T_Engine & engine) const -> T_Result
inlineconstexpr

Selects a value from a uniform distribution over the configured (min, max) interval, respecting the specified interval bounds.

**

Input: a random engine conforming to the UniformRandomEngine concept (currently accepts stdlib uniform engines and alpaka engines included in the alpaka::rand::engine namespace) Output: a floating-point value sampled from the configured distribution.

Note
: This distribution introduces a slight numerical bias due to floating-point rounding effects and the use of a 1 / MAX integer-to-floating-point conversion methods
See also
Goualard, F. (2020). Generating Random Floating-Point Numbers by Dividing Integers: A Case Study. https://doi.org/10.1007/978-3-030-50417-5_2 or Allen B. Downey Generating Pseudo-random Floating-Point Values https://allendowney.com/research/rand/. Additionally, using an interval with an open bound (OC,CO,OO) may introduce yet another small non-uniform bias –
scaleInterval().

Definition at line 296 of file UniformReal.hpp.

◆ scaleInterval()

template<std::floating_point T_Result, concepts::Interval T_Interval = interval::CO>
auto alpaka::rand::distribution::UniformReal< T_Result, T_Interval >::scaleInterval ( T_Result const & normalizedVal) const -> T_Result
inlineconstexprprivate

For open bounds, the normalized value in (0, 1) may (still) hit the lower or upper bound due to floating-point rounding (after scaling is applied).

To enforce adherence to the requested interval, the result is shifted to the next representable value using std::nextafter. WARNING: std::nextafter is not constexpr in cpp20 -> this might cause problems on some devices (regarding missing device annotations) and requires often unnecessary runtime evaluation – future maintainers should consider creating a constexpr adaptation of std::nextafter

Note
This introduces a(-/another) small non-uniform bias. The current implementation is inherently non-uniform due to integer-to-floating-point mapping
See also
https://doi.org/10.1007/978-3-030-50417-5_2

Definition at line 350 of file UniformReal.hpp.


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