From 60eefb228c9b5c2846d3640d68ae5a7ccb0c254d Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 1 Jun 2026 16:09:22 +0200 Subject: Adding unary - operator --- modules/codec/c++/data.hpp | 4 ++++ modules/codec/c++/data_math.hpp | 13 +++++++++++++ modules/codec/tests/math.cpp | 2 ++ 3 files changed, 19 insertions(+) (limited to 'modules') 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 operator-(const data& rhs)const{ return {get() - rhs.get()}; } + + constexpr data operator-() const { + return {-get()}; + } constexpr data& operator++() { set(get() + static_cast::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, encode::Native> operator-() const { + data, encode::Native> c; + + rank_iterator::in_fixed_bounds([&](const data, encode::Native>& index) -> error_or{ + c.at(index) = -at(index); + return make_void(); + }); + + return c; + } + + + template data, encode::Native> cast_to() const { data, 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"){ -- cgit v1.2.3