From 346d979dcdea3e3f37d3ad55680b4f0469d7220c Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 27 May 2026 15:58:45 +0200 Subject: Dangliung --- lib/core/c++/math/n_closest.hpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/core/c++/math/n_closest.hpp (limited to 'lib/core/c++/math') diff --git a/lib/core/c++/math/n_closest.hpp b/lib/core/c++/math/n_closest.hpp new file mode 100644 index 0000000..ddc89be --- /dev/null +++ b/lib/core/c++/math/n_closest.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "../common.hpp" +#include "../iterator.hpp" + +namespace kel { +namespace lbm { + +template +auto n_closest_read(saw::data, const saw::data>& frac_ind){ + + auto shift_frac_ind = frac_ind; + for(uint64_t i{0u}; i < D; ++i){ + + shift_frac_ind.at({{i}}) = shift_frac_ind.at({{i}}) + saw::data{0.5}; + if(shift_frac_ind.at({{i}}).get() < 0){ + shift_frac_ind.at({{i}}) = {}; + } + } + + auto shift_ind = frac_ind.template cast_to(); +} +} +} -- cgit v1.2.3 From 2dd7c95a111a930e8e23140ab3fec074e7de4c8c Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 29 May 2026 21:56:48 +0200 Subject: Dangling --- lib/core/c++/math/math.hpp | 4 ++++ lib/core/c++/math/n_closest.hpp | 24 ++++++++++++++++++++++-- lib/core/c++/math/round.hpp | 26 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 lib/core/c++/math/math.hpp create mode 100644 lib/core/c++/math/round.hpp (limited to 'lib/core/c++/math') diff --git a/lib/core/c++/math/math.hpp b/lib/core/c++/math/math.hpp new file mode 100644 index 0000000..3920bec --- /dev/null +++ b/lib/core/c++/math/math.hpp @@ -0,0 +1,4 @@ +#pragma once + +#include "n_linear.hpp" +#include "n_closest.hpp" diff --git a/lib/core/c++/math/n_closest.hpp b/lib/core/c++/math/n_closest.hpp index ddc89be..13414e2 100644 --- a/lib/core/c++/math/n_closest.hpp +++ b/lib/core/c++/math/n_closest.hpp @@ -6,8 +6,8 @@ namespace kel { namespace lbm { -template -auto n_closest_read(saw::data, const saw::data>& frac_ind){ +template +saw::data n_closest_read(const saw::data,Encode>& f, const saw::data>& frac_ind){ auto shift_frac_ind = frac_ind; for(uint64_t i{0u}; i < D; ++i){ @@ -19,6 +19,26 @@ auto n_closest_read(saw::data, const saw::data>& f } auto shift_ind = frac_ind.template cast_to(); + + return f.at(shift_ind); } + +template +void n_closest_add(saw::data,Encode>& f, const saw::data>& frac_ind, const saw::data& val){ + auto shift_frac_ind = frac_ind; + for(uint64_t i{0u}; i < D; ++i){ + + shift_frac_ind.at({{i}}) = shift_frac_ind.at({{i}}) + saw::data{0.5}; + if(shift_frac_ind.at({{i}}).get() < 0){ + shift_frac_ind.at({{i}}) = {}; + } + } + + auto shift_ind = frac_ind.template cast_to(); + auto& f_i = f.at(shift_ind); + + f_i = f_i + val; +} + } } diff --git a/lib/core/c++/math/round.hpp b/lib/core/c++/math/round.hpp new file mode 100644 index 0000000..d3a2586 --- /dev/null +++ b/lib/core/c++/math/round.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "../common.hpp" + +namespace kel { +namespace lbm { + +template +saw::data> round_to_unsigned(const saw::data>& inp){ + saw::data> rv; + + auto zero = static_cast::type>(0); + auto half = static_cast::type>(0.5); + + for(uint64_t i{0u}; i < D; ++i){ + auto val = inp.at({{i}}).get()+half; + val = std::max(zero,val); + + rv.at({i}).set(static_cast(val)); + } + + return rv; +} + +} +} -- cgit v1.2.3 From 7fd9bfd5946472230a3b74c52f88e19c15741faf Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 1 Jun 2026 17:21:44 +0200 Subject: I seem to have no clue what I'm doing --- lib/core/c++/math/n_closest.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lib/core/c++/math') diff --git a/lib/core/c++/math/n_closest.hpp b/lib/core/c++/math/n_closest.hpp index 13414e2..ac0fe2f 100644 --- a/lib/core/c++/math/n_closest.hpp +++ b/lib/core/c++/math/n_closest.hpp @@ -7,7 +7,7 @@ namespace kel { namespace lbm { template -saw::data n_closest_read(const saw::data,Encode>& f, const saw::data>& frac_ind){ +saw::data n_closest_read(const saw::data,Encode>& f, const saw::data>& frac_ind){ auto shift_frac_ind = frac_ind; for(uint64_t i{0u}; i < D; ++i){ @@ -18,13 +18,16 @@ saw::data n_closest_read(const saw::data } } - auto shift_ind = frac_ind.template cast_to(); + saw::data> shift_ind; + for(uint64_t i{0u}; i < D; ++i){ + shift_ind.at({i}) = frac_ind.at({{i}}).template cast_to(); + } return f.at(shift_ind); } template -void n_closest_add(saw::data,Encode>& f, const saw::data>& frac_ind, const saw::data& val){ +void n_closest_add(const saw::data,Encode>& f, const saw::data>& frac_ind, const saw::data& val){ auto shift_frac_ind = frac_ind; for(uint64_t i{0u}; i < D; ++i){ @@ -34,7 +37,14 @@ void n_closest_add(saw::data,Encode>& f, const saw::data(); + auto f_meta = f.meta(); + saw::data> shift_ind; + for(uint64_t i{0u}; i < D; ++i){ + shift_ind.at({i}) = frac_ind.at({{i}}).template cast_to(); + if(shift_ind.at({i}) < f_meta.at({i})){ + shift_ind.at({i}) = f_meta.at({i}) - 1u; + } + } auto& f_i = f.at(shift_ind); f_i = f_i + val; -- cgit v1.2.3