From 696408d8b222d916bf816de01a6e4e9f341ac062 Mon Sep 17 00:00:00 2001 From: Adam Osewski Date: Thu, 26 May 2022 15:33:05 +0200 Subject: [PATCH] UniforFill with integer values. --- library/include/ck/library/utility/fill.hpp | 44 +++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/library/include/ck/library/utility/fill.hpp b/library/include/ck/library/utility/fill.hpp index f44aec969d..dfd3e2ea85 100644 --- a/library/include/ck/library/utility/fill.hpp +++ b/library/include/ck/library/utility/fill.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include "data_type.hpp" @@ -8,35 +9,10 @@ namespace ck { namespace utils { -// template -// struct FillUniform; - -// TODO: what's wrong with this specialization??? -// err: segmentation fault in mt19937 - infinite loop like. -// template -// struct FillUniform::value && -// !std::is_same::value>::type> -// { -// int a_{0}; -// int b_{5}; -// // T a_ = T{0}; -// // T b_ = T{5}; - -// template -// void operator()(ForwardIter first, ForwardIter last) const -// { -// std::mt19937 gen{11939}; -// std::uniform_int_distribution dis(a_, b_); -// std::generate(first, last, [&dis, &gen]() { return ck::type_convert(dis(gen)); }); -// } -// }; - -// struct FillUniform::value || -// std::is_same::value>::type> template struct FillUniform { - float a_{0}; + float a_{-5}; float b_{5}; template @@ -48,6 +24,22 @@ struct FillUniform } }; +template +struct FillUniformIntegerValue +{ + float a_{-5}; + float b_{5}; + + template + void operator()(ForwardIter first, ForwardIter last) const + { + std::mt19937 gen{11939}; + std::uniform_real_distribution<> dis(a_, b_); + std::generate( + first, last, [&dis, &gen]() { return ck::type_convert(std::round(dis(gen))); }); + } +}; + template struct FillMonotonicSeq {