summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-08-06 14:20:21 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-08-06 14:20:21 +0200
commitf36a545b0f814d8d35e87262dd80d4d8d8dc4405 (patch)
tree828927280b83f6f43eb0b30bc3c99c3d3546511e /modules
parent25ccfc72c5851b2ff59daadad3aeef85b22a6bce (diff)
Extended math setup. Need meta iteration for multi dim array :/
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/data_math.hpp37
-rw-r--r--modules/codec/c++/schema_math.hpp26
-rw-r--r--modules/codec/tests/math.cpp32
3 files changed, 86 insertions, 9 deletions
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 <cmath>
namespace saw {
+/*
template<typename T>
class data<schema::Quaternion<T>,encode::Native> {
public:
@@ -61,5 +63,40 @@ public:
return mult;
}
};
+*/
+
+template<typename Inner, uint64_t... Dims>
+class data<schema::Tensor<Inner, Dims...>, encode::Native> {
+public:
+ using Schema = schema::Tensor<Inner, Dims...>;
+private:
+ data<schema::Array<Inner,Schema::Rank>, encode::Native> values_;
+public:
+ data():
+ values_{data<schema::FixedArray<schema::UInt64,sizeof...(Dims)>>{{data<schema::UInt64, encode::Native>{Dims}...}}}
+ {}
+
+ data<Inner, encode::Native>& at(const data<schema::FixedArray<schema::UInt64>, encode::Native>& index){
+ return values_.at(index);
+ }
+
+ const data<Inner, encode::Native>& at(const data<schema::FixedArray<schema::UInt64>, encode::Native>& index) const {
+ return values_.at(index);
+ }
+
+ data<Inner, encode::Native>& operator()(const data<schema::FixedArray<schema::UInt64>, encode::Native>& index){
+ return values_.at(index);
+ }
+
+ const data<Inner, encode::Native>& operator()(const data<schema::FixedArray<schema::UInt64>, encode::Native>& index) const {
+ return values_.at(index);
+ }
+
+ data<schema::Tensor<Inner, Dims...>, encode::Native> operator+(const data<schema::Tensor<Inner, Dims...>, encode::Native>& rhs) const {
+ data<schema::Tensor<Inner, Dims...>, 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<typename T>
-struct Complex {};
-template<typename T>
-struct Quaternion {
- static_assert(is_primitive<T>::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<typename Inner, uint64_t... D>
+struct Tensor {
+ static constexpr uint64_t Rank = sizeof...(D);
+ static constexpr std::array<uint64_t,Rank> Dimension{D...};
+ static constexpr string_literal name = "Tensor";
};
-template<typename T, uint64_t D>
-struct Euler {
- static_assert(is_primitive<T>::value, "Quaternions assume a primitive type");
-};
+template<typename Inner>
+using Scalar = Tensor<Inner>;
+
+template<typename Inner, uint64_t D>
+using Vector = Tensor<Inner,D>;
+
+template<typename Inner, uint64_t D1, uint64_t D2>
+using Matrix = Tensor<Inner,D1,D2>;
+
}
}
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 <forstio/test/suite.hpp>
+#include "../c++/data.hpp"
+#include "../c++/data_math.hpp"
+#include "../c++/csv.hpp"
+
+#include <iostream>
+
+namespace {
+namespace sch {
+using namespace saw::schema;
+}
+/*
+SAW_TEST("Math/Basic"){
+ using namespace saw;
+
+ data<sch::Vector<sch::Float64,2u>> a;
+ data<sch::Vector<sch::Float64,2u>> b;
+
+ auto c = a + b;
+}
+*/
+
+SAW_TEST("Math/Tensor"){
+ using namespace saw;
+
+ data<sch::Matrix<sch::Float64,2u,2u> > a;
+
+ data<sch::Matrix<sch::Float64,2u,2u> > b;
+
+ auto c = a + b;
+}
+}