summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-03-24 15:36:49 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-03-24 15:36:49 +0100
commit4929dbced501d4252e890872abf8e29b7dcfa0e7 (patch)
tree2fb476190430fbddb1101deb6697ae8f8b20e38b
parent135c8751041961ef7f66502926d770b93539c252 (diff)
downloadforstio-forstio-dev.tar.gz
Fixed iterator and compilation issuesdev
-rw-r--r--modules/codec/c++/math.hpp49
-rw-r--r--modules/codec/tests/math.cpp3
2 files changed, 43 insertions, 9 deletions
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<uint64_t D>
class iterator final {
+private:
+ template<uint64_t i, typename Func>
+ static void iterate_over_i(
+ Func& func,
+ const data<schema::FixedArray<schema::UInt64,D>>& start,
+ const data<schema::FixedArray<schema::UInt64,D>>& end,
+ data<schema::FixedArray<schema::UInt64,D>>& 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<i+1u,Func>(func,start,end,iter);
+ }
+ }
+ }
public:
- template<typename Func
- void apply(Func&& func){
- /// TODO !!!!
+ template<typename Func>
+ static void apply(
+ Func&& func,
+ const data<schema::FixedArray<schema::UInt64,D>>& start,
+ const data<schema::FixedArray<schema::UInt64,D>>& end
+ ){
+ data<schema::FixedArray<schema::UInt64,D>> iter;
+ iterate_over_i<0u,Func>(func,start,end,iter);
}
};
namespace math {
@@ -160,14 +183,24 @@ data<schema::Vector<T,D>,Encoding> scale(
}
template<typename T, uint64_t... Ds, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING>
-data<schema::Tensor<T,Ds...>, Encoding> fill(
- const data<T,Encoding>& filler){
- data<schema::Tensor<T,Ds...>, Encoding> tbf;
-
+void fill(
+ data<schema::Tensor<T,Ds...>, Encoding>& tbf,
+ const data<T,Encoding>& filler
+){
iterator<sizeof...(Ds)>::apply([&](const auto& index){
tbf.at(index) = filler;
}, {}, {{Ds...}});
- return tbf;
+}
+
+template<typename T, uint64_t... Ds, typename Encoding = FORSTIO_DEFAULT_DATA_ENCODING>
+saw::data<schema::Scalar<T>, Encoding> sum(const data<schema::Tensor<T,Ds...>,Encoding>& tens){
+ saw::data<schema::Scalar<T>, Encoding> s;
+
+ iterator<sizeof...(Ds)>::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<sch::Float64,2u,2u>({2.5});
+ data<schema::Tensor<sch::Float64,2u,2u>> tensor;
+ math::fill(tensor,{2.5});
bool cf{true};
for(uint64_t i = 0u; i < 2u; ++i){