diff --git a/include/rotgen/common/ref.hpp b/include/rotgen/common/ref.hpp index de58989..62720d6 100644 --- a/include/rotgen/common/ref.hpp +++ b/include/rotgen/common/ref.hpp @@ -36,6 +36,10 @@ namespace rotgen using parent::prod; using parent::mean; using parent::trace; + using parent::cwiseAbs; + using parent::cwiseAbs2; + using parent::cwiseInverse; + using parent::cwiseSqrt; using parent::maxCoeff; using parent::minCoeff; using parent::norm; @@ -104,6 +108,10 @@ namespace rotgen using parent::prod; using parent::mean; using parent::trace; + using parent::cwiseAbs; + using parent::cwiseAbs2; + using parent::cwiseInverse; + using parent::cwiseSqrt; using parent::maxCoeff; using parent::minCoeff; using parent::norm; diff --git a/include/rotgen/dynamic/block.hpp b/include/rotgen/dynamic/block.hpp index 977f4a7..e67c612 100644 --- a/include/rotgen/dynamic/block.hpp +++ b/include/rotgen/dynamic/block.hpp @@ -129,11 +129,15 @@ namespace rotgen concrete_type adjoint() const { - return concrete_type(static_cast(*this).adjoint()); + return concrete_type(static_cast(*this).adjoint()); } - void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); } + concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); } + concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); } + void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } friend bool operator==(block const& lhs, block const& rhs) diff --git a/include/rotgen/dynamic/map.hpp b/include/rotgen/dynamic/map.hpp index 1a9b02e..c8d5d8d 100644 --- a/include/rotgen/dynamic/map.hpp +++ b/include/rotgen/dynamic/map.hpp @@ -105,6 +105,11 @@ namespace rotgen return concrete_type(static_cast(*this).adjoint()); } + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); } + concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); } + concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); } + void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } diff --git a/include/rotgen/dynamic/matrix.hpp b/include/rotgen/dynamic/matrix.hpp index 02afd79..ed80384 100644 --- a/include/rotgen/dynamic/matrix.hpp +++ b/include/rotgen/dynamic/matrix.hpp @@ -98,6 +98,11 @@ namespace rotgen void transposeInPlace() { parent::transposeInPlace(); } void adjointInPlace() { parent::adjointInPlace(); } + matrix cwiseAbs() const { return matrix(base().cwiseAbs()); } + matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); } + matrix cwiseInverse() const { return matrix(base().cwiseInverse()); } + matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); } + friend bool operator==(matrix const& lhs, matrix const& rhs) { return static_cast(lhs) == static_cast(rhs); diff --git a/include/rotgen/fixed/block.hpp b/include/rotgen/fixed/block.hpp index 1a99ee1..4a7c0f3 100644 --- a/include/rotgen/fixed/block.hpp +++ b/include/rotgen/fixed/block.hpp @@ -140,6 +140,30 @@ namespace rotgen void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } + auto cwiseAbs() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()}; + else return base().cwiseAbs(); + } + + auto cwiseAbs2() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); + } + + auto cwiseInverse() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()}; + else return base().cwiseInverse(); + } + + auto cwiseSqrt() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); + } + static concrete_type Constant(value_type value) requires (Rows != -1 && Cols != -1) { return parent::Constant(Rows, Cols, static_cast(value)); diff --git a/include/rotgen/fixed/map.hpp b/include/rotgen/fixed/map.hpp index 1d36ea8..329e411 100644 --- a/include/rotgen/fixed/map.hpp +++ b/include/rotgen/fixed/map.hpp @@ -121,6 +121,30 @@ namespace rotgen return *this; } + auto cwiseAbs() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()}; + else return base().cwiseAbs(); + } + + auto cwiseAbs2() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); + } + + auto cwiseInverse() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()}; + else return base().cwiseInverse(); + } + + auto cwiseSqrt() const + { + if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); + } + auto transpose() const { if constexpr(use_expression_templates) return base().transpose(); diff --git a/include/rotgen/fixed/matrix.hpp b/include/rotgen/fixed/matrix.hpp index de8b989..3d53ef6 100644 --- a/include/rotgen/fixed/matrix.hpp +++ b/include/rotgen/fixed/matrix.hpp @@ -139,6 +139,30 @@ namespace rotgen void transposeInPlace() { parent::transposeInPlace(); } void adjointInPlace() { parent::adjointInPlace(); } + auto cwiseAbs() const + { + if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs()}; + else return base().cwiseAbs(); + } + + auto cwiseAbs2() const + { + if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); + } + + auto cwiseInverse() const + { + if constexpr(!use_expression_templates) return matrix{parent::cwiseInverse()}; + else return base().cwiseInverse(); + } + + auto cwiseSqrt() const + { + if constexpr(!use_expression_templates) return matrix{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); + } + void resize(int new_rows, int new_cols) requires(Rows == -1 && Cols == -1) { parent::resize(new_rows, new_cols); diff --git a/include/rotgen/functions.hpp b/include/rotgen/functions.hpp index 2864645..84949da 100644 --- a/include/rotgen/functions.hpp +++ b/include/rotgen/functions.hpp @@ -34,6 +34,18 @@ namespace rotgen void transposeInPlace(concepts::entity auto& arg) { arg.transposeInPlace(); } void adjointInPlace(concepts::entity auto& arg) { arg.adjointInPlace(); } + auto abs(concepts::entity auto const& arg) { return arg.cwiseAbs(); } + auto abs2(concepts::entity auto const& arg) { return arg.cwiseAbs2(); } + auto rec(concepts::entity auto const& arg) { return arg.cwiseInverse(); } + auto sqrt(concepts::entity auto const& arg) { return arg.cwiseSqrt(); } + + #if defined(ROTGEN_ENABLE_EXPRESSION_TEMPLATES) + decltype(auto) abs(concepts::eigen_compatible auto const& arg) { return arg.cwiseAbs(); } + decltype(auto) abs2(concepts::eigen_compatible auto const& arg) { return arg.cwiseAbs2(); } + decltype(auto) rec(concepts::eigen_compatible auto const& arg) { return arg.cwiseInverse(); } + decltype(auto) sqrt(concepts::eigen_compatible auto const& arg) { return arg.cwiseSqrt(); } + #endif + auto trace(concepts::entity auto const& arg) { return arg.trace(); } auto squaredNorm(concepts::entity auto const& arg) { return arg.squaredNorm(); } auto norm(concepts::entity auto const& arg) { return arg.norm(); } diff --git a/include/rotgen/impl/block_model.hpp b/include/rotgen/impl/block_model.hpp index a446ead..395c847 100644 --- a/include/rotgen/impl/block_model.hpp +++ b/include/rotgen/impl/block_model.hpp @@ -50,6 +50,11 @@ class ROTGEN_EXPORT CLASSNAME SOURCENAME conjugate() const; SOURCENAME adjoint() const; + SOURCENAME cwiseAbs() const; + SOURCENAME cwiseAbs2() const; + SOURCENAME cwiseInverse() const; + SOURCENAME cwiseSqrt() const; + #if !defined(USE_CONST) void transposeInPlace(); void adjointInPlace(); diff --git a/include/rotgen/impl/map_model.hpp b/include/rotgen/impl/map_model.hpp index d2b7b13..e52788e 100644 --- a/include/rotgen/impl/map_model.hpp +++ b/include/rotgen/impl/map_model.hpp @@ -40,6 +40,11 @@ class ROTGEN_EXPORT CLASSNAME SOURCENAME conjugate() const; SOURCENAME adjoint() const; + SOURCENAME cwiseAbs() const; + SOURCENAME cwiseAbs2() const; + SOURCENAME cwiseInverse() const; + SOURCENAME cwiseSqrt() const; + #if !defined(USE_CONST) void transposeInPlace(); void adjointInPlace(); diff --git a/include/rotgen/impl/matrix_model.hpp b/include/rotgen/impl/matrix_model.hpp index 05a522b..81e6beb 100644 --- a/include/rotgen/impl/matrix_model.hpp +++ b/include/rotgen/impl/matrix_model.hpp @@ -38,6 +38,11 @@ class ROTGEN_EXPORT CLASSNAME CLASSNAME conjugate() const; CLASSNAME adjoint() const; + CLASSNAME cwiseAbs() const; + CLASSNAME cwiseAbs2() const; + CLASSNAME cwiseInverse() const; + CLASSNAME cwiseSqrt() const; + void transposeInPlace(); void adjointInPlace(); diff --git a/src/block_model.cpp b/src/block_model.cpp index df4c0af..9d6d136 100644 --- a/src/block_model.cpp +++ b/src/block_model.cpp @@ -239,6 +239,34 @@ struct CLASSNAME::payload return result; } + SOURCENAME CLASSNAME::cwiseAbs() const + { + SOURCENAME result; + storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseAbs().eval()); }); + return result; + } + + SOURCENAME CLASSNAME::cwiseAbs2() const + { + SOURCENAME result; + storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseAbs2().eval()); }); + return result; + } + + SOURCENAME CLASSNAME::cwiseInverse() const + { + SOURCENAME result; + storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseInverse().eval()); }); + return result; + } + + SOURCENAME CLASSNAME::cwiseSqrt() const + { + SOURCENAME result; + storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseSqrt().eval()); }); + return result; + } + SOURCENAME CLASSNAME::adjoint() const { SOURCENAME result; diff --git a/src/map_model.cpp b/src/map_model.cpp index 9c03508..cee0edf 100644 --- a/src/map_model.cpp +++ b/src/map_model.cpp @@ -82,6 +82,34 @@ return result; } + SOURCENAME CLASSNAME::cwiseAbs() const + { + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseAbs().eval()); + return result; + } + + SOURCENAME CLASSNAME::cwiseAbs2() const + { + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseAbs2().eval()); + return result; + } + + SOURCENAME CLASSNAME::cwiseInverse() const + { + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseInverse().eval()); + return result; + } + + SOURCENAME CLASSNAME::cwiseSqrt() const + { + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseSqrt().eval()); + return result; + } + #if !defined(USE_CONST) void CLASSNAME::transposeInPlace() { diff --git a/src/matrix_model.cpp b/src/matrix_model.cpp index 0e48c94..e2b67f5 100644 --- a/src/matrix_model.cpp +++ b/src/matrix_model.cpp @@ -106,6 +106,34 @@ void CLASSNAME::adjointInPlace() storage_->data.adjointInPlace(); } +CLASSNAME CLASSNAME::cwiseAbs() const +{ + CLASSNAME result(*this); + result.storage_->data = storage_->data.cwiseAbs(); + return result; +} + +CLASSNAME CLASSNAME::cwiseAbs2() const +{ + CLASSNAME result(*this); + result.storage_->data = storage_->data.cwiseAbs2(); + return result; +} + +CLASSNAME CLASSNAME::cwiseInverse() const +{ + CLASSNAME result(*this); + result.storage_->data = storage_->data.cwiseInverse(); + return result; +} + +CLASSNAME CLASSNAME::cwiseSqrt() const +{ + CLASSNAME result(*this); + result.storage_->data = storage_->data.cwiseSqrt(); + return result; +} + TYPE CLASSNAME::sum() const { return storage_->data.sum(); } TYPE CLASSNAME::prod() const { return storage_->data.prod(); } TYPE CLASSNAME::mean() const { return storage_->data.mean(); } diff --git a/test/unit/free_functions/functions.cpp b/test/unit/free_functions/size_related.cpp similarity index 99% rename from test/unit/free_functions/functions.cpp rename to test/unit/free_functions/size_related.cpp index 8490d38..9eac1a5 100644 --- a/test/unit/free_functions/functions.cpp +++ b/test/unit/free_functions/size_related.cpp @@ -82,7 +82,3 @@ TTS_CASE("Matrix size-related operations") TTS_EXPECT_NOT_COMPILES(a, { rotgen::resize(a, 4, 5); }); TTS_EXPECT_NOT_COMPILES(a, { rotgen::conservativeResize(a, 4, 5); }); }; - - - -