From c0549d71b2109f10c1238db8b22362e7826ba61b Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Sun, 5 Jul 2026 15:59:23 +0200 Subject: Just rename from lib to modules --- modules/core/c++/flatten.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/core/c++/flatten.hpp (limited to 'modules/core/c++/flatten.hpp') diff --git a/modules/core/c++/flatten.hpp b/modules/core/c++/flatten.hpp new file mode 100644 index 0000000..1609589 --- /dev/null +++ b/modules/core/c++/flatten.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include + +namespace kel { +namespace lbm { +namespace sch { +using namespace saw::schema; +} + +template +struct flatten_index { +public: + template + static constexpr saw::data stride(const saw::data>& meta) { + if constexpr (i > 0u){ + return stride(meta) * meta.at({i-1u}); + } + + return 1u; + } +private: + /// 2,3,4 => 2,6,24 + /// i + j * 2 + k * 3*2 + /// 1 + 2 * 2 + 3 * 3*2 = 1+4+18 = 23 + template + static void apply_i(saw::data& flat_ind, const saw::data>& index, const saw::data>& meta){ + if constexpr ( D > i ) { + flat_ind = flat_ind + index.at({i}) * stride(meta); + apply_i(flat_ind,index,meta); + } + } +public: + static saw::data apply(const saw::data>& index, const saw::data>& meta){ + saw::data flat_ind{0u}; + apply_i<0u>(flat_ind, index, meta); + return flat_ind; + } +}; +} +} -- cgit v1.2.3