From e85b713cf31697a3309e12f30ba5759fee1cd3cc Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 20 Mar 2026 16:08:25 +0100 Subject: Trying out n linear interpolation --- lib/core/c++/math/n_linear.hpp | 44 +++++++++++++++++++++++++++++------------- lib/core/tests/math.cpp | 20 +++++++++++++++++++ 2 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 lib/core/tests/math.cpp (limited to 'lib/core') diff --git a/lib/core/c++/math/n_linear.hpp b/lib/core/c++/math/n_linear.hpp index 62906cd..4f47965 100644 --- a/lib/core/c++/math/n_linear.hpp +++ b/lib/core/c++/math/n_linear.hpp @@ -6,24 +6,42 @@ namespace kel { namespace lbm { template -void n_linear_interpolate(const saw::data& field, const saw::data>& pos){ +auto n_linear_interpolate(const saw::data& field, const saw::data>& pos){ + // Pos auto pos_bound = pos; + + // Dimensions auto meta = field.dims(); - saw::data ind; + + // Lower Index + saw::data> ind; + for(saw::data i{0u}; i < saw::data{D}; ++i){ - pos_bound.at(i).set( - std::max( - std::min( - meta.at(i).template cast_to().get(), - pos.at(i).get() + 1.5 - ), - 1, - ) - -1 - ); - ind.at(i) = pos_bound.at(i).template cast_to(); + // Native Positive i + auto npos_i = pos.at({i}).get(); + + { + // Ok I want to stay in bounds + npos_i = std::min(npos_i,meta.at(i).get()-1.0); + npos_i = std::max(npos_i,1.0); + } + + // Native Index i + auto nind_i = static_cast(std::floor(npos_i))-1ul; + + // Set index to i + ind.at(i).set(nind_i); } + saw::data> pos_frac; + for(saw::data i{0u}; i < saw::data{D}; ++i){ + pos_frac.at({i}) = pos_bound.at({i}) - ind.at(i).template cast_to(); + } + + // Base value + auto res = field.at(ind); + + constexpr uint64_t d_corners = 1ull << D; } } } diff --git a/lib/core/tests/math.cpp b/lib/core/tests/math.cpp new file mode 100644 index 0000000..738d637 --- /dev/null +++ b/lib/core/tests/math.cpp @@ -0,0 +1,20 @@ +#include + +#include "../c++/math/n_linear.hpp" + +namespace { +namespace sch { +using namespace saw::schema; +} + +SAW_TEST("Math 2-Linear"){ + using namespace kel; + + saw::data,32u,32u>> field; + + saw::data> pos; + + SAW_EXPECT(true, "Default true check"); +} + +} -- cgit v1.2.3