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>;
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 } };
63template <> BuildInfo<double> _getFloatBuildInfo<double>()
65 return { { -334353.245, +73536.324 } };
67template <> BuildInfo<float> _getFloatBuildInfo<float>()
69 return { { -14353.245f, 3536.324f } };
71template <> BuildInfo<BFloat16> _getFloatBuildInfo<BFloat16>()
75template <> BuildInfo<Float16> _getFloatBuildInfo<Float16>()
79template <
typename DataType> BuildInfo<DataType> _getIntegerBuildInfo(std::true_type)
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 } };
92template <
typename DataType> BuildInfo<DataType> _getIntegerBuildInfo(std::false_type)
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>
148 using UniformGeneratorType = std::uniform_int_distribution<RandomGeneratorDataType>;
153 :
BaseClass(impl::_getIntegerBuildInfo<DataType>(std::is_signed<DataType>{}))
160template <
typename DataType,
typename RandomGeneratorDataType = DataType>
168 using UniformGeneratorType = std::uniform_real_distribution<RandomGeneratorDataType>;
173 :
BaseClass(impl::_getFloatBuildInfo<DataType>())
182:
public IntegerFillTraitsT<char,std::conditional<std::is_signed_v<char>,short,unsigned short>::type>
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());
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.
Type flottant sur 128 bits.
Type flottant demi-précision.
Type entier sur 128 bits.
constexpr ARCCORE_HOST_DEVICE SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
Arccore::Float16 Float16
Type 'Float16' (binary16)
Arccore::BFloat16 BFloat16
Type 'Brain Float16'.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.