From 4929dbced501d4252e890872abf8e29b7dcfa0e7 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 24 Mar 2026 15:36:49 +0100 Subject: Fixed iterator and compilation issues --- modules/codec/c++/math.hpp | 49 ++++++++++++++++++++++++++++++++++++-------- modules/codec/tests/math.cpp | 3 ++- 2 files changed, 43 insertions(+), 9 deletions(-) (limited to 'modules/codec') diff --git a/modules/codec/c++/math.hpp b/modules/codec/c++/math.hpp index 7524265..2ce8333 100644 --- a/modules/codec/c++/math.hpp +++ b/modules/codec/c++/math.hpp @@ -5,10 +5,33 @@ namespace saw { template class iterator final { +private: + template + static void iterate_over_i( + Func& func, + const data>& start, + const data>& end, + data>& iter + ){ + static_assert(i <= D, "Iterator sanity check"); + if constexpr ( i == D ){ + func(iter); + }else // Has to be i < D due to last static_assert and constexpr if + { + for(iter.at({i}) = start.at({i}); iter.at({i}) < end.at({i}); ++iter.at({i})){ + iterate_over_i(func,start,end,iter); + } + } + } public: - template + static void apply( + Func&& func, + const data>& start, + const data>& end + ){ + data> iter; + iterate_over_i<0u,Func>(func,start,end,iter); } }; namespace math { @@ -160,14 +183,24 @@ data,Encoding> scale( } template -data, Encoding> fill( - const data& filler){ - data, Encoding> tbf; - +void fill( + data, Encoding>& tbf, + const data& filler +){ iterator::apply([&](const auto& index){ tbf.at(index) = filler; }, {}, {{Ds...}}); - return tbf; +} + +template +saw::data, Encoding> sum(const data,Encoding>& tens){ + saw::data, Encoding> s; + + iterator::apply([&](const auto& index){ + s.at({}) = s.at({}) + tens.at(index); + }, {}, {{Ds...}}); + + return s; } } } diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp index 5f4de92..34dcce8 100644 --- a/modules/codec/tests/math.cpp +++ b/modules/codec/tests/math.cpp @@ -31,7 +31,8 @@ SAW_TEST("Math/Tensor Construction"){ SAW_TEST("Math/Tensor Fill"){ using namespace saw; - auto tensor = math::fill({2.5}); + data> tensor; + math::fill(tensor,{2.5}); bool cf{true}; for(uint64_t i = 0u; i < 2u; ++i){ -- cgit v1.2.3