From f36a545b0f814d8d35e87262dd80d4d8d8dc4405 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 6 Aug 2025 14:20:21 +0200 Subject: Extended math setup. Need meta iteration for multi dim array :/ --- modules/codec/c++/data_math.hpp | 37 +++++++++++++++++++++++++++++++++++++ modules/codec/c++/schema_math.hpp | 26 +++++++++++++++++--------- modules/codec/tests/math.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 modules/codec/tests/math.cpp diff --git a/modules/codec/c++/data_math.hpp b/modules/codec/c++/data_math.hpp index a5c50fc..7277168 100644 --- a/modules/codec/c++/data_math.hpp +++ b/modules/codec/c++/data_math.hpp @@ -1,10 +1,12 @@ #pragma once +#include "data.hpp" #include "schema_math.hpp" #include namespace saw { +/* template class data,encode::Native> { public: @@ -61,5 +63,40 @@ public: return mult; } }; +*/ + +template +class data, encode::Native> { +public: + using Schema = schema::Tensor; +private: + data, encode::Native> values_; +public: + data(): + values_{data>{{data{Dims}...}}} + {} + + data& at(const data, encode::Native>& index){ + return values_.at(index); + } + + const data& at(const data, encode::Native>& index) const { + return values_.at(index); + } + + data& operator()(const data, encode::Native>& index){ + return values_.at(index); + } + + const data& operator()(const data, encode::Native>& index) const { + return values_.at(index); + } + + data, encode::Native> operator+(const data, encode::Native>& rhs) const { + data, encode::Native> c; + + return {}; + } +}; } diff --git a/modules/codec/c++/schema_math.hpp b/modules/codec/c++/schema_math.hpp index 203b88a..ddf95a0 100644 --- a/modules/codec/c++/schema_math.hpp +++ b/modules/codec/c++/schema_math.hpp @@ -4,17 +4,25 @@ namespace saw { namespace schema { -template -struct Complex {}; -template -struct Quaternion { - static_assert(is_primitive::value, "Quaternions assume a primitive type"); +/** + * Tensor Schema. I think I need this due to the amount of mathematical operators being able to be represented by this one construct. + */ +template +struct Tensor { + static constexpr uint64_t Rank = sizeof...(D); + static constexpr std::array Dimension{D...}; + static constexpr string_literal name = "Tensor"; }; -template -struct Euler { - static_assert(is_primitive::value, "Quaternions assume a primitive type"); -}; +template +using Scalar = Tensor; + +template +using Vector = Tensor; + +template +using Matrix = Tensor; + } } diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp new file mode 100644 index 0000000..4240df5 --- /dev/null +++ b/modules/codec/tests/math.cpp @@ -0,0 +1,32 @@ +#include +#include "../c++/data.hpp" +#include "../c++/data_math.hpp" +#include "../c++/csv.hpp" + +#include + +namespace { +namespace sch { +using namespace saw::schema; +} +/* +SAW_TEST("Math/Basic"){ + using namespace saw; + + data> a; + data> b; + + auto c = a + b; +} +*/ + +SAW_TEST("Math/Tensor"){ + using namespace saw; + + data > a; + + data > b; + + auto c = a + b; +} +} -- cgit v1.2.3