12#ifndef ARCCORE_BASE_VALUEFILLER_H
13#define ARCCORE_BASE_VALUEFILLER_H
18#include "arccore/base/BFloat16.h"
19#include "arccore/base/Float16.h"
20#include "arccore/base/Float128.h"
21#include "arccore/base/Int128.h"
28namespace Arccore::ValueFiller::impl
34template <
typename DataType>
39 using ClampValue = std::pair<DataType, DataType>;
40 BuildInfo(
const ClampValue& clamp_value)
41 : m_clamp_value(clamp_value)
43 ClampValue clampValue()
const
50 ClampValue m_clamp_value;
53template <
typename DataType>
57 return { { -122334353.245, +983973536.324 } };
59template <> BuildInfo<long double> _getFloatBuildInfo<long double>()
61 return { { -334353.245, +73536.324 } };
65 return { { -334353.245, +73536.324 } };
69 return { { -14353.245f, 3536.324f } };
81 if constexpr (
sizeof(DataType) == 1)
82 return { { -25, 32 } };
83 if constexpr (
sizeof(DataType) == 2)
84 return { { -212, 345 } };
85 if constexpr (
sizeof(DataType) == 4)
86 return { { -14353, 12345 } };
87 if constexpr (
sizeof(DataType) == 8)
88 return { { -234353, 452345 } };
89 if constexpr (
sizeof(DataType) == 16)
90 return { { -33435332, 9232023 } };
94 if constexpr (
sizeof(DataType) == 1)
96 if constexpr (
sizeof(DataType) == 2)
97 return { { 0, 721 } };
98 if constexpr (
sizeof(DataType) == 4)
99 return { { 0, 29540 } };
100 if constexpr (
sizeof(DataType) == 8)
101 return { { 0, 1290325 } };
102 if constexpr (
sizeof(DataType) == 16)
103 return { { 0, 931290325 } };
109template <
typename DataType>
112template <
typename DataType>
117 using value_type = DataType;
122 : m_min_clamp(build_info.clampValue().first)
123 , m_max_clamp(build_info.clampValue().second)
128 DataType minClamp()
const {
return m_min_clamp; }
129 DataType maxClamp()
const {
return m_max_clamp; }
133 DataType m_min_clamp = {};
134 DataType m_max_clamp = {};
140template <
typename DataType,
typename RandomGeneratorDataType = DataType>
141class IntegerFillTraitsT
142:
public FillTraitsBaseT<DataType>
144 using BaseClass = FillTraitsBaseT<DataType>;
148 using UniformGeneratorType = std::uniform_int_distribution<RandomGeneratorDataType>;
153 : BaseClass(impl::_getIntegerBuildInfo<DataType>(std::is_signed<DataType>{}))
160template <
typename DataType,
typename RandomGeneratorDataType = DataType>
161class FloatFillTraitsT
162:
public FillTraitsBaseT<DataType>
164 using BaseClass = FillTraitsBaseT<DataType>;
168 using UniformGeneratorType = std::uniform_real_distribution<RandomGeneratorDataType>;
172 explicit FloatFillTraitsT()
173 : BaseClass(impl::_getFloatBuildInfo<DataType>())
182:
public IntegerFillTraitsT<char,std::conditional<std::is_signed_v<char>,short,unsigned short>::type>
188:
public IntegerFillTraitsT<signed char,short>
194:
public IntegerFillTraitsT<unsigned char,unsigned short>
200:
public IntegerFillTraitsT<short>
206:
public IntegerFillTraitsT<unsigned short>
212:
public IntegerFillTraitsT<int>
218:
public IntegerFillTraitsT<unsigned int>
224:
public IntegerFillTraitsT<long>
230:
public IntegerFillTraitsT<unsigned long>
236:
public IntegerFillTraitsT<long long>
242:
public IntegerFillTraitsT<unsigned long long>
249:
public IntegerFillTraitsT<Int128, Int64>
258:
public FloatFillTraitsT<float>
264:
public FloatFillTraitsT<double>
270:
public FloatFillTraitsT<long double>
276:
public FloatFillTraitsT<BFloat16, float>
282:
public FloatFillTraitsT<Float16, float>
288:
public FloatFillTraitsT<Float128, long double>
300namespace Arccore::ValueFiller
306template <
typename DataType>
inline
309 std::seed_seq rng_seed{ seed };
310 using TraitsType = impl::FillTraitsT<DataType>;
311 using UniformGeneratorType =
typename TraitsType::UniformGeneratorType;
312 TraitsType traits_value;
313 std::mt19937_64 randomizer(rng_seed);
314 UniformGeneratorType rng_distrib(traits_value.minClamp(), traits_value.maxClamp());
316 Int64 n1 = values.
size();
317 for (Int32 i = 0; i < n1; ++i) {
318 values[i] =
static_cast<DataType
>(rng_distrib(randomizer));
Déclarations des types de la composante 'base' de Arccore.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
Arcane::Float128 Float128
Type représentant un floattan sur 128 bits.
Arcane::BFloat16 BFloat16
Type 'Brain Float16'.
Arcane::Float16 Float16
Type 'Float16' (binary16)
Arcane::Int128 Int128
Type représentant un entier sur 128 bits.