summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-06-01 16:09:22 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-06-01 16:09:22 +0200
commit60eefb228c9b5c2846d3640d68ae5a7ccb0c254d (patch)
tree569583fd49a257d4f2efd2885ece2c0364d144a2 /modules
parent4a667474433f18c60facd556daa5b73c6e651f4e (diff)
downloadforstio-forstio-60eefb228c9b5c2846d3640d68ae5a7ccb0c254d.tar.gz
Adding unary - operatorHEADmaster
Diffstat (limited to 'modules')
-rw-r--r--modules/codec/c++/data.hpp4
-rw-r--r--modules/codec/c++/data_math.hpp13
-rw-r--r--modules/codec/tests/math.cpp2
3 files changed, 19 insertions, 0 deletions
diff --git a/modules/codec/c++/data.hpp b/modules/codec/c++/data.hpp
index ae9d8eb..79a6ab8 100644
--- a/modules/codec/c++/data.hpp
+++ b/modules/codec/c++/data.hpp
@@ -171,6 +171,10 @@ public:
constexpr data<Schema, encode::Native> operator-(const data<Schema, encode::Native>& rhs)const{
return {get() - rhs.get()};
}
+
+ constexpr data<Schema, encode::Native> operator-() const {
+ return {-get()};
+ }
constexpr data<Schema, encode::Native>& operator++() {
set(get() + static_cast<typename native_data_type<Schema>::type>(1));
diff --git a/modules/codec/c++/data_math.hpp b/modules/codec/c++/data_math.hpp
index 48dae91..9d07eb3 100644
--- a/modules/codec/c++/data_math.hpp
+++ b/modules/codec/c++/data_math.hpp
@@ -131,6 +131,19 @@ public:
return c;
}
+ data<schema::Tensor<Inner, Dims...>, encode::Native> operator-() const {
+ data<schema::Tensor<Inner, Dims...>, encode::Native> c;
+
+ rank_iterator<Dims...>::in_fixed_bounds([&](const data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>, encode::Native>& index) -> error_or<void>{
+ c.at(index) = -at(index);
+ return make_void();
+ });
+
+ return c;
+ }
+
+
+
template<typename InnerChange>
data<schema::Tensor<InnerChange, Dims...>, encode::Native> cast_to() const {
data<schema::Tensor<InnerChange, Dims...>, encode::Native> native_change;
diff --git a/modules/codec/tests/math.cpp b/modules/codec/tests/math.cpp
index 34dcce8..18b6c41 100644
--- a/modules/codec/tests/math.cpp
+++ b/modules/codec/tests/math.cpp
@@ -76,6 +76,8 @@ SAW_TEST("Math/Tensor"){
SAW_EXPECT(d.at({{1u,0u}}).get() == 1.0, std::string{"Unexpected value at (1,0): "} + std::to_string(d.at({{1u,0u}}).get()));
SAW_EXPECT(d.at({{1u,1u}}).get() == 1.0, std::string{"Unexpected value at (1,1): "} + std::to_string(d.at({{1u,1u}}).get()));
}
+
+ auto e = -a;
}
SAW_TEST("Math/Rotate"){