18 template<std::
floating_po
int T_Floating>
21 if constexpr(
sizeof(T_Floating) == 4)
23 return std::bit_cast<T_Floating>(
static_cast<uint32_t
>(0x3f7f'ffff));
25 else if constexpr(
sizeof(T_Floating) == 8)
27 return std::bit_cast<T_Floating>(
static_cast<uint64_t
>(0x3fef'ffff'ffff'ffff));
35 template<std::
unsigned_
integral T_Integer, std::
floating_po
int T_Floating>
40 = T_Floating{1} /
static_cast<T_Floating
>(std::numeric_limits<T_Integer>::max());
57 template<
typename T_Engine, concepts::Interval T_Interval, std::
integral T_Integer, std::
floating_po
int T_Floating>
64 template<
typename T_Engine, std::
integral T_Integer, std::
floating_po
int T_Floating>
70 return static_cast<T_Floating
>(i) *
interval;
82 template<
typename T_Engine, std::
integral T_Integer, std::
floating_po
int T_Floating>
98 template<
typename T_Engine, std::
integral T_Integer, std::
floating_po
int T_Floating>
110 template<
typename T_Engine, std::
integral T_Integer, std::
floating_po
int T_Floating>
122 template<
typename T_Engine, u
int32_t
byteLengthEngineResult, u
int32_t
byteLengthRealType>
126 (byteLengthEngineResult == 4u || byteLengthRealType == 8u),
127 "Result returned by the randomBitGenerator does not have a length that is accepted by the uniformReal "
130 (byteLengthEngineResult == 8u || byteLengthRealType == 4u),
131 "The requested floating point type does not have a length that is accepted by the uniformReal "
134 byteLengthEngineResult == byteLengthRealType,
135 "By logic this should never fail in case the compiler accepts the specialization of the adapter!");
144 template<
typename T_Engine>
149 return static_cast<uint64_t
>(
engine()) << 32 |
static_cast<uint64_t
>(
engine());
154 template<
typename T_Engine>
159 return static_cast<uint32_t
>(
engine());
167 template<concepts::Interval T_Interval, std::
floating_po
int T_Result,
typename T_Engine>
170 using T_EngineResult = std::remove_cvref_t<
decltype(
engine())>;
174 static_cast<uint32_t
>(
sizeof(T_EngineResult)),
175 static_cast<uint32_t
>(
sizeof(T_Result))>{}(
engine);
179 template<concepts::UniformVectorEngine T_Engine, u
int32_t TResultSize, u
int32_t TElemSize, u
int32_t TElems>
182 template<concepts::UniformVectorEngine T_Engine, u
int32_t TElemSize, u
int32_t TElems>
186 static_assert(TElems > 0,
"RandomEngine did not return any elements!");
195 return static_cast<uint32_t
>(res[0]);
201 template<concepts::UniformVectorEngine T_Engine, u
int32_t TElems>
206 static constexpr auto dim = TResult::dim();
207 static_assert(TElems >= 2,
"Engine result dimension must be >= 2, to be usable in UniformReal<double>");
216 return (
static_cast<uint64_t
>(res[0]) << 32) |
static_cast<uint64_t
>(res[1]);
220 template<std::
floating_po
int T_Floating, concepts::Interval T_Interval>
228 constexpr explicit UniformRealBase(T_Floating min, T_Floating max, [[maybe_unused]] T_Interval)
257 template<std::
floating_po
int T_Result, concepts::Interval T_Interval =
interval::CO>
260 static_assert(
static_cast<uint32_t
>(
sizeof(T_Result)) == 4u ||
static_cast<uint32_t
>(
sizeof(T_Result)) == 8u);
262 template<std::
integral T_Value>
266 static_cast<uint32_t
>(
sizeof(T_Value)) == 4u ||
static_cast<uint32_t
>(
sizeof(T_Value)) == 8u);
295 template<concepts::UniformRandomEngine T_Engine>
305 template<concepts::UniformStdEngine T_Engine>
318 template<concepts::UniformVectorEngine T_Engine>
322 using valueType =
typename T_EngineResult::type;
324 constexpr auto dim =
getDim(T_EngineResult{});
327 static_cast<uint32_t
>(
sizeof(T_Result)),
328 static_cast<uint32_t
>(
sizeof(valueType)),
330 using T_DispatchWrapper =
decltype(dispatchWrapper);
350 constexpr auto scaleInterval(T_Result
const& normalizedVal)
const -> T_Result
352 T_Result res = normalizedVal * this->
m_range + this->
m_min;
354 if constexpr(std::is_same_v<T_Interval, interval::OC> || std::is_same_v<T_Interval, interval::OO>)
356 if(res == this->m_min)
357 res = std::nextafter(this->m_min, this->
m_max);
359 if constexpr(std::is_same_v<T_Interval, interval::CO> || std::is_same_v<T_Interval, interval::OO>)
361 if(res == this->
m_max)
362 res = std::nextafter(this->
m_max, this->m_min);
#define ALPAKA_TYPEOF(...)
Get the type of instance.
consteval T_Floating prevOne() noexcept
Returns a constant, which is equivalent to std::nextafter(T_Floating{1}, T_Floating{0}...
constexpr auto getNormalizedUniformReal(T_Engine &engine) -> T_Result
Generate a floating-point value in the requested interval.
consteval uint32_t getDim(T const &any)
Contains some (constexpr-)constants for random bit integer to floating point conversion – which impro...
static constexpr T_Floating normalizedOpenIntervalBin
uses a slightly smaller bucket size [0,std::nextafter(1,0)] / MAX to enforce the (open-) upper bounds...
static constexpr T_Floating halfBinWidth
this expression has been used by nvidia curand to respect the lower bounds criteria -> it essentially...
static constexpr T_Floating normalizedIntervalBin
represents one bucket when converting an integer numbers to a floating point type in the range [0,...
constexpr auto operator()(T_Integer const &i) const
constexpr auto operator()(T_Integer const &i) const
constexpr auto operator()(T_Integer const &i) const
constexpr auto operator()(T_Integer const &i) const
Convert an integer RNG result to a floating-point value.
constexpr vectorDispatchWrapper(T_Engine &eng)
constexpr uint32_t operator()() const
constexpr vectorDispatchWrapper(T_Engine &eng)
static constexpr auto dim
constexpr uint64_t operator()() const