From e151e136d6ca76967749e6f7f39b6a6c8ca65992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jules=20P=C3=A9nuchot?= Date: Wed, 17 Dec 2025 20:48:00 +0100 Subject: [PATCH] Resolve "[API-#2] Pseudo-privatization of rotgen entity member functions" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #18 Co-authored-by: Jules Pénuchot See merge request oss/rotgen!50 --- .clangd | 10 + .gitignore | 1 + .gitlab-ci.yml | 24 +- CMakePresets.json | 24 +- cmake/options.cmake | 4 +- include/rotgen/container/block/dynamic.hpp | 158 +++--- .../rotgen/container/block/dynamic/model.hpp | 83 +-- include/rotgen/container/block/fixed.hpp | 122 +++-- include/rotgen/container/map/dynamic.hpp | 228 ++++---- .../rotgen/container/map/dynamic/model.hpp | 101 ++-- include/rotgen/container/map/fixed.hpp | 116 ++-- include/rotgen/container/matrix/dynamic.hpp | 158 +++--- .../rotgen/container/matrix/dynamic/model.hpp | 71 +-- include/rotgen/container/matrix/fixed.hpp | 275 ++++++---- include/rotgen/container/ref/dynamic.hpp | 112 ++-- include/rotgen/container/ref/fixed.hpp | 130 +++-- include/rotgen/container/ref/functions.hpp | 15 +- include/rotgen/container/ref/generalize.hpp | 9 +- include/rotgen/detail/accept_as_ref.hpp | 38 +- include/rotgen/detail/helpers.hpp | 13 +- include/rotgen/functions/extract.hpp | 76 +-- include/rotgen/functions/functions.hpp | 503 ++++++++++++++---- include/rotgen/functions/generators.hpp | 280 +++++++--- include/rotgen/functions/reshaper.hpp | 111 ++-- src/block/model.cpp | 125 ++--- src/map/model.cpp | 100 ++-- src/matrix/model.cpp | 82 +-- test/integration/extract.cpp | 20 +- test/integration/outer_stride.cpp | 26 +- test/integration/ref_magic.cpp | 6 +- test/unit/block/basic_api.cpp | 37 +- test/unit/block/extract.cpp | 140 ++--- test/unit/block/generators.cpp | 80 +-- test/unit/common/arithmetic.hpp | 6 +- test/unit/common/cwise.hpp | 8 +- test/unit/common/norms.hpp | 4 +- test/unit/common/references.hpp | 9 +- test/unit/functions/rowwise.cpp | 38 +- test/unit/functions/svd.cpp | 6 +- test/unit/map/arithmetic_functions.cpp | 4 +- test/unit/map/basic_api.cpp | 37 +- test/unit/map/cwise.cpp | 14 +- test/unit/map/norms.cpp | 14 +- test/unit/map/strides.cpp | 24 +- test/unit/matrix/arithmetic_functions.cpp | 27 +- test/unit/matrix/basic_api.cpp | 85 +-- test/unit/matrix/constructors.cpp | 74 +-- test/unit/matrix/cwise.cpp | 14 +- test/unit/matrix/inverse.cpp | 16 +- test/unit/matrix/norms.cpp | 14 +- test/unit/matrix/operators.cpp | 92 ++-- test/unit/meta/ref.cpp | 4 +- 52 files changed, 2212 insertions(+), 1556 deletions(-) create mode 100644 .clangd diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..b976251 --- /dev/null +++ b/.clangd @@ -0,0 +1,10 @@ +CompileFlags: + CompilationDatabase: build/debug/ # Use this to change build type for LSP +Diagnostics: + UnusedIncludes: Strict + ClangTidy: + Add: + - 'bugprone-*' + - 'readability-*' + - 'clang-analyzer-core.*' + - 'clang-analyzer-security.*' diff --git a/.gitignore b/.gitignore index cc13b24..1e26de1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ _deps build/* .idea .vscode/* +.clangd diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da88d5f..d164291 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,11 +39,11 @@ test-native-debug: CXX: clang++ CMAKE_PRESET: debug -test-native-debug-static: +test-native-debug-fixed: <<: *test-native variables: CXX: clang++ - CMAKE_PRESET: debug-static + CMAKE_PRESET: debug-fixed test-native-debug-et: <<: *test-native @@ -57,11 +57,11 @@ test-native-release: CXX: clang++ CMAKE_PRESET: release -test-native-release-static: +test-native-release-fixed: <<: *test-native variables: CXX: clang++ - CMAKE_PRESET: release-static + CMAKE_PRESET: release-fixed test-native-release-et: <<: *test-native @@ -78,12 +78,12 @@ test-ubuntu-clang14-debug: CXXFLAGS: --stdlib=libc++ CMAKE_PRESET: debug -test-ubuntu-clang14-debug-static: +test-ubuntu-clang14-debug-fixed: <<: *test-ubuntu2404 variables: CXX: clang++-14 CXXFLAGS: --stdlib=libc++ - CMAKE_PRESET: debug-static + CMAKE_PRESET: debug-fixed test-ubuntu-clang14-debug-et: <<: *test-ubuntu2404 @@ -99,12 +99,12 @@ test-ubuntu-clang14-release: CXXFLAGS: --stdlib=libc++ CMAKE_PRESET: release -test-ubuntu-clang14-release-static: +test-ubuntu-clang14-release-fixed: <<: *test-ubuntu2404 variables: CXX: clang++-14 CXXFLAGS: --stdlib=libc++ - CMAKE_PRESET: release-static + CMAKE_PRESET: release-fixed test-ubuntu-clang14-release-et: <<: *test-ubuntu2404 @@ -121,11 +121,11 @@ test-ubuntu-gcc-debug: CXX: g++ CMAKE_PRESET: debug -test-ubuntu-gcc-debug-static: +test-ubuntu-gcc-debug-fixed: <<: *test-ubuntu2404 variables: CXX: g++ - CMAKE_PRESET: debug-static + CMAKE_PRESET: debug-fixed test-ubuntu-gcc-debug-et: <<: *test-ubuntu2404 @@ -139,11 +139,11 @@ test-ubuntu-gcc-release: CXX: g++ CMAKE_PRESET: release -test-ubuntu-gcc-release-static: +test-ubuntu-gcc-release-fixed: <<: *test-ubuntu2404 variables: CXX: g++ - CMAKE_PRESET: release-static + CMAKE_PRESET: release-fixed test-ubuntu-gcc-release-et: <<: *test-ubuntu2404 diff --git a/CMakePresets.json b/CMakePresets.json index 49a1a51..b3b93dd 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -42,21 +42,21 @@ } }, { - "name": "release-static", - "displayName": "Release (Static size)", - "description": "Release (Static size) build", + "name": "release-fixed", + "displayName": "Release (Fixed size)", + "description": "Release (Fixed size) build", "generator": "Ninja", - "binaryDir": "${sourceDir}/build/release-static", + "binaryDir": "${sourceDir}/build/release-fixed", "cacheVariables": { "ROTGEN_MAX_SIZE": "16" } }, { - "name": "debug-static", - "displayName": "Debug (Static size)", - "description": "Debug (Static size) build", + "name": "debug-fixed", + "displayName": "Debug (Fixed size)", + "description": "Debug (Fixed size) build", "generator": "Ninja", - "binaryDir": "${sourceDir}/build/debug-static", + "binaryDir": "${sourceDir}/build/debug-fixed", "cacheVariables": { "ROTGEN_MAX_SIZE": "16" } @@ -90,8 +90,8 @@ "configurePreset": "release" }, { - "name": "release-static", - "configurePreset": "release-static" + "name": "release-fixed", + "configurePreset": "release-fixed" }, { "name": "release-et", @@ -102,8 +102,8 @@ "configurePreset": "debug" }, { - "name": "debug-static", - "configurePreset": "debug-static" + "name": "debug-fixed", + "configurePreset": "debug-fixed" }, { "name": "debug-et", diff --git a/cmake/options.cmake b/cmake/options.cmake index c47c01f..134bf58 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -58,10 +58,10 @@ function(print_configuration_summary FORCE_DYNAMIC_VAR FORCE_CONFIG_REASON MAX_S if(${FORCE_DYNAMIC_VAR}) message(STATUS " Configuration mode: DYNAMIC") if(${FORCE_CONFIG_REASON}) - message(STATUS " Reason : No static size options were provided") + message(STATUS " Reason : No fixed size options were provided") endif() else() - message(STATUS " Configuration mode: STATIC") + message(STATUS " Configuration mode: FIXED SIZE") message(STATUS " Expression Templates: ${ROTGEN_ENABLE_EXPRESSION_TEMPLATES}") endif() diff --git a/include/rotgen/container/block/dynamic.hpp b/include/rotgen/container/block/dynamic.hpp index e9b5830..794575f 100644 --- a/include/rotgen/container/block/dynamic.hpp +++ b/include/rotgen/container/block/dynamic.hpp @@ -90,22 +90,22 @@ namespace rotgen } else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime) { - auto r = other.rows(); - auto c = other.cols(); + auto r = other._rows(); + auto c = other._cols(); - ROTGEN_ASSERT((r == 1 || c == 1), "Block assignment from dynamic sized " - "source doesn't match static size"); + ROTGEN_ASSERT(r == 1 || c == 1, "Block assignment from dynamic sized " + "source doesn't match static size"); for (rotgen::Index i = 0; i < parent::size(); ++i) (*this)[i] = other(r == 1 ? 0 : i, c == 1 ? 0 : i); } else { - ROTGEN_ASSERT(parent::rows() == other.rows() && - parent::cols() == other.cols(), + ROTGEN_ASSERT(parent::_rows() == other._rows() && + parent::_cols() == other._cols(), "Block assignment size mismatch"); - for (rotgen::Index r = 0; r < parent::rows(); ++r) - for (rotgen::Index c = 0; c < parent::cols(); ++c) + for (rotgen::Index r = 0; r < parent::_rows(); ++r) + for (rotgen::Index c = 0; c < parent::_cols(); ++c) (*this)(r, c) = other(r, c); } return *this; @@ -226,66 +226,69 @@ namespace rotgen return (*this)(i); } - concrete_type evaluate() const { return concrete_type{*this}; } + concrete_type _evaluate() const { return concrete_type{*this}; } - decltype(auto) noalias() const { return *this; } + decltype(auto) _noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + decltype(auto) _noalias() { return *this; } - concrete_type normalized() const + concrete_type _normalized() const requires(IsVectorAtCompileTime) { - return concrete_type(base().normalized()); + return concrete_type(base()._normalized()); } - transposed_type transpose() const + transposed_type _transpose() const { - return transposed_type(base().transpose()); + return transposed_type(base()._transpose()); } - concrete_type conjugate() const + concrete_type _conjugate() const { - return concrete_type(base().conjugate()); + return concrete_type(base()._conjugate()); } - transposed_type adjoint() const + transposed_type _adjoint() const { - return transposed_type(base().adjoint()); + return transposed_type(base()._adjoint()); } - concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } - - concrete_type cwiseAbs2() const + concrete_type _cwiseAbs() const { - return concrete_type(base().cwiseAbs2()); + return concrete_type(base()._cwiseAbs()); } - concrete_type cwiseInverse() const + concrete_type _cwiseAbs2() const { - return concrete_type(base().cwiseInverse()); + return concrete_type(base()._cwiseAbs2()); } - concrete_type cwiseSqrt() const + concrete_type _cwiseInverse() const { - return concrete_type(base().cwiseSqrt()); + return concrete_type(base()._cwiseInverse()); } - void normalize() + concrete_type _cwiseSqrt() const + { + return concrete_type(base()._cwiseSqrt()); + } + + void _normalize() requires(!is_immutable && IsVectorAtCompileTime) { - parent::normalize(); + parent::_normalize(); } - void transposeInPlace() + void _transposeInPlace() requires(!is_immutable) { - parent::transposeInPlace(); + parent::_transposeInPlace(); } - void adjointInPlace() + void _adjointInPlace() requires(!is_immutable) { - parent::adjointInPlace(); + parent::_adjointInPlace(); } friend bool operator==(block const& lhs, block const& rhs) @@ -336,37 +339,37 @@ namespace rotgen return *this; } - auto minCoeff() const { return parent::minCoeff(); } + auto _minCoeff() const { return parent::_minCoeff(); } - auto maxCoeff() const { return parent::maxCoeff(); } + auto _maxCoeff() const { return parent::_maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::minCoeff(&r, &c); + auto result = parent::_minCoeff(&r, &c); *row = r; *col = c; return result; } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::maxCoeff(&r, &c); + auto result = parent::_maxCoeff(&r, &c); *row = r; *col = c; return result; } - static concrete_type Zero() + static concrete_type _Zero() requires(Rows != -1 && Cols != -1) { - return parent::Zero(Rows, Cols); + return parent::_Zero(Rows, Cols); } - static concrete_type Zero(int rows, int cols) + static concrete_type _Zero(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -374,16 +377,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Zero(rows, cols); + return parent::_Zero(rows, cols); } - static concrete_type Ones() + static concrete_type _Ones() requires(Rows != -1 && Cols != -1) { - return parent::Ones(Rows, Cols); + return parent::_Ones(Rows, Cols); } - static concrete_type Ones(int rows, int cols) + static concrete_type _Ones(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -391,16 +394,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Ones(rows, cols); + return parent::_Ones(rows, cols); } - static concrete_type Constant(value_type value) + static concrete_type _Constant(value_type value) requires(Rows != -1 && Cols != -1) { - return parent::Constant(Rows, Cols, static_cast(value)); + return parent::_Constant(Rows, Cols, static_cast(value)); } - static concrete_type Constant(int rows, int cols, value_type value) + static concrete_type _Constant(int rows, int cols, value_type value) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -408,16 +411,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Constant(rows, cols, static_cast(value)); + return parent::_Constant(rows, cols, static_cast(value)); } - static concrete_type Random() + static concrete_type _Random() requires(Rows != -1 && Cols != -1) { - return parent::Random(Rows, Cols); + return parent::_Random(Rows, Cols); } - static concrete_type Random(int rows, int cols) + static concrete_type _Random(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -425,16 +428,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Random(rows, cols); + return parent::_Random(rows, cols); } - static concrete_type Identity() + static concrete_type _Identity() requires(Rows != -1 && Cols != -1) { - return parent::Identity(Rows, Cols); + return parent::_Identity(Rows, Cols); } - static concrete_type Identity(int rows, int cols) + static concrete_type _Identity(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -442,48 +445,49 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Identity(rows, cols); + return parent::_Identity(rows, cols); } - block& setOnes() + block& _setOnes() requires(!is_immutable) { - parent::assign(parent::Ones(parent::rows(), parent::cols())); + parent::assign(parent::_Ones(parent::_rows(), parent::_cols())); return *this; } - block& setZero() + block& _setZero() requires(!is_immutable) { - parent::assign(parent::Zero(parent::rows(), parent::cols())); + parent::assign(parent::_Zero(parent::_rows(), parent::_cols())); return *this; } - block& setConstant(value_type value) + block& _setConstant(value_type value) requires(!is_immutable) { - parent::assign(parent::Constant(parent::rows(), parent::cols(), value)); + parent::assign( + parent::_Constant(parent::_rows(), parent::_cols(), value)); return *this; } - block& setRandom() + block& _setRandom() requires(!is_immutable) { - parent::assign(parent::Random(parent::rows(), parent::cols())); + parent::assign(parent::_Random(parent::_rows(), parent::_cols())); return *this; } - block& setIdentity() + block& _setIdentity() requires(!is_immutable) { - parent::assign(parent::Identity(parent::rows(), parent::cols())); + parent::assign(parent::_Identity(parent::_rows(), parent::_cols())); return *this; } - template value_type lpNorm() const + template value_type _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); - return parent::lpNorm(P); + return parent::_lpNorm(P); } parent& base() { return static_cast(*this); } @@ -495,41 +499,41 @@ namespace rotgen auto operator+(block const& lhs, block const& rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(lhs.base().add(rhs)); + return concrete_type(lhs.base()._add(rhs)); } template auto operator-(block const& lhs, block const& rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(lhs.base().sub(rhs)); + return concrete_type(lhs.base()._sub(rhs)); } template auto operator*(block const& lhs, block const& rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(lhs.base().mul(rhs)); + return concrete_type(lhs.base()._mul(rhs)); } template auto operator*(block const& lhs, double rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(lhs.base().mul(rhs)); + return concrete_type(lhs.base()._mul(rhs)); } template auto operator*(double lhs, block const& rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(rhs.base().mul(lhs)); + return concrete_type(rhs.base()._mul(lhs)); } template auto operator/(block const& lhs, double rhs) { using concrete_type = typename block::concrete_type; - return concrete_type(lhs.base().div(rhs)); + return concrete_type(lhs.base()._div(rhs)); } } diff --git a/include/rotgen/container/block/dynamic/model.hpp b/include/rotgen/container/block/dynamic/model.hpp index 24785fd..f557847 100644 --- a/include/rotgen/container/block/dynamic/model.hpp +++ b/include/rotgen/container/block/dynamic/model.hpp @@ -39,44 +39,45 @@ public: void assign(SOURCENAME const&); #endif - Index rows() const; - Index cols() const; Index size() const; - Index innerStride() const; - Index outerStride() const; + Index _rows() const; + Index _cols() const; - Index startRow() const; - Index startCol() const; + Index _innerStride() const; + Index _outerStride() const; - SOURCENAME normalized() const; - SOURCENAME transpose() const; - SOURCENAME conjugate() const; - SOURCENAME adjoint() const; + Index _startRow() const; + Index _startCol() const; - SOURCENAME cwiseAbs() const; - SOURCENAME cwiseAbs2() const; - SOURCENAME cwiseInverse() const; - SOURCENAME cwiseSqrt() const; + SOURCENAME _normalized() const; + SOURCENAME _transpose() const; + SOURCENAME _conjugate() const; + SOURCENAME _adjoint() const; + + SOURCENAME _cwiseAbs() const; + SOURCENAME _cwiseAbs2() const; + SOURCENAME _cwiseInverse() const; + SOURCENAME _cwiseSqrt() const; #if !defined(USE_CONST) - void normalize(); - void transposeInPlace(); - void adjointInPlace(); + void _normalize(); + void _transposeInPlace(); + void _adjointInPlace(); #endif - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() const; - TYPE maxCoeff() const; - TYPE minCoeff() const; - TYPE maxCoeff(Index* row, Index* col) const; - TYPE minCoeff(Index* row, Index* col) const; + TYPE _sum() const; + TYPE _prod() const; + TYPE _mean() const; + TYPE _trace() const; + TYPE _maxCoeff() const; + TYPE _minCoeff() const; + TYPE _maxCoeff(Index* row, Index* col) const; + TYPE _minCoeff(Index* row, Index* col) const; - TYPE squaredNorm() const; - TYPE norm() const; - TYPE lpNorm(int p) const; + TYPE _squaredNorm() const; + TYPE _norm() const; + TYPE _lpNorm(int p) const; #if !defined(USE_CONST) TYPE& operator()(Index i, Index j); @@ -101,11 +102,11 @@ public: TYPE operator()(Index index) const; SOURCENAME operator-() const; - SOURCENAME add(CLASSNAME const& rhs) const; - SOURCENAME sub(CLASSNAME const& rhs) const; - SOURCENAME mul(CLASSNAME const& rhs) const; - SOURCENAME mul(TYPE s) const; - SOURCENAME div(TYPE s) const; + SOURCENAME _add(CLASSNAME const& rhs) const; + SOURCENAME _sub(CLASSNAME const& rhs) const; + SOURCENAME _mul(CLASSNAME const& rhs) const; + SOURCENAME _mul(TYPE s) const; + SOURCENAME _div(TYPE s) const; friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, CLASSNAME const&); @@ -121,23 +122,23 @@ public: #endif const TYPE* data() const; - static SOURCENAME Zero(Index r, Index c) { return SOURCENAME::Zero(r, c); } + static SOURCENAME _Zero(Index r, Index c) { return SOURCENAME::_Zero(r, c); } - static SOURCENAME Ones(Index r, Index c) { return SOURCENAME::Ones(r, c); } + static SOURCENAME _Ones(Index r, Index c) { return SOURCENAME::_Ones(r, c); } - static SOURCENAME Constant(Index r, Index c, TYPE v) + static SOURCENAME _Constant(Index r, Index c, TYPE v) { - return SOURCENAME::Constant(r, c, v); + return SOURCENAME::_Constant(r, c, v); } - static SOURCENAME Random(Index r, Index c) + static SOURCENAME _Random(Index r, Index c) { - return SOURCENAME::Random(r, c); + return SOURCENAME::_Random(r, c); } - static SOURCENAME Identity(Index r, Index c) + static SOURCENAME _Identity(Index r, Index c) { - return SOURCENAME::Identity(r, c); + return SOURCENAME::_Identity(r, c); } public: diff --git a/include/rotgen/container/block/fixed.hpp b/include/rotgen/container/block/fixed.hpp index 5cb1e3d..0c4708d 100644 --- a/include/rotgen/container/block/fixed.hpp +++ b/include/rotgen/container/block/fixed.hpp @@ -193,21 +193,21 @@ namespace rotgen parent const& base() const { return static_cast(*this); } - auto evaluate() const { return concrete_type(base().eval()); } + auto _evaluate() const { return concrete_type(base().eval()); } - decltype(auto) noalias() const + decltype(auto) _noalias() const { if constexpr (use_expression_templates) return base().noalias(); else return *this; } - decltype(auto) noalias() + decltype(auto) _noalias() { if constexpr (use_expression_templates) return base().noalias(); else return *this; } - auto normalized() const + auto _normalized() const requires(IsVectorAtCompileTime) { if constexpr (use_expression_templates) return base().normalized(); @@ -216,7 +216,7 @@ namespace rotgen base().normalized()); } - auto transpose() const + auto _transpose() const { if constexpr (use_expression_templates) return base().transpose(); else @@ -224,14 +224,14 @@ namespace rotgen base().transpose()); } - auto adjoint() const + auto _adjoint() const { if constexpr (use_expression_templates) return base().adjoint(); else return as_concrete_type(base().adjoint()); } - auto conjugate() const + auto _conjugate() const { if constexpr (use_expression_templates) return base().conjugate(); else @@ -239,59 +239,59 @@ namespace rotgen base().conjugate()); } - void normalize() + void _normalize() requires(!is_immutable && IsVectorAtCompileTime) { parent::normalize(); } - void transposeInPlace() + void _transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } - void adjointInPlace() + void _adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } - auto cwiseAbs() const + auto _cwiseAbs() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseAbs()}; else return base().cwiseAbs(); } - auto cwiseAbs2() const + auto _cwiseAbs2() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; else return base().cwiseAbs2(); } - auto cwiseInverse() const + auto _cwiseInverse() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseInverse()}; else return base().cwiseInverse(); } - auto cwiseSqrt() const + auto _cwiseSqrt() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; else return base().cwiseSqrt(); } - static concrete_type Constant(value_type value) + static concrete_type _Constant(value_type value) requires(Rows != -1 && Cols != -1) { return parent::Constant(Rows, Cols, static_cast(value)); } - static concrete_type Constant(int rows, int cols, value_type value) + static concrete_type _Constant(int rows, int cols, value_type value) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -302,13 +302,13 @@ namespace rotgen return parent::Constant(rows, cols, static_cast(value)); } - static concrete_type Identity() + static concrete_type _Identity() requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } - static concrete_type Identity(int rows, int cols) + static concrete_type _Identity(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -319,13 +319,13 @@ namespace rotgen return parent::Identity(rows, cols); } - static concrete_type Zero() + static concrete_type _Zero() requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } - static concrete_type Zero(int rows, int cols) + static concrete_type _Zero(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -336,13 +336,13 @@ namespace rotgen return parent::Zero(rows, cols); } - static concrete_type Ones() + static concrete_type _Ones() requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } - static concrete_type Ones(int rows, int cols) + static concrete_type _Ones(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -353,13 +353,13 @@ namespace rotgen return parent::Ones(rows, cols); } - static concrete_type Random() + static concrete_type _Random() requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } - static concrete_type Random(int rows, int cols) + static concrete_type _Random(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -370,77 +370,77 @@ namespace rotgen return parent::Random(rows, cols); } - block& setOnes() + block& _setOnes() requires(!is_immutable) { - *this = parent::Ones(rows(), cols()); + *this = parent::Ones(_rows(), _cols()); return *this; } - block& setOnes(int r, int c) + block& _setOnes(int r, int c) requires(!is_immutable) { *this = parent::Ones(r, c); return *this; } - block& setZero() + block& _setZero() requires(!is_immutable) { - *this = parent::Zero(rows(), cols()); + *this = parent::Zero(_rows(), _cols()); return *this; } - block& setZero(int r, int c) + block& _setZero(int r, int c) requires(!is_immutable) { *this = parent::Zero(r, c); return *this; } - block& setConstant(value_type value) + block& _setConstant(value_type value) requires(!is_immutable) { - *this = parent::Constant(rows(), cols(), value); + *this = parent::Constant(_rows(), _cols(), value); return *this; } - block& setConstant(int r, int c, value_type value) + block& _setConstant(int r, int c, value_type value) requires(!is_immutable) { *this = parent::Constant(r, c, value); return *this; } - block& setRandom() + block& _setRandom() requires(!is_immutable) { - *this = parent::Random(rows(), cols()); + *this = parent::Random(_rows(), _cols()); return *this; } - block& setRandom(int r, int c) + block& _setRandom(int r, int c) requires(!is_immutable) { *this = parent::Random(r, c); return *this; } - block& setIdentity() + block& _setIdentity() requires(!is_immutable) { - *this = parent::Identity(rows(), cols()); + *this = parent::Identity(_rows(), _cols()); return *this; } - block& setIdentity(int r, int c) + block& _setIdentity(int r, int c) requires(!is_immutable) { *this = parent::Identity(r, c); return *this; } - template value_type lpNorm() const + template value_type _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); return parent::template lpNorm

(); @@ -478,25 +478,35 @@ namespace rotgen return (*this)(i); } - using parent::cols; using parent::data; - using parent::innerStride; - using parent::mean; - using parent::norm; - using parent::outerStride; - using parent::prod; - using parent::rows; using parent::size; - using parent::squaredNorm; - using parent::sum; - using parent::trace; - auto minCoeff() const { return parent::minCoeff(); } + Index _cols() const { return parent::cols(); } - auto maxCoeff() const { return parent::maxCoeff(); } + Index _rows() const { return parent::rows(); } + + value_type _mean() const { return parent::mean(); } + + value_type _norm() const { return parent::norm(); } + + value_type _squaredNorm() const { return parent::squaredNorm(); } + + value_type _sum() const { return parent::sum(); } + + value_type _prod() const { return parent::prod(); } + + value_type _trace() const { return parent::trace(); } + + Index _innerStride() const noexcept { return parent::innerStride(); }; + + Index _outerStride() const noexcept { return parent::outerStride(); }; + + auto _minCoeff() const { return parent::minCoeff(); } + + auto _maxCoeff() const { return parent::maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { Index r, c; auto result = parent::minCoeff(&r, &c); @@ -506,7 +516,7 @@ namespace rotgen } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { Index r, c; auto result = parent::maxCoeff(&r, &c); @@ -515,9 +525,9 @@ namespace rotgen return result; } - Index startRow() const { return base().startRow(); } + Index _startRow() const { return base().startRow(); } - Index startCol() const { return base().startCol(); } + Index _startCol() const { return base().startCol(); } template block& operator+=(E const& rhs) diff --git a/include/rotgen/container/map/dynamic.hpp b/include/rotgen/container/map/dynamic.hpp index f87e261..30d0dab 100644 --- a/include/rotgen/container/map/dynamic.hpp +++ b/include/rotgen/container/map/dynamic.hpp @@ -97,8 +97,13 @@ namespace rotgen map(ptr_type ptr, Index r, Index c) : parent(ptr, r, c, [&]() { if constexpr (!std::same_as>) + { return strides(Stride{}, r, c); - else return strides(r, c); + } + else + { + return strides(r, c); + } }()) { } @@ -127,9 +132,9 @@ namespace rotgen template map(map const& other) : map(other.data(), - other.rows(), - other.cols(), - dynamic_stride{other.outerStride(), other.innerStride()}) + other._rows(), + other._cols(), + dynamic_stride{other._outerStride(), other._innerStride()}) { } @@ -166,11 +171,11 @@ namespace rotgen } else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime) { - auto r = other.rows(); - auto c = other.cols(); + auto r = other._rows(); + auto c = other._cols(); ROTGEN_ASSERT( - (r == 1 || c == 1), + r == 1 || c == 1, "Map assignment from dynamic sized source doesn't match static size"); for (rotgen::Index i = 0; i < parent::size(); ++i) @@ -178,11 +183,11 @@ namespace rotgen } else { - ROTGEN_ASSERT(parent::rows() == other.rows() && - parent::cols() == other.cols(), + ROTGEN_ASSERT(parent::_rows() == other._rows() && + parent::_cols() == other._cols(), "Map assignment size mismatch"); - for (rotgen::Index r = 0; r < parent::rows(); ++r) - for (rotgen::Index c = 0; c < parent::cols(); ++c) + for (rotgen::Index r = 0; r < parent::_rows(); ++r) + for (rotgen::Index c = 0; c < parent::_cols(); ++c) (*this)(r, c) = other(r, c); } @@ -224,83 +229,86 @@ namespace rotgen return (*this)(i); } - concrete_type evaluate() const { return concrete_type{*this}; } + concrete_type _evaluate() const { return concrete_type{*this}; } - decltype(auto) noalias() const { return *this; } + decltype(auto) _noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + decltype(auto) _noalias() { return *this; } - concrete_type normalized() const + concrete_type _normalized() const requires(IsVectorAtCompileTime) { - return concrete_type(base().normalized()); + return concrete_type(base()._normalized()); } - transposed_type transpose() const + transposed_type _transpose() const { - return transposed_type(base().transpose()); + return transposed_type(base()._transpose()); } - concrete_type conjugate() const + concrete_type _conjugate() const { - return concrete_type(base().conjugate()); + return concrete_type(base()._conjugate()); } - transposed_type adjoint() const + transposed_type _adjoint() const { - return transposed_type(base().adjoint()); + return transposed_type(base()._adjoint()); } - concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } - - concrete_type cwiseAbs2() const + concrete_type _cwiseAbs() const { - return concrete_type(base().cwiseAbs2()); + return concrete_type(base()._cwiseAbs()); } - concrete_type cwiseInverse() const + concrete_type _cwiseAbs2() const { - return concrete_type(base().cwiseInverse()); + return concrete_type(base()._cwiseAbs2()); } - concrete_type cwiseSqrt() const + concrete_type _cwiseInverse() const { - return concrete_type(base().cwiseSqrt()); + return concrete_type(base()._cwiseInverse()); } - concrete_type cwiseMin(map const& rhs) const + concrete_type _cwiseSqrt() const { - return concrete_type(base().cwiseMin(rhs.base())); + return concrete_type(base()._cwiseSqrt()); } - concrete_type cwiseMax(map const& rhs) const + concrete_type _cwiseMin(map const& rhs) const { - return concrete_type(base().cwiseMax(rhs.base())); + return concrete_type(base()._cwiseMin(rhs.base())); } - concrete_type cwiseQuotient(map const& rhs) const + concrete_type _cwiseMax(map const& rhs) const { - return concrete_type(base().cwiseQuotient(rhs.base())); + return concrete_type(base()._cwiseMax(rhs.base())); } - concrete_type cwiseProduct(map const& rhs) const + concrete_type _cwiseQuotient(map const& rhs) const { - return concrete_type(base().cwiseProduct(rhs.base())); + return concrete_type(base()._cwiseQuotient(rhs.base())); } - concrete_type cwiseMin(value_type s) const + concrete_type _cwiseProduct(map const& rhs) const { - return concrete_type(base().cwiseMin(s)); + return concrete_type(base()._cwiseProduct(rhs.base())); } - concrete_type cwiseMax(value_type s) const + concrete_type _cwiseMin(value_type s) const { - return concrete_type(base().cwiseMax(s)); + return concrete_type(base()._cwiseMin(s)); } - concrete_type inverse() const { return concrete_type(base().inverse()); } + concrete_type _cwiseMax(value_type s) const + { + return concrete_type(base()._cwiseMax(s)); + } - concrete_type cross(map const& other) const + concrete_type _inverse() const { return concrete_type(base()._inverse()); } + + concrete_type _cross(map const& other) const { concrete_type that; if constexpr (ColsAtCompileTime == 1) @@ -318,22 +326,22 @@ namespace rotgen return that; } - void normalize() + void _normalize() requires(!is_immutable && IsVectorAtCompileTime) { - parent::normalize(); + parent::_normalize(); } - void transposeInPlace() + void _transposeInPlace() requires(!is_immutable) { - parent::transposeInPlace(); + parent::_transposeInPlace(); } - void adjointInPlace() + void _adjointInPlace() requires(!is_immutable) { - parent::adjointInPlace(); + parent::_adjointInPlace(); } template @@ -363,8 +371,8 @@ namespace rotgen map& operator*=(map const& rhs) requires(!is_immutable) { - ROTGEN_ASSERT(parent::cols() == rhs.rows() && - parent::cols() == rhs.cols(), + ROTGEN_ASSERT(parent::_cols() == rhs._rows() && + parent::_cols() == rhs._cols(), "Incompatible dimensions for compound matrix-product"); base() *= rhs.base(); return *this; @@ -384,121 +392,121 @@ namespace rotgen return *this; } - auto minCoeff() const { return parent::minCoeff(); } + auto _minCoeff() const { return parent::_minCoeff(); } - auto maxCoeff() const { return parent::maxCoeff(); } + auto _maxCoeff() const { return parent::_maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::minCoeff(&r, &c); + auto result = parent::_minCoeff(&r, &c); *row = r; *col = c; return result; } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::maxCoeff(&r, &c); + auto result = parent::_maxCoeff(&r, &c); *row = r; *col = c; return result; } - static auto Zero() - requires(requires { Ref::Zero(); }) + static auto _Zero() + requires(requires { Ref::_Zero(); }) { - return Ref::Zero(); + return Ref::_Zero(); } - static auto Ones() - requires(requires { Ref::Ones(); }) + static auto _Ones() + requires(requires { Ref::_Ones(); }) { - return Ref::Ones(); + return Ref::_Ones(); } - static auto Zero(int rows, int cols) { return Ref::Zero(rows, cols); } + static auto _Zero(int rows, int cols) { return Ref::_Zero(rows, cols); } - static auto Ones(int rows, int cols) { return Ref::Ones(rows, cols); } + static auto _Ones(int rows, int cols) { return Ref::_Ones(rows, cols); } - static auto Constant(value_type value) - requires(requires { Ref::Constant(value); }) + static auto _Constant(value_type value) + requires(requires { Ref::_Constant(value); }) { - return Ref::Constant(value); + return Ref::_Constant(value); } - static auto Constant(int rows, int cols, value_type value) + static auto _Constant(int rows, int cols, value_type value) { - return Ref::Constant(rows, cols, value); + return Ref::_Constant(rows, cols, value); } - static auto Random() - requires(requires { Ref::Random(); }) + static auto _Random() + requires(requires { Ref::_Random(); }) { - return Ref::Random(); + return Ref::_Random(); } - static auto Random(int rows, int cols) { return Ref::Random(rows, cols); } + static auto _Random(int rows, int cols) { return Ref::_Random(rows, cols); } - static auto Identity() - requires(requires { Ref::Identity(); }) + static auto _Identity() + requires(requires { Ref::_Identity(); }) { - return Ref::Identity(); + return Ref::_Identity(); } - static auto Identity(int rows, int cols) + static auto _Identity(int rows, int cols) { - return Ref::Identity(rows, cols); + return Ref::_Identity(rows, cols); } - map& setZero() + map& _setZero() requires(!is_immutable) { - parent::setZero(); + parent::_setZero(); return *this; } - map& setOnes() + map& _setOnes() requires(!is_immutable) { - parent::setOnes(); + parent::_setOnes(); return *this; } - map& setIdentity() + map& _setIdentity() requires(!is_immutable) { - parent::setIdentity(); + parent::_setIdentity(); return *this; } - map& setRandom() + map& _setRandom() requires(!is_immutable) { - parent::setRandom(); + parent::_setRandom(); return *this; } - map& setConstant(value_type s) + map& _setConstant(value_type scalar) requires(!is_immutable) { - parent::setConstant(s); + parent::_setConstant(scalar); return *this; } template - value_type dot(map const& rhs) const + value_type _dot(map const& rhs) const { - return base().dot(rhs.base()); + return base()._dot(rhs.base()); } - template value_type lpNorm() const + template value_type _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); - return parent::lpNorm(P); + return parent::_lpNorm(P); } parent& base() { return static_cast(*this); } @@ -529,9 +537,9 @@ namespace rotgen } else { - ROTGEN_ASSERT(parent::rows() == rhs.rows(), + ROTGEN_ASSERT(parent::_rows() == rhs._rows(), "Mismatched rows count in compound assignment operator"); - ROTGEN_ASSERT(parent::cols() == rhs.cols(), + ROTGEN_ASSERT(parent::_cols() == rhs._cols(), "Mismatched cols count in compound assignment operator"); } } @@ -544,7 +552,7 @@ namespace rotgen using map1_type = map; using map2_type = map; using concrete_type = detail::composite_type; - return concrete_type(map1_type(lhs).base().add(map2_type(rhs))); + return concrete_type(map1_type(lhs).base()._add(map2_type(rhs))); } template @@ -554,7 +562,7 @@ namespace rotgen using map1_type = map; using map2_type = map; using concrete_type = detail::composite_type; - return concrete_type(map1_type(lhs).base().sub(map2_type(rhs))); + return concrete_type(map1_type(lhs).base()._sub(map2_type(rhs))); } template @@ -565,12 +573,22 @@ namespace rotgen using concrete_type = matrix; - if constexpr (concrete_type::SizeAtCompileTime == 0) return concrete_type{}; + if constexpr (concrete_type::SizeAtCompileTime == 0) + { + return concrete_type{}; + } else { - auto p = concrete_type(map1_type(lhs).base().mul(map2_type(rhs).base())); - if constexpr (concrete_type::SizeAtCompileTime == 1) return product{p}; - else return p; + auto product_result = + concrete_type(map1_type(lhs).base()._mul(map2_type(rhs).base())); + if constexpr (concrete_type::SizeAtCompileTime == 1) + { + return product{product_result}; + } + else + { + return product_result; + } } } @@ -579,7 +597,7 @@ namespace rotgen map const& lhs, std::convertible_to auto s) { using concrete_type = typename map::concrete_type; - return concrete_type(lhs.base().mul(s)); + return concrete_type(lhs.base()._mul(s)); } template @@ -587,7 +605,7 @@ namespace rotgen std::convertible_to auto s, map const& rhs) { using concrete_type = typename map::concrete_type; - return concrete_type(rhs.base().mul(s)); + return concrete_type(rhs.base()._mul(s)); } template @@ -595,7 +613,7 @@ namespace rotgen map const& lhs, std::convertible_to auto s) { using concrete_type = typename map::concrete_type; - return concrete_type(lhs.base().div(s)); + return concrete_type(lhs.base()._div(s)); } template diff --git a/include/rotgen/container/map/dynamic/model.hpp b/include/rotgen/container/map/dynamic/model.hpp index a8bb0f3..4c41423 100644 --- a/include/rotgen/container/map/dynamic/model.hpp +++ b/include/rotgen/container/map/dynamic/model.hpp @@ -28,52 +28,53 @@ public: ~CLASSNAME(); - Index rows() const; - Index cols() const; Index size() const; - Index innerStride() const; - Index outerStride() const; + Index _rows() const; + Index _cols() const; - SOURCENAME normalized() const; - SOURCENAME transpose() const; - SOURCENAME conjugate() const; - SOURCENAME adjoint() const; + Index _innerStride() const; + Index _outerStride() const; - SOURCENAME cwiseAbs() const; - SOURCENAME cwiseAbs2() const; - SOURCENAME cwiseInverse() const; - SOURCENAME cwiseSqrt() const; + SOURCENAME _normalized() const; + SOURCENAME _transpose() const; + SOURCENAME _conjugate() const; + SOURCENAME _adjoint() const; - SOURCENAME cwiseMax(CLASSNAME const&) const; - SOURCENAME cwiseMin(CLASSNAME const&) const; - SOURCENAME cwiseProduct(CLASSNAME const&) const; - SOURCENAME cwiseQuotient(CLASSNAME const&) const; - SOURCENAME cwiseMax(TYPE) const; - SOURCENAME cwiseMin(TYPE) const; + SOURCENAME _cwiseAbs() const; + SOURCENAME _cwiseAbs2() const; + SOURCENAME _cwiseInverse() const; + SOURCENAME _cwiseSqrt() const; + + SOURCENAME _cwiseMax(CLASSNAME const&) const; + SOURCENAME _cwiseMin(CLASSNAME const&) const; + SOURCENAME _cwiseProduct(CLASSNAME const&) const; + SOURCENAME _cwiseQuotient(CLASSNAME const&) const; + SOURCENAME _cwiseMax(TYPE) const; + SOURCENAME _cwiseMin(TYPE) const; #if !defined(USE_CONST) - void normalize(); - void transposeInPlace(); - void adjointInPlace(); + void _normalize(); + void _transposeInPlace(); + void _adjointInPlace(); #endif - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() const; - TYPE maxCoeff() const; - TYPE minCoeff() const; - TYPE maxCoeff(Index*, Index*) const; - TYPE minCoeff(Index*, Index*) const; - TYPE dot(CLASSNONCONSTNAME const&) const; - TYPE dot(CLASSCONSTNAME const&) const; - TYPE dot(TRANSCLASSCONSTNAME const&) const; - TYPE dot(TRANSCLASSNONCONSTNAME const&) const; + TYPE _sum() const; + TYPE _prod() const; + TYPE _mean() const; + TYPE _trace() const; + TYPE _maxCoeff() const; + TYPE _minCoeff() const; + TYPE _maxCoeff(Index*, Index*) const; + TYPE _minCoeff(Index*, Index*) const; + TYPE _dot(CLASSNONCONSTNAME const&) const; + TYPE _dot(CLASSCONSTNAME const&) const; + TYPE _dot(TRANSCLASSCONSTNAME const&) const; + TYPE _dot(TRANSCLASSNONCONSTNAME const&) const; - TYPE squaredNorm() const; - TYPE norm() const; - TYPE lpNorm(int p) const; + TYPE _squaredNorm() const; + TYPE _norm() const; + TYPE _lpNorm(int p) const; SOURCENAME qr_solve(CLASSNAME const& rhs) const; @@ -103,16 +104,16 @@ public: #endif SOURCENAME operator-() const; - SOURCENAME add(CLASSNAME const& rhs) const; - SOURCENAME add(TRANSCLASSNAME const& rhs) const; - SOURCENAME sub(CLASSNAME const& rhs) const; - SOURCENAME sub(TRANSCLASSNAME const& rhs) const; - SOURCENAME mul(CLASSNAME const& rhs) const; - SOURCENAME mul(TRANSCLASSNAME const& rhs) const; - SOURCENAME mul(TYPE s) const; - SOURCENAME div(TYPE s) const; + SOURCENAME _add(CLASSNAME const& rhs) const; + SOURCENAME _add(TRANSCLASSNAME const& rhs) const; + SOURCENAME _sub(CLASSNAME const& rhs) const; + SOURCENAME _sub(TRANSCLASSNAME const& rhs) const; + SOURCENAME _mul(CLASSNAME const& rhs) const; + SOURCENAME _mul(TRANSCLASSNAME const& rhs) const; + SOURCENAME _mul(TYPE s) const; + SOURCENAME _div(TYPE s) const; - SOURCENAME inverse() const; + SOURCENAME _inverse() const; friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, CLASSNAME const&); @@ -122,11 +123,11 @@ public: #if !defined(USE_CONST) TYPE* data(); - void setZero(); - void setOnes(); - void setRandom(); - void setIdentity(); - void setConstant(TYPE); + void _setZero(); + void _setOnes(); + void _setRandom(); + void _setIdentity(); + void _setConstant(TYPE); #endif friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, diff --git a/include/rotgen/container/map/fixed.hpp b/include/rotgen/container/map/fixed.hpp index 9997a59..ad65b8d 100644 --- a/include/rotgen/container/map/fixed.hpp +++ b/include/rotgen/container/map/fixed.hpp @@ -134,15 +134,15 @@ namespace rotgen parent const& base() const { return static_cast(*this); } - auto evaluate() const { return concrete_type(base().eval()); } + auto _evaluate() const { return concrete_type(base().eval()); } - decltype(auto) noalias() const + decltype(auto) _noalias() const { if constexpr (use_expression_templates) return base().noalias(); else return *this; } - decltype(auto) noalias() + decltype(auto) _noalias() { if constexpr (use_expression_templates) return base().noalias(); else return *this; @@ -221,91 +221,91 @@ namespace rotgen return *this; } - auto cwiseMin(map const& rhs) const + auto _cwiseMin(map const& rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseMin(rhs.base())}; else return base().cwiseMin(rhs.base()); } - auto cwiseMin(value_type rhs) const + auto _cwiseMin(value_type rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseMin(rhs)}; else return base().cwiseMin(rhs); } - auto cwiseMax(map const& rhs) const + auto _cwiseMax(map const& rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseMax(rhs.base())}; else return base().cwiseMax(rhs.base()); } - auto cwiseMax(value_type rhs) const + auto _cwiseMax(value_type rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseMax(rhs)}; else return base().cwiseMax(rhs); } - auto cwiseProduct(map const& rhs) const + auto _cwiseProduct(map const& rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseProduct(rhs.base())}; else return base().cwiseProduct(rhs.base()); } - auto cwiseQuotient(map const& rhs) const + auto _cwiseQuotient(map const& rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseQuotient(rhs.base())}; else return base().cwiseQuotient(rhs.base()); } - auto cwiseAbs() const + auto _cwiseAbs() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseAbs()}; else return base().cwiseAbs(); } - auto cwiseAbs2() const + auto _cwiseAbs2() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; else return base().cwiseAbs2(); } - auto cwiseInverse() const + auto _cwiseInverse() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseInverse()}; else return base().cwiseInverse(); } - auto cwiseSqrt() const + auto _cwiseSqrt() const { if constexpr (!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; else return base().cwiseSqrt(); } - auto cross(map const& rhs) const + auto _cross(map const& rhs) const { if constexpr (!use_expression_templates) return concrete_type{parent::cross(rhs.base())}; else return base().cross(rhs.base()); } - auto inverse() const + auto _inverse() const { if constexpr (use_expression_templates) return base().inverse(); else return as_concrete_type(base().inverse()); } - auto normalized() const + auto _normalized() const requires(IsVectorAtCompileTime) { if constexpr (use_expression_templates) return base().normalized(); @@ -314,7 +314,7 @@ namespace rotgen base().normalized()); } - auto transpose() const + auto _transpose() const { if constexpr (use_expression_templates) return base().transpose(); else @@ -322,14 +322,14 @@ namespace rotgen base().transpose()); } - auto adjoint() const + auto _adjoint() const { if constexpr (use_expression_templates) return base().adjoint(); else return as_concrete_type(base().adjoint()); } - auto conjugate() const + auto _conjugate() const { if constexpr (use_expression_templates) return base().conjugate(); else @@ -337,116 +337,126 @@ namespace rotgen base().conjugate()); } - void normalize() + void _normalize() requires(IsVectorAtCompileTime) { base().normalize(); } - void transposeInPlace() { base().transposeInPlace(); } + void _transposeInPlace() { base().transposeInPlace(); } - void adjointInPlace() { base().adjointInPlace(); } + void _adjointInPlace() { base().adjointInPlace(); } auto qr_solve(auto const& rhs) const { return concrete_type(base().colPivHouseholderQr().solve(rhs.base())); }; - static auto Zero() + static auto _Zero() requires(requires { Ref::Zero(); }) { return Ref::Zero(); } - static auto Zero(int rows, int cols) { return Ref::Zero(rows, cols); } + static auto _Zero(int rows, int cols) { return Ref::Zero(rows, cols); } - static auto Ones() + static auto _Ones() requires(requires { Ref::Ones(); }) { return Ref::Ones(); } - static auto Ones(int rows, int cols) { return Ref::Ones(rows, cols); } + static auto _Ones(int rows, int cols) { return Ref::Ones(rows, cols); } - static auto Constant(value_type value) + static auto _Constant(value_type value) requires(requires { Ref::Constant(value); }) { return Ref::Constant(value); } - static auto Constant(int rows, int cols, value_type value) + static auto _Constant(int rows, int cols, value_type value) { return Ref::Constant(rows, cols, value); } - static auto Random() + static auto _Random() requires(requires { Ref::Random(); }) { return Ref::Random(); } - static auto Random(int rows, int cols) { return Ref::Random(rows, cols); } + static auto _Random(int rows, int cols) { return Ref::Random(rows, cols); } - static auto Identity() + static auto _Identity() requires(requires { Ref::Identity(); }) { return Ref::Identity(); } - static auto Identity(int rows, int cols) + static auto _Identity(int rows, int cols) { return Ref::Identity(rows, cols); } - map& setOnes() + map& _setOnes() { base() = parent::Ones(base().rows(), base().cols()); return *this; } - map& setZero() + map& _setZero() { base() = parent::Zero(base().rows(), base().cols()); return *this; } - map& setConstant(value_type value) + map& _setConstant(value_type value) { base() = parent::Constant(base().rows(), base().cols(), value); return *this; } - map& setRandom() + map& _setRandom() { base() = parent::Random(base().rows(), base().cols()); return *this; } - map& setIdentity() + map& _setIdentity() { base() = parent::Identity(base().rows(), base().cols()); return *this; } - using parent::cols; using parent::data; - using parent::innerStride; - using parent::mean; - using parent::norm; - using parent::outerStride; - using parent::prod; - using parent::rows; using parent::size; - using parent::squaredNorm; - using parent::sum; - using parent::trace; - auto minCoeff() const { return parent::minCoeff(); } + Index _cols() const { return parent::cols(); } - auto maxCoeff() const { return parent::maxCoeff(); } + Index _rows() const { return parent::rows(); } + + value_type _mean() const { return parent::mean(); } + + value_type _norm() const { return parent::norm(); } + + value_type _squaredNorm() const { return parent::squaredNorm(); } + + value_type _sum() const { return parent::sum(); } + + value_type _prod() const { return parent::prod(); } + + value_type _trace() const { return parent::trace(); } + + Index _innerStride() const noexcept { return parent::innerStride(); }; + + Index _outerStride() const noexcept { return parent::outerStride(); }; + + auto _minCoeff() const { return parent::minCoeff(); } + + auto _maxCoeff() const { return parent::maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { Index r, c; auto result = parent::minCoeff(&r, &c); @@ -456,7 +466,7 @@ namespace rotgen } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { Index r, c; auto result = parent::maxCoeff(&r, &c); @@ -466,12 +476,12 @@ namespace rotgen } template - value_type dot(map const& rhs) const + value_type _dot(map const& rhs) const { return base().dot(rhs.base()); } - template value_type lpNorm() const + template value_type _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); return parent::template lpNorm

(); diff --git a/include/rotgen/container/matrix/dynamic.hpp b/include/rotgen/container/matrix/dynamic.hpp index 14e66d3..dd323f3 100644 --- a/include/rotgen/container/matrix/dynamic.hpp +++ b/include/rotgen/container/matrix/dynamic.hpp @@ -129,10 +129,10 @@ namespace rotgen } else { - resize(other.rows(), other.cols()); + resize(other._rows(), other._cols()); - for (rotgen::Index r = 0; r < parent::rows(); ++r) - for (rotgen::Index c = 0; c < parent::cols(); ++c) + for (rotgen::Index r = 0; r < parent::_rows(); ++r) + for (rotgen::Index c = 0; c < parent::_cols(); ++c) (*this)(r, c) = other(r, c); } } @@ -163,21 +163,21 @@ namespace rotgen base().swap(other.base()); } - auto evaluate() const { return *this; } + auto _evaluate() const { return *this; } - decltype(auto) noalias() const { return *this; } + decltype(auto) _noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + decltype(auto) _noalias() { return *this; } - Index innerStride() const noexcept { return 1; } + Index _innerStride() const noexcept { return 1; } - Index outerStride() const noexcept + Index _outerStride() const noexcept { if constexpr (IsVectorAtCompileTime) return this->size(); else { - if constexpr (IsRowMajor) return this->cols(); - else return this->rows(); + if constexpr (IsRowMajor) return this->_cols(); + else return this->_rows(); } } @@ -199,7 +199,7 @@ namespace rotgen else parent::resize(s, 1); } - void conservativeResize(int r, int c) + void _conservativeResize(int r, int c) { if constexpr (Cols != -1) ROTGEN_ASSERT(c == Cols, @@ -207,51 +207,51 @@ namespace rotgen if constexpr (Rows != -1) ROTGEN_ASSERT(r == Rows, "Mismatched between dynamic and static row size"); - parent::conservativeResize(r, c); + parent::_conservativeResize(r, c); } - void conservativeResize(int s) + void _conservativeResize(int s) requires(IsVectorAtCompileTime) { - if constexpr (Rows == 1) parent::conservativeResize(1, s); - else parent::conservativeResize(s, 1); + if constexpr (Rows == 1) parent::_conservativeResize(1, s); + else parent::_conservativeResize(s, 1); } - matrix normalized() const + matrix _normalized() const requires(IsVectorAtCompileTime) { - return matrix(base().normalized()); + return matrix(base()._normalized()); } - transposed_type transpose() const + transposed_type _transpose() const { - return transposed_type(base().transpose()); + return transposed_type(base()._transpose()); } - matrix conjugate() const { return matrix(base().conjugate()); } + matrix _conjugate() const { return matrix(base()._conjugate()); } - transposed_type adjoint() const + transposed_type _adjoint() const { - return transposed_type(base().adjoint()); + return transposed_type(base()._adjoint()); } - void normalize() + void _normalize() requires(IsVectorAtCompileTime) { - parent::normalize(); + parent::_normalize(); } - void transposeInPlace() { parent::transposeInPlace(); } + void _transposeInPlace() { parent::_transposeInPlace(); } - void adjointInPlace() { parent::adjointInPlace(); } + void _adjointInPlace() { parent::_adjointInPlace(); } - matrix cwiseAbs() const { return matrix(base().cwiseAbs()); } + matrix _cwiseAbs() const { return matrix(base()._cwiseAbs()); } - matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); } + matrix _cwiseAbs2() const { return matrix(base()._cwiseAbs2()); } - matrix cwiseInverse() const { return matrix(base().cwiseInverse()); } + matrix _cwiseInverse() const { return matrix(base()._cwiseInverse()); } - matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); } + matrix _cwiseSqrt() const { return matrix(base()._cwiseSqrt()); } friend bool operator==(matrix const& lhs, matrix const& rhs) { @@ -290,37 +290,37 @@ namespace rotgen return *this; } - auto minCoeff() const { return parent::minCoeff(); } + auto _minCoeff() const { return parent::_minCoeff(); } - auto maxCoeff() const { return parent::maxCoeff(); } + auto _maxCoeff() const { return parent::_maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::minCoeff(&r, &c); + auto result = parent::_minCoeff(&r, &c); *row = r; *col = c; return result; } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { Index r, c; - auto result = parent::maxCoeff(&r, &c); + auto result = parent::_maxCoeff(&r, &c); *row = r; *col = c; return result; } - static matrix Ones() + static matrix _Ones() requires(Rows != -1 && Cols != -1) { - return parent::Ones(Rows, Cols); + return parent::_Ones(Rows, Cols); } - static matrix Ones(int rows, int cols) + static matrix _Ones(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -328,16 +328,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Ones(rows, cols); + return parent::_Ones(rows, cols); } - static matrix Zero() + static matrix _Zero() requires(Rows != -1 && Cols != -1) { - return parent::Zero(Rows, Cols); + return parent::_Zero(Rows, Cols); } - static matrix Zero(int rows, int cols) + static matrix _Zero(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -345,16 +345,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Zero(rows, cols); + return parent::_Zero(rows, cols); } - static matrix Constant(Scalar value) + static matrix _Constant(Scalar value) requires(Rows != -1 && Cols != -1) { - return parent::Constant(Rows, Cols, static_cast(value)); + return parent::_Constant(Rows, Cols, static_cast(value)); } - static matrix Constant(int rows, int cols, Scalar value) + static matrix _Constant(int rows, int cols, Scalar value) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -362,16 +362,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Constant(rows, cols, static_cast(value)); + return parent::_Constant(rows, cols, static_cast(value)); } - static matrix Random() + static matrix _Random() requires(Rows != -1 && Cols != -1) { - return parent::Random(Rows, Cols); + return parent::_Random(Rows, Cols); } - static matrix Random(int rows, int cols) + static matrix _Random(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -379,16 +379,16 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Random(rows, cols); + return parent::_Random(rows, cols); } - static matrix Identity() + static matrix _Identity() requires(Rows != -1 && Cols != -1) { - return parent::Identity(Rows, Cols); + return parent::_Identity(Rows, Cols); } - static matrix Identity(int rows, int cols) + static matrix _Identity(int rows, int cols) { if constexpr (Rows != -1) ROTGEN_ASSERT(rows == Rows, @@ -396,74 +396,74 @@ namespace rotgen if constexpr (Cols != -1) ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Identity(rows, cols); + return parent::_Identity(rows, cols); } - matrix& setOnes() + matrix& _setOnes() { - parent::setOnes(parent::rows(), parent::cols()); + parent::_setOnes(parent::_rows(), parent::_cols()); return *this; } - matrix& setOnes(int rows, int cols) + matrix& _setOnes(int rows, int cols) { - parent::setOnes(rows, cols); + parent::_setOnes(rows, cols); return *this; } - matrix& setZero() + matrix& _setZero() { - parent::setZero(parent::rows(), parent::cols()); + parent::_setZero(parent::_rows(), parent::_cols()); return *this; } - matrix& setZero(int rows, int cols) + matrix& _setZero(int rows, int cols) { - parent::setZero(rows, cols); + parent::_setZero(rows, cols); return *this; } - matrix& setConstant(Scalar v) + matrix& _setConstant(Scalar v) { - parent::setConstant(parent::rows(), parent::cols(), - static_cast(v)); + parent::_setConstant(parent::_rows(), parent::_cols(), + static_cast(v)); return *this; } - matrix& setConstant(int rows, int cols, Scalar v) + matrix& _setConstant(int rows, int cols, Scalar v) { - parent::setConstant(rows, cols, static_cast(v)); + parent::_setConstant(rows, cols, static_cast(v)); return *this; } - matrix& setRandom() + matrix& _setRandom() { - parent::setRandom(parent::rows(), parent::cols()); + parent::_setRandom(parent::_rows(), parent::_cols()); return *this; } - matrix& setRandom(int rows, int cols) + matrix& _setRandom(int rows, int cols) { - parent::setRandom(rows, cols); + parent::_setRandom(rows, cols); return *this; } - matrix& setIdentity() + matrix& _setIdentity() { - parent::setIdentity(parent::rows(), parent::cols()); + parent::_setIdentity(parent::_rows(), parent::_cols()); return *this; } - matrix& setIdentity(int rows, int cols) + matrix& _setIdentity(int rows, int cols) { - parent::setIdentity(rows, cols); + parent::_setIdentity(rows, cols); return *this; } - template Scalar lpNorm() const + template Scalar _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); - return parent::lp_norm(P); + return parent::_lp_norm(P); } parent& base() { return static_cast(*this); } diff --git a/include/rotgen/container/matrix/dynamic/model.hpp b/include/rotgen/container/matrix/dynamic/model.hpp index df5c427..3ee4d66 100644 --- a/include/rotgen/container/matrix/dynamic/model.hpp +++ b/include/rotgen/container/matrix/dynamic/model.hpp @@ -28,39 +28,40 @@ public: ~CLASSNAME(); - Index rows() const; - Index cols() const; Index size() const; + Index _rows() const; + Index _cols() const; + void resize(Index new_rows, Index new_cols); - void conservativeResize(Index new_rows, Index new_cols); + void _conservativeResize(Index new_rows, Index new_cols); - CLASSNAME normalized() const; - CLASSNAME transpose() const; - CLASSNAME conjugate() const; - CLASSNAME adjoint() const; + CLASSNAME _normalized() const; + CLASSNAME _transpose() const; + CLASSNAME _conjugate() const; + CLASSNAME _adjoint() const; - CLASSNAME cwiseAbs() const; - CLASSNAME cwiseAbs2() const; - CLASSNAME cwiseInverse() const; - CLASSNAME cwiseSqrt() const; + CLASSNAME _cwiseAbs() const; + CLASSNAME _cwiseAbs2() const; + CLASSNAME _cwiseInverse() const; + CLASSNAME _cwiseSqrt() const; - void normalize(); - void transposeInPlace(); - void adjointInPlace(); + void _normalize(); + void _transposeInPlace(); + void _adjointInPlace(); - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() const; - TYPE maxCoeff() const; - TYPE minCoeff() const; - TYPE maxCoeff(Index* row, Index* col) const; - TYPE minCoeff(Index* row, Index* col) const; + TYPE _sum() const; + TYPE _prod() const; + TYPE _mean() const; + TYPE _trace() const; + TYPE _maxCoeff() const; + TYPE _minCoeff() const; + TYPE _maxCoeff(Index* row, Index* col) const; + TYPE _minCoeff(Index* row, Index* col) const; - TYPE squaredNorm() const; - TYPE norm() const; - TYPE lp_norm(int p) const; + TYPE _squaredNorm() const; + TYPE _norm() const; + TYPE _lp_norm(int p) const; TYPE& operator()(Index i, Index j); TYPE const& operator()(Index i, Index j) const; @@ -87,17 +88,17 @@ public: const TYPE* data() const; TYPE* data(); - static CLASSNAME Zero(Index rows, Index cols); - static CLASSNAME Ones(Index rows, Index cols); - static CLASSNAME Constant(Index rows, Index cols, TYPE value); - static CLASSNAME Random(Index rows, Index cols); - static CLASSNAME Identity(Index rows, Index cols); + static CLASSNAME _Zero(Index rows, Index cols); + static CLASSNAME _Ones(Index rows, Index cols); + static CLASSNAME _Constant(Index rows, Index cols, TYPE value); + static CLASSNAME _Random(Index rows, Index cols); + static CLASSNAME _Identity(Index rows, Index cols); - void setOnes(Index rows, Index cols); - void setZero(Index rows, Index cols); - void setConstant(Index rows, Index cols, TYPE value); - void setRandom(Index rows, Index cols); - void setIdentity(Index rows, Index cols); + void _setOnes(Index rows, Index cols); + void _setZero(Index rows, Index cols); + void _setConstant(Index rows, Index cols, TYPE value); + void _setRandom(Index rows, Index cols); + void _setIdentity(Index rows, Index cols); void swap(CLASSNAME& other) { storage_.swap(other.storage_); } diff --git a/include/rotgen/container/matrix/fixed.hpp b/include/rotgen/container/matrix/fixed.hpp index 7b8981a..4f96209 100644 --- a/include/rotgen/container/matrix/fixed.hpp +++ b/include/rotgen/container/matrix/fixed.hpp @@ -100,12 +100,16 @@ namespace rotgen matrix(Index r, Index c) : parent(r, c) { if constexpr (RowsAtCompileTime != -1) + { ROTGEN_ASSERT(r == RowsAtCompileTime, "Mismatched between dynamic and static row size"); + } if constexpr (ColsAtCompileTime != -1) + { ROTGEN_ASSERT(c == ColsAtCompileTime, "Mismatched between dynamic and static column size"); + } } matrix(matrix const& other) = default; @@ -127,8 +131,11 @@ namespace rotgen explicit matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent([&]() { - if constexpr (has_static_storage) return parent(v); - else return parent{1, 1}; + if constexpr (has_static_storage) { return parent(v); } + else + { + return parent{1, 1}; + } }()) { if constexpr (!has_static_storage) (*this)(0) = v; @@ -137,12 +144,18 @@ namespace rotgen matrix(std::initializer_list init) requires(IsVectorAtCompileTime) : parent([&]() { - if constexpr (has_static_storage) return parent{}; - else return parent{Rows, Cols}; + if constexpr (has_static_storage) { return parent{}; } + else + { + return parent{Rows, Cols}; + } }()) { auto first = init.begin(); - for (rotgen::Index i = 0; i < parent::size(); i++) (*this)(i) = first[i]; + for (rotgen::Index i = 0; i < parent::size(); i++) + { + (*this)(i) = first[i]; + } } matrix(Scalar v0, Scalar v1, auto... vs) @@ -184,31 +197,34 @@ namespace rotgen return *this; } - using parent::innerStride; - using parent::outerStride; - parent& base() { return static_cast(*this); } parent const& base() const { return static_cast(*this); } - auto evaluate() const { return *this; } + auto _evaluate() const { return *this; } - decltype(auto) noalias() const + decltype(auto) _noalias() const { - if constexpr (use_expression_templates) return base().noalias(); - else return *this; + if constexpr (use_expression_templates) { return base().noalias(); } + else + { + return *this; + } } - decltype(auto) noalias() + decltype(auto) _noalias() { - if constexpr (use_expression_templates) return base().noalias(); - else return *this; + if constexpr (use_expression_templates) { return base().noalias(); } + else + { + return *this; + } } - auto normalized() const + auto _normalized() const requires(IsVectorAtCompileTime) { - if constexpr (use_expression_templates) return base().normalized(); + if constexpr (use_expression_templates) { return base().normalized(); } else { auto res = base().normalized(); @@ -216,9 +232,9 @@ namespace rotgen } } - auto transpose() const + auto _transpose() const { - if constexpr (use_expression_templates) return base().transpose(); + if constexpr (use_expression_templates) { return base().transpose(); } else { auto res = base().transpose(); @@ -226,178 +242,232 @@ namespace rotgen } } - auto conjugate() const + auto _conjugate() const { auto res = base().conjugate(); return as_concrete_type(res); } - auto adjoint() const + auto _adjoint() const { auto res = base().adjoint(); return as_concrete_type(res); } - void normalize() + void _normalize() requires(IsVectorAtCompileTime) { parent::normalize(); } - void transposeInPlace() { parent::transposeInPlace(); } + void _transposeInPlace() { parent::transposeInPlace(); } - void adjointInPlace() { parent::adjointInPlace(); } + void _adjointInPlace() { parent::adjointInPlace(); } - auto cwiseAbs() const + auto _cwiseAbs() const { if constexpr (!use_expression_templates) + { return matrix{parent::cwiseAbs()}; - else return base().cwiseAbs(); + } + else + { + return base().cwiseAbs(); + } } - auto cwiseAbs2() const + auto _cwiseAbs2() const { if constexpr (!use_expression_templates) + { return matrix{parent::cwiseAbs2()}; - else return base().cwiseAbs2(); + } + else + { + return base().cwiseAbs2(); + } } - auto cwiseInverse() const + auto _cwiseInverse() const { if constexpr (!use_expression_templates) + { return matrix{parent::cwiseInverse()}; - else return base().cwiseInverse(); + } + else + { + return base().cwiseInverse(); + } } - auto cwiseSqrt() const + auto _cwiseSqrt() const { if constexpr (!use_expression_templates) + { return matrix{parent::cwiseSqrt()}; - else return base().cwiseSqrt(); + } + else + { + return base().cwiseSqrt(); + } } - void resize(int s) + void resize(int new_size) requires(IsVectorAtCompileTime) { - if constexpr (Rows == 1) parent::resize(1, s); - else parent::resize(s, 1); + if constexpr (Rows == 1) { parent::resize(1, new_size); } + else + { + parent::resize(new_size, 1); + } } - void resize(int r, int c) + void resize(int new_row_count, int new_col_count) { if constexpr (Cols != -1) - ROTGEN_ASSERT(c == Cols, + { + ROTGEN_ASSERT(new_col_count == Cols, "Mismatched between dynamic and static col size"); + } if constexpr (Rows != -1) - ROTGEN_ASSERT(r == Rows, + { + ROTGEN_ASSERT(new_row_count == Rows, "Mismatched between dynamic and static row size"); - parent::resize(r, c); + } + parent::resize(new_row_count, new_col_count); } - void conservativeResize(int s) + void _conservativeResize(int new_size) requires(IsVectorAtCompileTime) { - if constexpr (Rows == 1) parent::conservativeResize(1, s); - else parent::conservativeResize(s, 1); + if constexpr (Rows == 1) { parent::conservativeResize(1, new_size); } + else + { + parent::conservativeResize(new_size, 1); + } } - void conservativeResize(int r, int c) + void _conservativeResize(int new_row_count, int new_col_count) { if constexpr (Cols != -1) - ROTGEN_ASSERT(c == Cols, + { + ROTGEN_ASSERT(new_col_count == Cols, "Mismatched between dynamic and static col size"); + } if constexpr (Rows != -1) - ROTGEN_ASSERT(r == Rows, + { + ROTGEN_ASSERT(new_row_count == Rows, "Mismatched between dynamic and static row size"); - parent::conservativeResize(r, c); + } + parent::conservativeResize(new_row_count, new_col_count); } - static matrix Constant(Scalar value) + static matrix _Constant(Scalar value) requires(Rows != -1 && Cols != -1) { - return parent::Constant(Rows, Cols, static_cast(value)); + return parent::Constant(Rows, Cols, value); } - static matrix Constant(int rows, int cols, Scalar value) + static matrix _Constant(int rows, int cols, Scalar value) { if constexpr (Rows != -1) + { ROTGEN_ASSERT(rows == Rows, "Mismatched between dynamic and static row size"); + } if constexpr (Cols != -1) + { ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); - return parent::Constant(rows, cols, static_cast(value)); + } + return parent::Constant(rows, cols, value); } - static matrix Identity() + static matrix _Identity() requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } - static matrix Identity(int rows, int cols) + static matrix _Identity(int rows, int cols) { if constexpr (Rows != -1) + { ROTGEN_ASSERT(rows == Rows, "Mismatched between dynamic and static row size"); + } if constexpr (Cols != -1) + { ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); + } return parent::Identity(rows, cols); } - static matrix Ones() + static matrix _Ones() requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } - static matrix Ones(int rows, int cols) + static matrix _Ones(int rows, int cols) { if constexpr (Rows != -1) + { ROTGEN_ASSERT(rows == Rows, "Mismatched between dynamic and static row size"); + } if constexpr (Cols != -1) + { ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); + } return parent::Ones(rows, cols); } - static matrix Zero() + static matrix _Zero() requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } - static matrix Zero(int rows, int cols) + static matrix _Zero(int rows, int cols) { if constexpr (Rows != -1) + { ROTGEN_ASSERT(rows == Rows, "Mismatched between dynamic and static row size"); + } if constexpr (Cols != -1) + { ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); + } return parent::Zero(rows, cols); } - static matrix Random() + static matrix _Random() requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } - static matrix Random(int rows, int cols) + static matrix _Random(int rows, int cols) { if constexpr (Rows != -1) + { ROTGEN_ASSERT(rows == Rows, "Mismatched between dynamic and static row size"); + } if constexpr (Cols != -1) + { ROTGEN_ASSERT(cols == Cols, "Mismatched between dynamic and static column size"); + } return parent::Random(rows, cols); } - template value_type lpNorm() const + template value_type _lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); return parent::template lpNorm

(); @@ -416,96 +486,111 @@ namespace rotgen } using parent::operator(); - using parent::cols; + using parent::data; - using parent::mean; - using parent::norm; - using parent::prod; - using parent::rows; using parent::size; - using parent::squaredNorm; - using parent::sum; - using parent::trace; - auto minCoeff() const { return parent::minCoeff(); } + Index _cols() const { return parent::cols(); } - auto maxCoeff() const { return parent::maxCoeff(); } + Index _rows() const { return parent::rows(); } + + // Reductions + + value_type _mean() const { return parent::mean(); } + + value_type _norm() const { return parent::norm(); } + + value_type _squaredNorm() const { return parent::squaredNorm(); } + + value_type _sum() const { return parent::sum(); } + + value_type _prod() const { return parent::prod(); } + + value_type _trace() const { return parent::trace(); } + + Index _innerStride() const noexcept { return parent::innerStride(); }; + + Index _outerStride() const noexcept { return parent::outerStride(); }; + + auto _minCoeff() const { return parent::minCoeff(); } + + auto _maxCoeff() const { return parent::maxCoeff(); } template - auto minCoeff(IndexType* row, IndexType* col) const + auto _minCoeff(IndexType* row, IndexType* col) const { - Index r, c; - auto result = parent::minCoeff(&r, &c); - *row = r; - *col = c; + Index result_row, result_col; + auto result = parent::minCoeff(&result_row, &result_col); + *row = result_row; + *col = result_col; return result; } template - auto maxCoeff(IndexType* row, IndexType* col) const + auto _maxCoeff(IndexType* row, IndexType* col) const { - Index r, c; - auto result = parent::maxCoeff(&r, &c); - *row = r; - *col = c; + Index result_row, result_col; + auto result = parent::maxCoeff(&result_row, &result_col); + *row = result_row; + *col = result_col; return result; } - matrix& setOnes() + matrix& _setOnes() { - *this = parent::Ones(rows(), cols()); + *this = parent::Ones(_rows(), _cols()); return *this; } - matrix& setOnes(int r, int c) + matrix& _setOnes(int r, int c) { *this = parent::Ones(r, c); return *this; } - matrix& setZero() + matrix& _setZero() { - *this = parent::Zero(rows(), cols()); + *this = parent::Zero(_rows(), _cols()); return *this; } - matrix& setZero(int r, int c) + matrix& _setZero(int r, int c) { *this = parent::Zero(r, c); return *this; } - matrix& setConstant(Scalar value) + matrix& _setConstant(Scalar value) { - *this = parent::Constant(rows(), cols(), static_cast(value)); + *this = parent::Constant(_rows(), _cols(), value); return *this; } - matrix& setConstant(int r, int c, Scalar value) + matrix& _setConstant(int r, int c, Scalar value) { - *this = parent::Constant(r, c, static_cast(value)); + *this = parent::Constant(r, c, value); return *this; } - matrix& setRandom() + matrix& _setRandom() { - *this = parent::Random(rows(), cols()); + *this = parent::Random(_rows(), _cols()); return *this; } - matrix& setRandom(int r, int c) + matrix& _setRandom(int r, int c) { *this = parent::Random(r, c); return *this; } - matrix& setIdentity() + matrix& _setIdentity() { - *this = parent::Identity(rows(), cols()); + *this = parent::Identity(_rows(), _cols()); return *this; } - matrix& setIdentity(int r, int c) + matrix& _setIdentity(int r, int c) { *this = parent::Identity(r, c); return *this; diff --git a/include/rotgen/container/ref/dynamic.hpp b/include/rotgen/container/ref/dynamic.hpp index 6be959a..d861853 100644 --- a/include/rotgen/container/ref/dynamic.hpp +++ b/include/rotgen/container/ref/dynamic.hpp @@ -60,33 +60,33 @@ namespace rotgen using parent::operator[]; // Size related functions - using parent::cols; using parent::data; - using parent::innerStride; - using parent::outerStride; - using parent::rows; using parent::size; + using parent::_cols; + using parent::_innerStride; + using parent::_outerStride; + using parent::_rows; // Aliasing handling - using parent::evaluate; - using parent::noalias; + using parent::_evaluate; + using parent::_noalias; // Reductions - using parent::lpNorm; - using parent::maxCoeff; - using parent::mean; - using parent::minCoeff; - using parent::norm; - using parent::prod; - using parent::squaredNorm; - using parent::sum; - using parent::trace; + using parent::_lpNorm; + using parent::_maxCoeff; + using parent::_mean; + using parent::_minCoeff; + using parent::_norm; + using parent::_prod; + using parent::_squaredNorm; + using parent::_sum; + using parent::_trace; // Arithmetic - using parent::cwiseAbs; - using parent::cwiseAbs2; - using parent::cwiseInverse; - using parent::cwiseSqrt; + using parent::_cwiseAbs; + using parent::_cwiseAbs2; + using parent::_cwiseInverse; + using parent::_cwiseSqrt; // Compound Operators template @@ -128,27 +128,27 @@ namespace rotgen } // Shape modifications - using parent::adjoint; - using parent::conjugate; - using parent::normalized; - using parent::transpose; + using parent::_adjoint; + using parent::_conjugate; + using parent::_normalized; + using parent::_transpose; // In-place Shape modifications - using parent::adjointInPlace; - using parent::normalize; - using parent::transposeInPlace; + using parent::_adjointInPlace; + using parent::_normalize; + using parent::_transposeInPlace; // Generators - using parent::Constant; - using parent::Identity; - using parent::Ones; - using parent::Random; - using parent::setConstant; - using parent::setIdentity; - using parent::setOnes; - using parent::setRandom; - using parent::setZero; - using parent::Zero; + using parent::_Constant; + using parent::_Identity; + using parent::_Ones; + using parent::_Random; + using parent::_setConstant; + using parent::_setIdentity; + using parent::_setOnes; + using parent::_setRandom; + using parent::_setZero; + using parent::_Zero; using parent::operator=; using parent::operator-; @@ -348,70 +348,70 @@ namespace rotgen template auto min(ref lhs, ref rhs) - -> decltype(lhs.base().cwiseMin(rhs.base())) + -> decltype(lhs.base()._cwiseMin(rhs.base())) { - return lhs.base().cwiseMin(rhs.base()); + return lhs.base()._cwiseMin(rhs.base()); } template auto min(ref lhs, std::convertible_to auto s) - -> decltype(lhs.base().cwiseMin(s)) + -> decltype(lhs.base()._cwiseMin(s)) { - return lhs.base().cwiseMin(s); + return lhs.base()._cwiseMin(s); } template auto min(std::convertible_to auto s, ref rhs) - -> decltype(rhs.base().cwiseMin(s)) + -> decltype(rhs.base()._cwiseMin(s)) { - return rhs.base().cwiseMin(s); + return rhs.base()._cwiseMin(s); } template auto max(ref lhs, ref rhs) - -> decltype(lhs.base().cwiseMax(rhs.base())) + -> decltype(lhs.base()._cwiseMax(rhs.base())) { - return lhs.base().cwiseMax(rhs.base()); + return lhs.base()._cwiseMax(rhs.base()); } template auto max(ref lhs, std::convertible_to auto s) - -> decltype(lhs.base().cwiseMax(s)) + -> decltype(lhs.base()._cwiseMax(s)) { - return lhs.base().cwiseMax(s); + return lhs.base()._cwiseMax(s); } template auto max(std::convertible_to auto s, ref rhs) - -> decltype(rhs.base().cwiseMax(s)) + -> decltype(rhs.base()._cwiseMax(s)) { - return rhs.base().cwiseMax(s); + return rhs.base()._cwiseMax(s); } template auto mul(ref lhs, ref rhs) - -> decltype(lhs.base().cwiseProduct(rhs.base())) + -> decltype(lhs.base()._cwiseProduct(rhs.base())) { - return lhs.base().cwiseProduct(rhs.base()); + return lhs.base()._cwiseProduct(rhs.base()); } template auto div(ref lhs, ref rhs) - -> decltype(lhs.base().cwiseQuotient(rhs.base())) + -> decltype(lhs.base()._cwiseQuotient(rhs.base())) { - return lhs.base().cwiseQuotient(rhs.base()); + return lhs.base()._cwiseQuotient(rhs.base()); } template - auto inverse(ref lhs) -> decltype(lhs.base().inverse()) + auto inverse(ref lhs) -> decltype(lhs.base()._inverse()) { - return lhs.base().inverse(); + return lhs.base()._inverse(); } template auto cross(ref lhs, ref rhs) - -> decltype(lhs.base().cross(rhs.base())) + -> decltype(lhs.base()._cross(rhs.base())) { - return lhs.base().cross(rhs.base()); + return lhs.base()._cross(rhs.base()); } } diff --git a/include/rotgen/container/ref/fixed.hpp b/include/rotgen/container/ref/fixed.hpp index a49c0cf..67a1268 100644 --- a/include/rotgen/container/ref/fixed.hpp +++ b/include/rotgen/container/ref/fixed.hpp @@ -86,25 +86,30 @@ namespace rotgen // Access to values using parent::operator(); using parent::operator[]; - - // Size related functions - using parent::cols; using parent::data; - using parent::innerStride; - using parent::outerStride; - using parent::rows; using parent::size; - // Aliasing handling - auto evaluate() const { return T(base().eval()); } + // Size related functions - decltype(auto) noalias() const + Index _cols() const { return parent::cols(); } + + Index _rows() const { return parent::rows(); } + + Index _innerStride() const noexcept { return parent::innerStride(); }; + + Index _outerStride() const noexcept { return parent::outerStride(); }; + + // Aliasing handling + + auto _evaluate() const { return T(base().eval()); } + + decltype(auto) _noalias() const { if constexpr (use_expression_templates) return base().noalias(); else return *this; } - decltype(auto) noalias() + decltype(auto) _noalias() { if constexpr (use_expression_templates) return base().noalias(); else return *this; @@ -113,36 +118,64 @@ namespace rotgen // Numeric functions auto operator-() const { return detail::concretize(-base()); } - auto cwiseAbs() const + auto _cwiseAbs() const { return detail::concretize(base().cwiseAbs()); } - auto cwiseAbs2() const + auto _cwiseAbs2() const { return detail::concretize(base().cwiseAbs2()); } - auto cwiseInverse() const + auto _cwiseInverse() const { return detail::concretize(base().cwiseInverse()); } - auto cwiseSqrt() const + auto _cwiseSqrt() const { return detail::concretize(base().cwiseSqrt()); } // Reductions - using parent::lpNorm; - using parent::maxCoeff; - using parent::mean; - using parent::minCoeff; - using parent::norm; - using parent::prod; - using parent::squaredNorm; - using parent::sum; - using parent::trace; + value_type _mean() const { return parent::mean(); } + + value_type _norm() const { return parent::norm(); } + + value_type _lpNorm() const { return parent::lpNorm(); } + + value_type _squaredNorm() const { return parent::squaredNorm(); } + + value_type _sum() const { return parent::sum(); } + + value_type _prod() const { return parent::prod(); } + + value_type _trace() const { return parent::trace(); } + + auto _minCoeff() const { return parent::minCoeff(); } + + auto _maxCoeff() const { return parent::maxCoeff(); } + + template + auto _minCoeff(IndexType* row, IndexType* col) const + { + Index result_row, result_col; + auto result = parent::minCoeff(&result_row, &result_col); + *row = result_row; + *col = result_col; + return result; + } + + template + auto _maxCoeff(IndexType* row, IndexType* col) const + { + Index result_row, result_col; + auto result = parent::maxCoeff(&result_row, &result_col); + *row = result_row; + *col = result_col; + return result; + } // Compound Operators template @@ -184,102 +217,109 @@ namespace rotgen } // Shape modifications - auto normalized() const + auto _normalized() const requires(IsVectorAtCompileTime) { return detail::concretize(base().normalized()); } - auto transpose() const + auto _transpose() const { return detail::concretize(base().transpose()); } - auto adjoint() const + auto _adjoint() const { return detail::concretize(base().adjoint()); } - auto conjugate() const + auto _conjugate() const { return detail::concretize(base().conjugate()); } // In-place Shape modifications - using parent::adjointInPlace; - using parent::normalize; - using parent::transposeInPlace; + + void _adjointInPlace() { parent::adjointInPlace(); } + + void _normalize() + requires(IsVectorAtCompileTime) + { + parent::normalize(); + } + + void _transposeInPlace() { parent::transposeInPlace(); } // Generators - static auto Zero() { return detail::concretize(parent::Zero()); } + static auto _Zero() { return detail::concretize(parent::Zero()); } - static auto Zero(int rows, int cols) + static auto _Zero(int rows, int cols) { return detail::concretize(parent::Zero(rows, cols)); } - static auto Ones() { return detail::concretize(parent::Ones()); } + static auto _Ones() { return detail::concretize(parent::Ones()); } - static auto Ones(int rows, int cols) + static auto _Ones(int rows, int cols) { return detail::concretize(parent::Ones(rows, cols)); } - static auto Constant(value_type value) + static auto _Constant(value_type value) { return detail::concretize(parent::Constant(value)); } - static auto Constant(int rows, int cols, value_type value) + static auto _Constant(int rows, int cols, value_type value) { return detail::concretize(parent::Constant(rows, cols, value)); } - static auto Random() + static auto _Random() { return detail::concretize(parent::Random()); } - static auto Random(int rows, int cols) + static auto _Random(int rows, int cols) { return detail::concretize(parent::Random(rows, cols)); } - static auto Identity() + static auto _Identity() { return detail::concretize(parent::Identity()); } - static auto Identity(int rows, int cols) + static auto _Identity(int rows, int cols) { return detail::concretize(parent::Identity(rows, cols)); } - ref& setOnes() + ref& _setOnes() { base() = parent::Ones(base().rows(), base().cols()); return *this; } - ref& setZero() + ref& _setZero() { base() = parent::Zero(base().rows(), base().cols()); return *this; } - ref& setConstant(value_type value) + ref& _setConstant(value_type value) { base() = parent::Constant(base().rows(), base().cols(), value); return *this; } - ref& setRandom() + ref& _setRandom() { base() = parent::Random(base().rows(), base().cols()); return *this; } - ref& setIdentity() + ref& _setIdentity() { base() = parent::Identity(base().rows(), base().cols()); return *this; diff --git a/include/rotgen/container/ref/functions.hpp b/include/rotgen/container/ref/functions.hpp index eb62875..e8425a1 100644 --- a/include/rotgen/container/ref/functions.hpp +++ b/include/rotgen/container/ref/functions.hpp @@ -7,6 +7,8 @@ //================================================================================================== #pragma once +#include + #include namespace rotgen @@ -34,7 +36,18 @@ namespace rotgen template auto dot(ref const& lhs, ref const& rhs) { - return lhs.base().dot(rhs.base()); + if constexpr (requires { lhs.base().dot(rhs.base()); }) + { + return lhs.base().dot(rhs.base()); + } + else if constexpr (requires { lhs.base()._dot(rhs.base()); }) + { + return lhs.base()._dot(rhs.base()); + } + else + { + return detail::unsupported_parameters(); + } } template diff --git a/include/rotgen/container/ref/generalize.hpp b/include/rotgen/container/ref/generalize.hpp index 93a24bb..855f452 100644 --- a/include/rotgen/container/ref/generalize.hpp +++ b/include/rotgen/container/ref/generalize.hpp @@ -1,13 +1,16 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== #pragma once +#include #include +#include +#include #include @@ -15,7 +18,7 @@ namespace rotgen { template class quaternion; - //------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Convert entity/eigen types to a proper ref so we can write less function // overloads diff --git a/include/rotgen/detail/accept_as_ref.hpp b/include/rotgen/detail/accept_as_ref.hpp index b738224..89c29de 100644 --- a/include/rotgen/detail/accept_as_ref.hpp +++ b/include/rotgen/detail/accept_as_ref.hpp @@ -9,6 +9,8 @@ #include +#include + #include namespace rotgen::detail @@ -73,34 +75,34 @@ namespace rotgen::detail using parent = typename Ref::parent; using map_base = typename parent::parent; - auto rows = in.rows(); - auto cols = in.cols(); + auto r = rows(in); + auto c = cols(in); if (Ref::RowsAtCompileTime == 1) { - ROTGEN_ASSERT(in.rows() == 1 || in.cols() == 1, + ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, "Incompatible rows/cols in ref binding"); - rows = 1; - cols = in.size(); + r = 1; + c = in.size(); } else if (Ref::ColsAtCompileTime == 1) { - ROTGEN_ASSERT(in.rows() == 1 || in.cols() == 1, + ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, "Incompatible rows/cols in ref binding"); - rows = in.size(); - cols = 1; + r = in.size(); + c = 1; } // Verify that the sizes are valid. ROTGEN_ASSERT((Ref::RowsAtCompileTime == Dynamic) || - (Ref::RowsAtCompileTime == rows), + (Ref::RowsAtCompileTime == r), "Incompatible static rows/cols in ref binding"); ROTGEN_ASSERT((Ref::ColsAtCompileTime == Dynamic) || - (Ref::ColsAtCompileTime == cols), + (Ref::ColsAtCompileTime == c), "Incompatible static rows/cols in ref binding"); // Swap stride if we are a vector and we changed rows as such - bool transpose = Ref::IsVectorAtCompileTime && (rows != in.rows()); + bool transpose = Ref::IsVectorAtCompileTime && (r != rows(in)); // Swap stride if storage ordder doesn't match constexpr bool row_major = Ref::IsRowMajor; @@ -110,13 +112,13 @@ namespace rotgen::detail bool swap_stride = (transpose != storage_differs); // Determine expr's actual strides, resolving any defaults if zero. - Index inner_actual = proper_inner_stride(in.innerStride()); + Index inner_actual = proper_inner_stride(innerStride(in)); Index outer_actual = - proper_outer_stride(inner_actual, in.outerStride(), in.rows(), in.cols(), + proper_outer_stride(inner_actual, outerStride(in), rows(in), cols(in), Input::IsVectorAtCompileTime, input_row_major); - bool row_vector = (rows == 1); - bool col_vector = (cols == 1); + bool row_vector = (r == 1); + bool col_vector = (c == 1); // Adapt inner stride based on row/col vector status Index inner_stride = @@ -132,7 +134,7 @@ namespace rotgen::detail ((!row_major && col_vector) || (row_major && row_vector)) ? (stride_type::OuterStrideAtCompileTime > 0 ? stride_type::OuterStrideAtCompileTime - : rows * cols * inner_stride) + : r * c * inner_stride) : swap_stride ? inner_actual : outer_actual; @@ -147,7 +149,7 @@ namespace rotgen::detail bool outer_valid = (stride_type::OuterStrideAtCompileTime == Dynamic) || (proper_outer_stride( - inner_stride, Index(stride_type::OuterStrideAtCompileTime), rows, cols, + inner_stride, Index(stride_type::OuterStrideAtCompileTime), r, c, Ref::IsVectorAtCompileTime != 0, row_major) == outer_stride); if (!outer_valid) return false; @@ -156,7 +158,7 @@ namespace rotgen::detail stride_type::OuterStrideAtCompileTime == 0 ? 1 : outer_stride, stride_type::InnerStrideAtCompileTime == 0 ? 1 : inner_stride); - auto actual = map_base(in.data(), rows, cols, proper_stride); + auto actual = map_base(in.data(), r, c, proper_stride); ref.base().base().storage().swap(actual.storage()); diff --git a/include/rotgen/detail/helpers.hpp b/include/rotgen/detail/helpers.hpp index 5c839d9..2003cf9 100644 --- a/include/rotgen/detail/helpers.hpp +++ b/include/rotgen/detail/helpers.hpp @@ -1,10 +1,10 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== #pragma once #include @@ -15,6 +15,15 @@ namespace rotgen::detail { + /// Returned when a function is called with unsupported parameters, + /// effectively triggering a compile error to avoid undefined behaviors in + /// cases where return directives are missing. + template auto unsupported_parameters() + { + static_assert(sizeof(T) == 0, + "Function was called with unsupported parameters."); + }; + template constexpr int static_size() { auto rows = T::RowsAtCompileTime; diff --git a/include/rotgen/functions/extract.hpp b/include/rotgen/functions/extract.hpp index e10c457..492f0a7 100644 --- a/include/rotgen/functions/extract.hpp +++ b/include/rotgen/functions/extract.hpp @@ -1,13 +1,17 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== #pragma once + +#include #include +#include + #include namespace rotgen @@ -23,9 +27,9 @@ namespace rotgen { ROTGEN_ASSERT(i0 >= 0, "block extraction uses negative row index."); ROTGEN_ASSERT(j0 >= 0, "block extraction uses negative col index."); - ROTGEN_ASSERT(i0 + ni <= e.rows(), + ROTGEN_ASSERT(i0 + ni <= rows(e), "block extraction rows is out of range."); - ROTGEN_ASSERT(j0 + nj <= e.cols(), + ROTGEN_ASSERT(j0 + nj <= cols(e), "block extraction cols is out of range."); } } @@ -83,55 +87,55 @@ namespace rotgen template auto topRightCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), 0, e.cols() - nj, ni, nj); + return extract(ROTGEN_FWD(e), 0, cols(e) - nj, ni, nj); } template auto topRightCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), 0, e.cols() - NJ); + return extract(ROTGEN_FWD(e), 0, cols(e) - NJ); } //======================== BOTTOM LEFT CORNER ======================== template auto bottomLeftCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, nj); + return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, nj); } template auto bottomLeftCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), e.rows() - NI, 0); + return extract(ROTGEN_FWD(e), rows(e) - NI, 0); } //======================== BOTTOM RIGHT CORNER ======================== template auto bottomRightCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), e.rows() - ni, e.cols() - nj, ni, nj); + return extract(ROTGEN_FWD(e), rows(e) - ni, cols(e) - nj, ni, nj); } template auto bottomRightCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), e.rows() - NI, e.cols() - NJ); + return extract(ROTGEN_FWD(e), rows(e) - NI, cols(e) - NJ); } //======================== TOP ROWS ======================== template auto topRows(Entity&& e, Index ni) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, 0, ni, e.cols()); + return extract(ROTGEN_FWD(e), 0, 0, ni, cols(e)); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), 0, 0, ni, e.cols()); + ROTGEN_FWD(e), 0, 0, ni, cols(e)); } template auto topRows(Entity&& e) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, 0, NI, e.cols()); + return extract(ROTGEN_FWD(e), 0, 0, NI, cols(e)); else return extract::ColsAtCompileTime>( ROTGEN_FWD(e), 0, 0); @@ -142,17 +146,17 @@ namespace rotgen auto middleRows(Entity&& e, Index i0, Index ni) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), i0, 0, ni, e.cols()); + return extract(ROTGEN_FWD(e), i0, 0, ni, cols(e)); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), i0, 0, ni, e.cols()); + ROTGEN_FWD(e), i0, 0, ni, cols(e)); } template auto middleRows(Entity&& e, Index i0) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), i0, 0, NI, e.cols()); + return extract(ROTGEN_FWD(e), i0, 0, NI, cols(e)); else return extract::ColsAtCompileTime>( ROTGEN_FWD(e), i0, 0); @@ -162,35 +166,35 @@ namespace rotgen template auto bottomRows(Entity&& e, Index ni) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols()); + return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols()); + ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); } template auto bottomRows(Entity&& e) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), e.rows() - NI, 0, NI, e.cols()); + return extract(ROTGEN_FWD(e), rows(e) - NI, 0, NI, cols(e)); else return extract::ColsAtCompileTime>( - ROTGEN_FWD(e), e.rows() - NI, 0); + ROTGEN_FWD(e), rows(e) - NI, 0); } //======================== LEFT COLS ======================== template auto leftCols(Entity&& e, Index nj) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, 0, e.rows(), nj); + return extract(ROTGEN_FWD(e), 0, 0, rows(e), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, 0, e.rows(), nj); + ROTGEN_FWD(e), 0, 0, rows(e), nj); } template auto leftCols(Entity&& e) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, e.rows(), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, rows(e), NJ); else return extract::RowsAtCompileTime, NJ>( ROTGEN_FWD(e), 0, 0); @@ -201,17 +205,17 @@ namespace rotgen auto middleCols(Entity&& e, Index j0, Index nj) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, j0, e.rows(), nj); + return extract(ROTGEN_FWD(e), 0, j0, rows(e), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, j0, e.rows(), nj); + ROTGEN_FWD(e), 0, j0, rows(e), nj); } template auto middleCols(Entity&& e, Index j0) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, NJ>(ROTGEN_FWD(e), 0, j0, e.rows(), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, j0, rows(e), NJ); else return extract::RowsAtCompileTime, NJ>( ROTGEN_FWD(e), 0, j0); @@ -221,27 +225,27 @@ namespace rotgen template auto rightCols(Entity&& e, Index nj) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj); + return extract(ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj); + ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); ; } template auto rightCols(Entity&& e) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, NJ>(ROTGEN_FWD(e), 0, e.cols() - NJ, e.rows(), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, cols(e) - NJ, rows(e), NJ); else return extract::RowsAtCompileTime, NJ>( - ROTGEN_FWD(e), 0, e.cols() - NJ); + ROTGEN_FWD(e), 0, cols(e) - NJ); } //======================== ROW ======================== template auto row(Entity&& e, Index i0) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract<1, -1>(ROTGEN_FWD(e), i0, 0, 1, e.cols()); + return extract<1, -1>(ROTGEN_FWD(e), i0, 0, 1, cols(e)); else return extract<1, std::remove_cvref_t::ColsAtCompileTime>( ROTGEN_FWD(e), i0, 0); @@ -251,7 +255,7 @@ namespace rotgen template auto col(Entity&& e, Index j0) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, 1>(ROTGEN_FWD(e), 0, j0, e.rows(), 1); + return extract<-1, 1>(ROTGEN_FWD(e), 0, j0, rows(e), 1); else return extract::RowsAtCompileTime, 1>( ROTGEN_FWD(e), 0, j0); @@ -287,9 +291,9 @@ namespace rotgen std::remove_cvref_t::ColsAtCompileTime == 1) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == 1) - return extract<1, Dynamic>(ROTGEN_FWD(e), 0, e.cols() - n, 1, n); + return extract<1, Dynamic>(ROTGEN_FWD(e), 0, cols(e) - n, 1, n); else if constexpr (std::remove_cvref_t::ColsAtCompileTime == 1) - return extract(ROTGEN_FWD(e), e.rows() - n, 0, n, 1); + return extract(ROTGEN_FWD(e), rows(e) - n, 0, n, 1); } template @@ -298,9 +302,9 @@ namespace rotgen std::remove_cvref_t::ColsAtCompileTime == 1) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == 1) - return extract<1, N>(ROTGEN_FWD(e), 0, e.cols() - N); + return extract<1, N>(ROTGEN_FWD(e), 0, cols(e) - N); else if constexpr (std::remove_cvref_t::ColsAtCompileTime == 1) - return extract(ROTGEN_FWD(e), e.rows() - N, 0); + return extract(ROTGEN_FWD(e), rows(e) - N, 0); } //======================== VECTOR SEGMENT ======================== diff --git a/include/rotgen/functions/functions.hpp b/include/rotgen/functions/functions.hpp index 7733f2d..a7c0ab4 100644 --- a/include/rotgen/functions/functions.hpp +++ b/include/rotgen/functions/functions.hpp @@ -1,187 +1,371 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== #pragma once #include +#include +#include + namespace rotgen { - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Infos & Shape - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + + /// Returns the row count of a matrix. Index rows(auto const& m) - requires(requires { m.rows(); }) { - return m.rows(); + if constexpr (requires { m.rows(); }) { return m.rows(); } + else if constexpr (requires { m._rows(); }) { return m._rows(); } + else + { + return detail::unsupported_parameters(); + } } + /// Returns the column count of a matrix. Index cols(auto const& m) - requires(requires { m.cols(); }) { - return m.cols(); + + if constexpr (requires { m.cols(); }) { return m.cols(); } + else if constexpr (requires { m._cols(); }) { return m._cols(); } + else + { + return detail::unsupported_parameters(); + } } + Index startRow(auto const& m) + { + if constexpr (requires { m.startRow(); }) { return m.startRow(); } + else if constexpr (requires { m._startRow(); }) { return m._startRow(); } + else + { + return detail::unsupported_parameters(); + } + } + + Index startCol(auto const& m) + { + if constexpr (requires { m.startCol(); }) { return m.startCol(); } + else if constexpr (requires { m._startCol(); }) { return m._startCol(); } + else + { + return detail::unsupported_parameters(); + } + } + + /// Returns the size of a matrix. Index size(auto const& m) requires(requires { m.size(); }) { return m.size(); } - void resize(auto& a, int s) - requires requires { a.resize(s); } + /// Resizes a matrix into a vector of size s. + void resize(auto& m, int s) + requires requires { m.resize(s); } { - a.resize(s); + m.resize(s); } - void resize(auto& a, int r, int c) - requires requires { a.resize(r, c); } + /// Resizes a matrix into with a given number of rows and columns. + void resize(auto& m, int r, int c) + requires requires { m.resize(r, c); } { - a.resize(r, c); + m.resize(r, c); } void conservativeResize(auto& a, int s) - requires requires { a.conservativeResize(s); } { - a.conservativeResize(s); + if constexpr (requires { a.conservativeResize(s); }) + { + a.conservativeResize(s); + } + else if constexpr (requires { a._conservativeResize(s); }) + { + a._conservativeResize(s); + } + else + { + return detail::unsupported_parameters(); + } } void conservativeResize(auto& a, int r, int c) - requires requires { a.conservativeResize(r, c); } { - a.conservativeResize(r, c); + if constexpr (requires { a.conservativeResize(r, c); }) + { + a.conservativeResize(r, c); + } + else if constexpr (requires { a._conservativeResize(r, c); }) + { + a._conservativeResize(r, c); + } + else + { + return detail::unsupported_parameters(); + } } - //----------------------------------------------------------------------------------------------- - // Global operations - //----------------------------------------------------------------------------------------------- - decltype(auto) normalized(auto const& m) - requires(requires { m.normalized(); }) + Index innerStride(auto const& m) { - return m.normalized(); + if constexpr (requires { m.innerStride(); }) { return m.innerStride(); } + else if constexpr (requires { m._innerStride(); }) + { + return m._innerStride(); + } + else + { + return detail::unsupported_parameters(); + } + } + + Index outerStride(auto const& m) + { + if constexpr (requires { m.outerStride(); }) { return m.outerStride(); } + else if constexpr (requires { m._outerStride(); }) + { + return m._outerStride(); + } + else + { + return detail::unsupported_parameters(); + } + } + + //---------------------------------------------------------------------------- + // Global operations + //---------------------------------------------------------------------------- + + decltype(auto) normalized(auto const& m) + { + if constexpr (requires { m.normalized(); }) { return m.normalized(); } + else if constexpr (requires { m._normalized(); }) + { + return m._normalized(); + } + else + { + return detail::unsupported_parameters(); + } } decltype(auto) transpose(auto const& m) - requires(requires { m.transpose(); }) { - return m.transpose(); + if constexpr (requires { m.transpose(); }) { return m.transpose(); } + else if constexpr (requires { m._transpose(); }) { return m._transpose(); } + else + { + return detail::unsupported_parameters(); + } } decltype(auto) conjugate(auto const& m) - requires(requires { m.conjugate(); }) { - return m.conjugate(); + if constexpr (requires { m.conjugate(); }) { return m.conjugate(); } + else if constexpr (requires { m._conjugate(); }) { return m._conjugate(); } } decltype(auto) adjoint(auto const& m) - requires(requires { m.adjoint(); }) { - return m.adjoint(); + if constexpr (requires { m.adjoint(); }) { return m.adjoint(); } + else if constexpr (requires { m._adjoint(); }) { return m._adjoint(); } + else + { + return detail::unsupported_parameters(); + } } void normalize(auto& a) - requires(requires { a.normalize(); }) { - a.normalize(); + if constexpr (requires { a.normalize(); }) { a.normalize(); } + else if constexpr (requires { a._normalize(); }) // PROCESSME + { + a._normalize(); + } + else + { + return detail::unsupported_parameters(); + } } void transposeInPlace(auto& a) - requires(requires { a.transposeInPlace(); }) { - a.transposeInPlace(); + if constexpr (requires { a.transposeInPlace(); }) { a.transposeInPlace(); } + else if constexpr (requires { a._transposeInPlace(); }) // PROCESSME + { + a._transposeInPlace(); + } + else + { + return detail::unsupported_parameters(); + } } void adjointInPlace(auto& a) - requires(requires { a.adjointInPlace(); }) { - a.adjointInPlace(); + if constexpr (requires { a.adjointInPlace(); }) { a.adjointInPlace(); } + else if constexpr (requires { a._adjointInPlace(); }) // PROCESSME + { + a._adjointInPlace(); + } + else + { + return detail::unsupported_parameters(); + } } - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Component-wise functions - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + auto abs(auto const& arg) - requires(requires { arg.cwiseAbs(); }) { - return arg.cwiseAbs(); + if constexpr (requires { arg.cwiseAbs(); }) { return arg.cwiseAbs(); } + else if constexpr (requires { arg._cwiseAbs(); }) + { + return arg._cwiseAbs(); + } + else + { + return detail::unsupported_parameters(); + } } auto abs2(auto const& arg) - requires(requires { arg.cwiseAbs2(); }) { - return arg.cwiseAbs2(); + if constexpr (requires { arg.cwiseAbs2(); }) { return arg.cwiseAbs2(); } + else if constexpr (requires { arg._cwiseAbs2(); }) + { + return arg._cwiseAbs2(); + } + else + { + return detail::unsupported_parameters(); + } } auto rec(auto const& arg) - requires(requires { arg.cwiseInverse(); }) { - return arg.cwiseInverse(); + if constexpr (requires { arg.cwiseInverse(); }) + { + return arg.cwiseInverse(); + } + else if constexpr (requires { arg._cwiseInverse(); }) + { + return arg._cwiseInverse(); + } + else + { + return detail::unsupported_parameters(); + } } auto sqrt(auto const& arg) - requires(requires { arg.cwiseSqrt(); }) { - return arg.cwiseSqrt(); + if constexpr (requires { arg.cwiseSqrt(); }) { return arg.cwiseSqrt(); } + else if constexpr (requires { arg._cwiseSqrt(); }) + { + return arg._cwiseSqrt(); + } } template auto min(A const& a, B const& b) { if constexpr (!use_expression_templates) + { return min(generalize_t(a), generalize_t(b)); - else return base_of(a).cwiseMin(base_of(b)); + } + else + { + return base_of(a).cwiseMin(base_of(b)); + } } template auto min(A const& a, std::convertible_to auto b) { if constexpr (!use_expression_templates) + { return min(generalize_t(a), b); - else return base_of(a).cwiseMin(b); + } + else + { + return base_of(a).cwiseMin(b); + } } template auto min(std::convertible_to auto a, B const& b) { if constexpr (!use_expression_templates) + { return min(a, generalize_t(b)); - else return base_of(b).cwiseMin(a); + } + else + { + return base_of(b).cwiseMin(a); + } } template auto max(A const& a, B const& b) { if constexpr (!use_expression_templates) + { return max(generalize_t(a), generalize_t(b)); - else return base_of(a).cwiseMax(base_of(b)); + } + else + { + return base_of(a).cwiseMax(base_of(b)); + } } template auto max(A const& a, std::convertible_to auto b) { if constexpr (!use_expression_templates) + { return max(generalize_t(a), b); - else return base_of(a).cwiseMax(b); + } + else + { + return base_of(a).cwiseMax(b); + } } template auto max(std::convertible_to auto a, B const& b) { if constexpr (!use_expression_templates) + { return max(a, generalize_t(b)); - else return base_of(b).cwiseMax(a); + } + else + { + return base_of(b).cwiseMax(a); + } } template auto mul(A const& a, B const& b) { if constexpr (!use_expression_templates) + { return mul(generalize_t(a), generalize_t(b)); - else return base_of(a).cwiseProduct(base_of(b)); + } + else + { + return base_of(a).cwiseProduct(base_of(b)); + } } template @@ -200,8 +384,13 @@ namespace rotgen auto div(A const& a, B const& b) { if constexpr (!use_expression_templates) + { return div(generalize_t(a), generalize_t(b)); - else return base_of(a).array() / base_of(b).array(); + } + else + { + return base_of(a).array() / base_of(b).array(); + } } template @@ -215,43 +404,71 @@ namespace rotgen return mul(a, a); } - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Reductions - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + auto trace(auto const& arg) - requires requires { arg.trace(); } { - return arg.trace(); + if constexpr (requires { arg.trace(); }) { return arg.trace(); } + else if constexpr (requires { arg._trace(); }) { return arg._trace(); } + else + { + return detail::unsupported_parameters(); + } } auto squaredNorm(auto const& arg) - requires requires { arg.squaredNorm(); } { - return arg.squaredNorm(); + if constexpr (requires { arg.squaredNorm(); }) { return arg.squaredNorm(); } + else if constexpr (requires { arg._squaredNorm(); }) + { + return arg._squaredNorm(); + } + else + { + return detail::unsupported_parameters(); + } } auto norm(auto const& arg) - requires requires { arg.norm(); } { - return arg.norm(); + if constexpr (requires { arg.norm(); }) { return arg.norm(); } + else if constexpr (requires { arg._norm(); }) { return arg._norm(); } + else + { + return detail::unsupported_parameters(); + } } auto sum(auto const& arg) - requires requires { arg.sum(); } { - return arg.sum(); + if constexpr (requires { arg.sum(); }) { return arg.sum(); } + else if constexpr (requires { arg._sum(); }) { return arg._sum(); } + else + { + return detail::unsupported_parameters(); + } } auto prod(auto const& arg) - requires requires { arg.prod(); } { - return arg.prod(); + if constexpr (requires { arg.prod(); }) { return arg.prod(); } + else if constexpr (requires { arg._prod(); }) { return arg._prod(); } + else + { + return detail::unsupported_parameters(); + } } auto mean(auto const& arg) - requires requires { arg.mean(); } { - return arg.mean(); + if constexpr (requires { arg.mean(); }) { return arg.mean(); } + else if constexpr (requires { arg._mean(); }) { return arg._mean(); } + else + { + return detail::unsupported_parameters(); + } } template @@ -260,89 +477,167 @@ namespace rotgen std::same_as) { if constexpr (!use_expression_templates) + { return dot(generalize_t(a), generalize_t(b)); - else return base_of(a).dot(base_of(b)); + } + else + { + return base_of(a).dot(base_of(b)); + } } auto maxCoeff(auto const& arg) - requires(requires { arg.maxCoeff(); }) { - return arg.maxCoeff(); + if constexpr (requires { arg.maxCoeff(); }) { return arg.maxCoeff(); } + else if constexpr (requires { arg._maxCoeff(); }) + { + return arg._maxCoeff(); + } + else + { + return detail::unsupported_parameters(); + } } auto minCoeff(auto const& arg) - requires(requires { arg.minCoeff(); }) { - return arg.minCoeff(); + if constexpr (requires { arg.minCoeff(); }) { return arg.minCoeff(); } + else if constexpr (requires { arg._minCoeff(); }) + { + return arg._minCoeff(); + } + else + { + return detail::unsupported_parameters(); + } } template auto maxCoeff(auto const& arg, IndexType* row, IndexType* col) - requires(requires { arg.maxCoeff(row, col); }) { - return arg.maxCoeff(row, col); + if constexpr (requires { arg.maxCoeff(row, col); }) + { + return arg.maxCoeff(row, col); + } + else if constexpr (requires { arg._maxCoeff(row, col); }) + { + return arg._maxCoeff(row, col); + } + else + { + return detail::unsupported_parameters(); + } } template auto minCoeff(auto const& arg, IndexType* row, IndexType* col) - requires(requires { arg.minCoeff(row, col); }) { - return arg.minCoeff(row, col); + if constexpr (requires { arg.minCoeff(row, col); }) + { + return arg.minCoeff(row, col); + } + else if constexpr (requires { arg._minCoeff(row, col); }) + { + return arg._minCoeff(row, col); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto lpNorm(T const& arg) - requires(requires { arg.template lpNorm

(); }) + template auto lpNorm(T const& arg) { - static_assert(P == 1 || P == 2 || P == Infinity); - return arg.template lpNorm

(); + if constexpr (requires { arg.template lpNorm

(); }) + { + static_assert(P == 1 || P == 2 || P == Infinity); + return arg.template lpNorm

(); + } + else if constexpr (requires { arg.template _lpNorm

(); }) + { + static_assert(P == 1 || P == 2 || P == Infinity); + return arg.template _lpNorm

(); + } + else + { + return detail::unsupported_parameters(); + } } - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Expression handling - //----------------------------------------------------------------------------------------------- - template - decltype(auto) noalias(T&& t) - requires(requires { std::forward(t).noalias(); }) + //---------------------------------------------------------------------------- + + template decltype(auto) noalias(T&& t) { - return std::forward(t).noalias(); + if constexpr (requires { std::forward(t).noalias(); }) + { + return std::forward(t).noalias(); + } + else if constexpr (requires { std::forward(t)._noalias(); }) + { + return std::forward(t)._noalias(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto evaluate(T&& t) - requires(requires { std::forward(t).evaluate(); }) + template auto evaluate(T&& t) { - return std::forward(t).evaluate(); + if constexpr (requires { std::forward(t).evaluate(); }) + { + return std::forward(t).evaluate(); + } + else if constexpr (requires { std::forward(t)._evaluate(); }) + { + return std::forward(t)._evaluate(); + } + else if constexpr (requires { std::forward(t).eval(); }) + { + return std::forward(t).eval(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto evaluate(T&& t) - requires(requires { std::forward(t).eval(); }) - { - return std::forward(t).eval(); - } - - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Others // TODO: Adapt other functions ot behave as inverse and limit code in // non-ref/non-map containers - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + template auto inverse(A const& a) { if constexpr (!use_expression_templates) + { return inverse(generalize_t(a)); - else return base_of(a).inverse(); + } + else + { + return base_of(a).inverse(); + } } template L, concepts::vectorND<3> R> auto cross(L const& l, R const& r) { if constexpr (!use_expression_templates) + { return cross(generalize_t(l), generalize_t(r)); + } else if constexpr ( requires { typename L::rotgen_tag; } || requires { typename R::rotgen_tag; }) - return base_of(l).cross(base_of(r)); - else return l.cross(r); + { + return base_of(l)._cross(base_of(r)); + } + else + { + return l._cross(r); + } } } diff --git a/include/rotgen/functions/generators.hpp b/include/rotgen/functions/generators.hpp index 96c6f34..b627626 100644 --- a/include/rotgen/functions/generators.hpp +++ b/include/rotgen/functions/generators.hpp @@ -1,19 +1,22 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== #pragma once #include #include +#include + namespace rotgen { - //----------------------------------------------------------------------------------------------- - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- + template void initialize_with(T&& m, Args... v) { using type = typename std::remove_cvref_t::value_type; @@ -22,149 +25,264 @@ namespace rotgen ROTGEN_ASSERT(sizeof...(v) == m.size(), "Incorrect quantity of coefficients for initialization"); type data[] = {static_cast(v)...}; - m = map_t(data, m.rows(), m.cols()); + m = map_t(data, rows(m), cols(m)); } - //----------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------- // Generators - //----------------------------------------------------------------------------------------------- - template - auto setZero(T&& t) - requires(requires { std::forward(t).setZero(); }) + //---------------------------------------------------------------------------- + + template auto setZero(T&& t) { - return std::forward(t).setZero(); + if constexpr (requires { std::forward(t).setZero(); }) + { + return std::forward(t).setZero(); + } + else if constexpr (requires { std::forward(t)._setZero(); }) + { + return std::forward(t)._setZero(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setZero() - requires(requires { T::Zero(); }) + template auto setZero() { - return T::Zero(); + if constexpr (requires { T::Zero(); }) { return T::Zero(); } + else if constexpr (requires { T::_Zero(); }) { return T::_Zero(); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setZero(std::integral auto n) - requires(requires { T::Zero(n); }) + template auto setZero(std::integral auto n) { - return T::Zero(n); + if constexpr (requires { T::Zero(n); }) { return T::Zero(n); } + else if constexpr (requires { T::_Zero(n); }) { return T::_Zero(n); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setZero(std::integral auto r, std::integral auto c) - requires(requires { T::Zero(r, c); }) + template auto setZero(std::integral auto r, std::integral auto c) { - return T::Zero(r, c); + if constexpr (requires { T::Zero(r, c); }) { return T::Zero(r, c); } + else if constexpr (requires { T::_Zero(r, c); }) { return T::_Zero(r, c); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setOnes(T&& t) - requires(requires { std::forward(t).setOnes(); }) + template auto setOnes(T&& t) { - return std::forward(t).setOnes(); + if constexpr (requires { std::forward(t).setOnes(); }) + { + return std::forward(t).setOnes(); + } + else if constexpr (requires { std::forward(t)._setOnes(); }) + { + return std::forward(t)._setOnes(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setOnes() - requires(requires { T::Ones(); }) + template auto setOnes() { - return T::Ones(); + if constexpr (requires { T::Ones(); }) { return T::Ones(); } + else if constexpr (requires { T::_Ones(); }) { return T::_Ones(); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setOnes(std::integral auto n) - requires(requires { T::Ones(n); }) + template auto setOnes(std::integral auto n) { - return T::Ones(n); + if constexpr (requires { T::Ones(n); }) { return T::Ones(n); } + else if constexpr (requires { T::_Ones(n); }) { return T::_Ones(n); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setOnes(std::integral auto r, std::integral auto c) - requires(requires { T::Ones(r, c); }) + template auto setOnes(std::integral auto r, std::integral auto c) { - return T::Ones(r, c); + if constexpr (requires { T::Ones(r, c); }) { return T::Ones(r, c); } + else if constexpr (requires { T::_Ones(r, c); }) { return T::_Ones(r, c); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setIdentity(T&& t) - requires(requires { std::forward(t).setIdentity(); }) + template auto setIdentity(T&& t) { - return std::forward(t).setIdentity(); + if constexpr (requires { std::forward(t).setIdentity(); }) + { + return std::forward(t).setIdentity(); + } + else if constexpr (requires { std::forward(t)._setIdentity(); }) + { + return std::forward(t)._setIdentity(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setIdentity() - requires(requires { T::Identity(); }) + template auto setIdentity() { - return T::Identity(); + if constexpr (requires { T::Identity(); }) { return T::Identity(); } + else if constexpr (requires { T::_Identity(); }) { return T::_Identity(); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setIdentity(std::integral auto n) - requires(requires { T::Identity(n); }) + template auto setIdentity(std::integral auto n) { - return T::Identity(n); + if constexpr (requires { T::Identity(n); }) { return T::Identity(n); } + else if constexpr (requires { T::_Identity(n); }) + { + return T::_Identity(n); + } + else + { + return detail::unsupported_parameters(); + } } template auto setIdentity(std::integral auto r, std::integral auto c) - requires(requires { T::Identity(r, c); }) { - return T::Identity(r, c); + if constexpr (requires { T::Identity(r, c); }) { return T::Identity(r, c); } + else if constexpr (requires { T::_Identity(r, c); }) + { + return T::_Identity(r, c); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setRandom(T&& t) - requires(requires { std::forward(t).setRandom(); }) + template auto setRandom(T&& t) { - return std::forward(t).setRandom(); + if constexpr (requires { std::forward(t).setRandom(); }) + { + return std::forward(t).setRandom(); + } + else if constexpr (requires { std::forward(t)._setRandom(); }) + { + return std::forward(t)._setRandom(); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setRandom() - requires(requires { T::Random(); }) + template auto setRandom() { - return T::Random(); + if constexpr (requires { T::Random(); }) { return T::Random(); } + else if constexpr (requires { T::_Random(); }) { return T::_Random(); } + else + { + return detail::unsupported_parameters(); + } } - template - auto setRandom(std::integral auto n) - requires(requires { T::Random(n); }) + template auto setRandom(std::integral auto n) { - return T::Random(n); + if constexpr (requires { T::Random(n); }) { return T::Random(n); } + else if constexpr (requires { T::_Random(n); }) { return T::_Random(n); } + else + { + return detail::unsupported_parameters(); + } } template auto setRandom(std::integral auto r, std::integral auto c) - requires(requires { T::Random(r, c); }) { - return T::Random(r, c); + if constexpr (requires { T::Random(r, c); }) { return T::Random(r, c); } + else if constexpr (requires { T::_Random(r, c); }) + { + return T::_Random(r, c); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setConstant(T&& t, auto v) - requires(requires { std::forward(t).setConstant(v); }) + template auto setConstant(T&& t, auto v) { - return std::forward(t).setConstant(v); + if constexpr (requires { std::forward(t).setConstant(v); }) + { + return std::forward(t).setConstant(v); + } + else if constexpr (requires { std::forward(t)._setConstant(v); }) + { + return std::forward(t)._setConstant(v); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setConstant(auto v) - requires(requires { T::Constant(v); }) + template auto setConstant(auto v) { - return T::Constant(v); + if constexpr (requires { T::Constant(v); }) { return T::Constant(v); } + else if constexpr (requires { T::_Constant(v); }) + { + return T::_Constant(v); + } + else + { + return detail::unsupported_parameters(); + } } - template - auto setConstant(std::integral auto n, auto v) - requires(requires { T::Constant(n, v); }) + template auto setConstant(std::integral auto n, auto v) { - return T::Constant(n, v); + if constexpr (requires { T::Constant(n, v); }) { return T::Constant(n, v); } + else if constexpr (requires { T::_Constant(n, v); }) + { + return T::_Constant(n, v); + } + else + { + return detail::unsupported_parameters(); + } } template auto setConstant(std::integral auto r, std::integral auto c, auto v) - requires(requires { T::Constant(r, c, v); }) { - return T::Constant(r, c, v); + if constexpr (requires { T::Constant(r, c, v); }) + { + return T::Constant(r, c, v); + } + else if constexpr (requires { T::_Constant(r, c, v); }) + { + return T::_Constant(r, c, v); + } + else + { + return detail::unsupported_parameters(); + } } } diff --git a/include/rotgen/functions/reshaper.hpp b/include/rotgen/functions/reshaper.hpp index b47d347..89a030b 100644 --- a/include/rotgen/functions/reshaper.hpp +++ b/include/rotgen/functions/reshaper.hpp @@ -7,6 +7,11 @@ //================================================================================================== #pragma once +#include +#include + +#include + namespace rotgen { template struct rowwise_adaptor @@ -14,64 +19,64 @@ namespace rotgen using concrete_type = typename std::remove_cvref_t::concrete_type; Ref& target_; - concrete_type sum() const + concrete_type _sum() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.sum(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); return res; } - concrete_type mean() const + concrete_type _mean() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.mean(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); return res; } - concrete_type prod() const + concrete_type _prod() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.prod(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); return res; } - concrete_type maxCoeff() const + concrete_type _maxCoeff() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); return res; } - concrete_type minCoeff() const + concrete_type _minCoeff() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.minCoeff(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); return res; } - concrete_type squaredNorm() const + concrete_type _squaredNorm() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); return res; } - concrete_type norm() const + concrete_type _norm() const { - concrete_type res(target_.rows(), 1); - apply([&](auto r, auto i) { res(i) = r.norm(); }); + concrete_type res(rows(target_), 1); + apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); return res; } private: template void apply(Func f) { - for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i); + for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } } template void apply(Func f) const { - for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i); + for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } } }; @@ -80,76 +85,82 @@ namespace rotgen using concrete_type = typename std::remove_cvref_t::concrete_type; Ref& target_; - concrete_type sum() const + concrete_type _sum() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.sum(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); return res; } - concrete_type mean() const + concrete_type _mean() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.mean(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); return res; } - concrete_type prod() const + concrete_type _prod() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.prod(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); return res; } - concrete_type maxCoeff() const + concrete_type _maxCoeff() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); return res; } - concrete_type minCoeff() const + concrete_type _minCoeff() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.minCoeff(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); return res; } - concrete_type squaredNorm() const + concrete_type _squaredNorm() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); return res; } - concrete_type norm() const + concrete_type _norm() const { - concrete_type res(1, target_.cols()); - apply([&](auto r, auto i) { res(i) = r.norm(); }); + concrete_type res(1, cols(target_)); + apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); return res; } private: template void apply(Func f) { - for (Index i = 0; i < target_.cols(); ++i) f(col(target_, i), i); + for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } } template void apply(Func f) const { - for (Index i = 0; i < target_.cols(); ++i) f(col(target_, i), i); + for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } } }; template auto rowwise(T&& t) { - if constexpr (use_expression_templates) return t.base().rowwise(); - else return rowwise_adaptor{t}; + if constexpr (use_expression_templates) { return t.base().rowwise(); } + else + { + return rowwise_adaptor{t}; + } } template auto colwise(T&& t) { - if constexpr (use_expression_templates) return t.base().colwise(); - else return colwise_adaptor{t}; + if constexpr (use_expression_templates) { return t.base().colwise(); } + else + { + return colwise_adaptor{t}; + } } } diff --git a/src/block/model.cpp b/src/block/model.cpp index 4c8ac4e..983602b 100644 --- a/src/block/model.cpp +++ b/src/block/model.cpp @@ -1,20 +1,20 @@ -//================================================================================================== +//============================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//================================================================================================== +//============================================================================== -//================================================================================================== +//============================================================================== /* This file is a X-File to generate various block_impl_* definitions variant */ -//================================================================================================== +//============================================================================== -//================================================================================================== +//============================================================================== // Constructors & Special Members -//================================================================================================== +//============================================================================== CLASSNAME::CLASSNAME( SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj) : storage_( @@ -134,22 +134,9 @@ void CLASSNAME::assign(SOURCENAME const& m) } #endif -//================================================================================================== +//============================================================================== // Matrix API -//================================================================================================== -rotgen::Index CLASSNAME::rows() const -{ - rotgen::Index that; - storage_->apply([&](auto const& blk) { that = blk.rows(); }); - return that; -} - -rotgen::Index CLASSNAME::cols() const -{ - rotgen::Index that; - storage_->apply([&](auto const& blk) { that = blk.cols(); }); - return that; -} +//============================================================================== rotgen::Index CLASSNAME::size() const { @@ -158,26 +145,40 @@ rotgen::Index CLASSNAME::size() const return that; } -rotgen::Index CLASSNAME::innerStride() const +rotgen::Index CLASSNAME::_rows() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.rows(); }); + return that; +} + +rotgen::Index CLASSNAME::_cols() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.cols(); }); + return that; +} + +rotgen::Index CLASSNAME::_innerStride() const { rotgen::Index that; storage_->apply([&](auto const& blk) { that = blk.innerStride(); }); return that; } -rotgen::Index CLASSNAME::outerStride() const +rotgen::Index CLASSNAME::_outerStride() const { rotgen::Index that; storage_->apply([&](auto const& blk) { that = blk.outerStride(); }); return that; } -rotgen::Index CLASSNAME::startRow() const +rotgen::Index CLASSNAME::_startRow() const { return storage_->rel_i0; } -rotgen::Index CLASSNAME::startCol() const +rotgen::Index CLASSNAME::_startCol() const { return storage_->rel_j0; } @@ -203,16 +204,16 @@ TYPE CLASSNAME::operator()(Index i, Index j) const #if !defined(USE_CONST) TYPE& CLASSNAME::operator()(Index index) { - auto r = rows() == 1 ? 0 : index; - auto c = cols() == 1 ? 0 : index; + auto r = _rows() == 1 ? 0 : index; + auto c = _cols() == 1 ? 0 : index; return (*this)(r, c); } #endif TYPE CLASSNAME::operator()(Index index) const { - auto r = rows() == 1 ? 0 : index; - auto c = cols() == 1 ? 0 : index; + auto r = _rows() == 1 ? 0 : index; + auto c = _cols() == 1 ? 0 : index; return (*this)(r, c); } @@ -233,10 +234,10 @@ TYPE const* CLASSNAME::data() const return ptr; } -//================================================================================================== +//============================================================================== // Matrix operations -//================================================================================================== -SOURCENAME CLASSNAME::normalized() const +//============================================================================== +SOURCENAME CLASSNAME::_normalized() const { SOURCENAME result; storage_->apply([&](auto const& blk) { @@ -245,7 +246,7 @@ SOURCENAME CLASSNAME::normalized() const return result; } -SOURCENAME CLASSNAME::transpose() const +SOURCENAME CLASSNAME::_transpose() const { SOURCENAME result; storage_->apply( @@ -253,7 +254,7 @@ SOURCENAME CLASSNAME::transpose() const return result; } -SOURCENAME CLASSNAME::conjugate() const +SOURCENAME CLASSNAME::_conjugate() const { SOURCENAME result; storage_->apply( @@ -261,7 +262,7 @@ SOURCENAME CLASSNAME::conjugate() const return result; } -SOURCENAME CLASSNAME::adjoint() const +SOURCENAME CLASSNAME::_adjoint() const { SOURCENAME result; storage_->apply( @@ -269,7 +270,7 @@ SOURCENAME CLASSNAME::adjoint() const return result; } -SOURCENAME CLASSNAME::cwiseAbs() const +SOURCENAME CLASSNAME::_cwiseAbs() const { SOURCENAME result; storage_->apply( @@ -277,7 +278,7 @@ SOURCENAME CLASSNAME::cwiseAbs() const return result; } -SOURCENAME CLASSNAME::cwiseAbs2() const +SOURCENAME CLASSNAME::_cwiseAbs2() const { SOURCENAME result; storage_->apply( @@ -285,7 +286,7 @@ SOURCENAME CLASSNAME::cwiseAbs2() const return result; } -SOURCENAME CLASSNAME::cwiseInverse() const +SOURCENAME CLASSNAME::_cwiseInverse() const { SOURCENAME result; storage_->apply([&](auto const& blk) { @@ -294,7 +295,7 @@ SOURCENAME CLASSNAME::cwiseInverse() const return result; } -SOURCENAME CLASSNAME::cwiseSqrt() const +SOURCENAME CLASSNAME::_cwiseSqrt() const { SOURCENAME result; storage_->apply( @@ -303,96 +304,96 @@ SOURCENAME CLASSNAME::cwiseSqrt() const } #if !defined(USE_CONST) -void CLASSNAME::normalize() +void CLASSNAME::_normalize() { storage_->apply([](auto& blk) { blk.normalize(); }); } -void CLASSNAME::transposeInPlace() +void CLASSNAME::_transposeInPlace() { storage_->apply([](auto& blk) { blk.transposeInPlace(); }); } -void CLASSNAME::adjointInPlace() +void CLASSNAME::_adjointInPlace() { storage_->apply([](auto& blk) { blk.adjointInPlace(); }); } #endif -//================================================================================================== +//============================================================================== // Reductions -//================================================================================================== -TYPE CLASSNAME::sum() const +//============================================================================== +TYPE CLASSNAME::_sum() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.sum(); }); return val; } -TYPE CLASSNAME::prod() const +TYPE CLASSNAME::_prod() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.prod(); }); return val; } -TYPE CLASSNAME::mean() const +TYPE CLASSNAME::_mean() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.mean(); }); return val; } -TYPE CLASSNAME::trace() const +TYPE CLASSNAME::_trace() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.trace(); }); return val; } -TYPE CLASSNAME::minCoeff() const +TYPE CLASSNAME::_minCoeff() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.minCoeff(); }); return val; } -TYPE CLASSNAME::maxCoeff() const +TYPE CLASSNAME::_maxCoeff() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.maxCoeff(); }); return val; } -TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.minCoeff(row, col); }); return val; } -TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.maxCoeff(row, col); }); return val; } -TYPE CLASSNAME::squaredNorm() const +TYPE CLASSNAME::_squaredNorm() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.squaredNorm(); }); return val; } -TYPE CLASSNAME::norm() const +TYPE CLASSNAME::_norm() const { TYPE val{}; storage_->apply([&](auto const& blk) { val = blk.norm(); }); return val; } -TYPE CLASSNAME::lpNorm(int p) const +TYPE CLASSNAME::_lpNorm(int p) const { TYPE val{}; storage_->apply([&](auto const& blk) { @@ -403,9 +404,9 @@ TYPE CLASSNAME::lpNorm(int p) const return val; } -//================================================================================================== +//============================================================================== // Operators -//================================================================================================== +//============================================================================== ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) { m.storage_->apply([&](auto const& blk) { os << blk; }); @@ -549,7 +550,7 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s) } #endif -SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_add(CLASSNAME const& rhs) const { SOURCENAME result; std::visit( @@ -560,7 +561,7 @@ SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const return result; } -SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_sub(CLASSNAME const& rhs) const { SOURCENAME result; std::visit( @@ -571,7 +572,7 @@ SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const return result; } -SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_mul(CLASSNAME const& rhs) const { SOURCENAME result; std::visit( @@ -582,7 +583,7 @@ SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const return result; } -SOURCENAME CLASSNAME::mul(TYPE s) const +SOURCENAME CLASSNAME::_mul(TYPE s) const { SOURCENAME result; std::visit( @@ -593,7 +594,7 @@ SOURCENAME CLASSNAME::mul(TYPE s) const return result; } -SOURCENAME CLASSNAME::div(TYPE s) const +SOURCENAME CLASSNAME::_div(TYPE s) const { SOURCENAME result; std::visit( diff --git a/src/map/model.cpp b/src/map/model.cpp index cc31a69..0983011 100644 --- a/src/map/model.cpp +++ b/src/map/model.cpp @@ -58,12 +58,12 @@ CLASSNAME::~CLASSNAME() = default; //================================================================================================== // Matrix API //================================================================================================== -rotgen::Index CLASSNAME::rows() const +rotgen::Index CLASSNAME::_rows() const { return storage_->data.rows(); } -rotgen::Index CLASSNAME::cols() const +rotgen::Index CLASSNAME::_cols() const { return storage_->data.cols(); } @@ -73,12 +73,12 @@ rotgen::Index CLASSNAME::size() const return storage_->data.size(); } -rotgen::Index CLASSNAME::innerStride() const +rotgen::Index CLASSNAME::_innerStride() const { return storage_->data.innerStride(); } -rotgen::Index CLASSNAME::outerStride() const +rotgen::Index CLASSNAME::_outerStride() const { return storage_->data.outerStride(); } @@ -115,77 +115,77 @@ TYPE CLASSNAME::operator()(Index i) const return storage_->data.data()[i]; } -SOURCENAME CLASSNAME::normalized() const +SOURCENAME CLASSNAME::_normalized() const { SOURCENAME result; result.storage()->assign(storage_->data.normalized().eval()); return result; } -SOURCENAME CLASSNAME::transpose() const +SOURCENAME CLASSNAME::_transpose() const { SOURCENAME result; result.storage()->assign(storage_->data.transpose().eval()); return result; } -SOURCENAME CLASSNAME::conjugate() const +SOURCENAME CLASSNAME::_conjugate() const { SOURCENAME result; result.storage()->assign(storage_->data.conjugate().eval()); return result; } -SOURCENAME CLASSNAME::adjoint() const +SOURCENAME CLASSNAME::_adjoint() const { SOURCENAME result; result.storage()->assign(storage_->data.adjoint().eval()); return result; } -SOURCENAME CLASSNAME::cwiseAbs() const +SOURCENAME CLASSNAME::_cwiseAbs() const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseAbs().eval()); return result; } -SOURCENAME CLASSNAME::cwiseAbs2() const +SOURCENAME CLASSNAME::_cwiseAbs2() const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseAbs2().eval()); return result; } -SOURCENAME CLASSNAME::cwiseInverse() const +SOURCENAME CLASSNAME::_cwiseInverse() const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseInverse().eval()); return result; } -SOURCENAME CLASSNAME::cwiseSqrt() const +SOURCENAME CLASSNAME::_cwiseSqrt() const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseSqrt().eval()); return result; } -SOURCENAME CLASSNAME::cwiseMin(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_cwiseMin(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseMin(rhs.storage()->data).eval()); return result; } -SOURCENAME CLASSNAME::cwiseMax(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_cwiseMax(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseMax(rhs.storage()->data).eval()); return result; } -SOURCENAME CLASSNAME::cwiseProduct(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_cwiseProduct(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign( @@ -193,7 +193,7 @@ SOURCENAME CLASSNAME::cwiseProduct(CLASSNAME const& rhs) const return result; } -SOURCENAME CLASSNAME::cwiseQuotient(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_cwiseQuotient(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign( @@ -201,21 +201,21 @@ SOURCENAME CLASSNAME::cwiseQuotient(CLASSNAME const& rhs) const return result; } -SOURCENAME CLASSNAME::cwiseMin(TYPE rhs) const +SOURCENAME CLASSNAME::_cwiseMin(TYPE rhs) const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseMin(rhs).eval()); return result; } -SOURCENAME CLASSNAME::cwiseMax(TYPE rhs) const +SOURCENAME CLASSNAME::_cwiseMax(TYPE rhs) const { SOURCENAME result; result.storage()->assign(storage_->data.cwiseMax(rhs).eval()); return result; } -SOURCENAME CLASSNAME::inverse() const +SOURCENAME CLASSNAME::_inverse() const { SOURCENAME result; result.storage()->assign(storage_->data.inverse().eval()); @@ -223,93 +223,93 @@ SOURCENAME CLASSNAME::inverse() const } #if !defined(USE_CONST) -void CLASSNAME::normalize() +void CLASSNAME::_normalize() { storage_->data.normalize(); } -void CLASSNAME::transposeInPlace() +void CLASSNAME::_transposeInPlace() { storage_->data.transposeInPlace(); } -void CLASSNAME::adjointInPlace() +void CLASSNAME::_adjointInPlace() { storage_->data.adjointInPlace(); } #endif -TYPE CLASSNAME::dot(CLASSNONCONSTNAME const& rhs) const +TYPE CLASSNAME::_dot(CLASSNONCONSTNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::dot(CLASSCONSTNAME const& rhs) const +TYPE CLASSNAME::_dot(CLASSCONSTNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::dot(TRANSCLASSNONCONSTNAME const& rhs) const +TYPE CLASSNAME::_dot(TRANSCLASSNONCONSTNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::dot(TRANSCLASSCONSTNAME const& rhs) const +TYPE CLASSNAME::_dot(TRANSCLASSCONSTNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::sum() const +TYPE CLASSNAME::_sum() const { return storage_->data.sum(); } -TYPE CLASSNAME::prod() const +TYPE CLASSNAME::_prod() const { return storage_->data.prod(); } -TYPE CLASSNAME::mean() const +TYPE CLASSNAME::_mean() const { return storage_->data.mean(); } -TYPE CLASSNAME::trace() const +TYPE CLASSNAME::_trace() const { return storage_->data.trace(); } -TYPE CLASSNAME::minCoeff() const +TYPE CLASSNAME::_minCoeff() const { return storage_->data.minCoeff(); } -TYPE CLASSNAME::maxCoeff() const +TYPE CLASSNAME::_maxCoeff() const { return storage_->data.maxCoeff(); } -TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const { return storage_->data.minCoeff(row, col); } -TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const { return storage_->data.maxCoeff(row, col); } -TYPE CLASSNAME::squaredNorm() const +TYPE CLASSNAME::_squaredNorm() const { return storage_->data.squaredNorm(); } -TYPE CLASSNAME::norm() const +TYPE CLASSNAME::_norm() const { return storage_->data.norm(); } -TYPE CLASSNAME::lpNorm(int p) const +TYPE CLASSNAME::_lpNorm(int p) const { if (p == 1) return storage_->data.lpNorm<1>(); else if (p == 2) return storage_->data.lpNorm<2>(); @@ -317,27 +317,27 @@ TYPE CLASSNAME::lpNorm(int p) const } #if !defined(USE_CONST) -void CLASSNAME::setZero() +void CLASSNAME::_setZero() { storage_->data.setZero(); } -void CLASSNAME::setOnes() +void CLASSNAME::_setOnes() { storage_->data.setOnes(); } -void CLASSNAME::setIdentity() +void CLASSNAME::_setIdentity() { storage_->data.setIdentity(); } -void CLASSNAME::setRandom() +void CLASSNAME::_setRandom() { storage_->data.setRandom(); } -void CLASSNAME::setConstant(TYPE s) +void CLASSNAME::_setConstant(TYPE s) { storage_->data.setConstant(s); } @@ -471,56 +471,56 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s) } #endif -SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_add(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data + rhs.storage_->data); return result; } -SOURCENAME CLASSNAME::add(TRANSCLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_add(TRANSCLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data + rhs.storage()->data); return result; } -SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_sub(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data - rhs.storage_->data); return result; } -SOURCENAME CLASSNAME::sub(TRANSCLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_sub(TRANSCLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data - rhs.storage()->data); return result; } -SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_mul(CLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data * rhs.storage_->data); return result; } -SOURCENAME CLASSNAME::mul(TRANSCLASSNAME const& rhs) const +SOURCENAME CLASSNAME::_mul(TRANSCLASSNAME const& rhs) const { SOURCENAME result; result.storage()->assign(storage_->data * rhs.storage()->data); return result; } -SOURCENAME CLASSNAME::mul(TYPE s) const +SOURCENAME CLASSNAME::_mul(TYPE s) const { SOURCENAME result; result.storage()->assign(storage_->data * s); return result; } -SOURCENAME CLASSNAME::div(TYPE s) const +SOURCENAME CLASSNAME::_div(TYPE s) const { SOURCENAME result; result.storage()->assign(storage_->data / s); diff --git a/src/matrix/model.cpp b/src/matrix/model.cpp index 937e6d9..98d2230 100644 --- a/src/matrix/model.cpp +++ b/src/matrix/model.cpp @@ -34,7 +34,7 @@ CLASSNAME::CLASSNAME(Index r, Index c, std::initializer_list init) for (std::size_t i = 0; i < init.size(); i++) (*this)(i) = first[i]; } -CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o.rows(), o.cols()) +CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o._rows(), o._cols()) { storage_->data = o.storage_->data; } @@ -54,27 +54,27 @@ CLASSNAME::~CLASSNAME() = default; //================================================================================================== // Matrix API //================================================================================================== -rotgen::Index CLASSNAME::rows() const +rotgen::Index CLASSNAME::size() const +{ + return storage_->data.size(); +} + +rotgen::Index CLASSNAME::_rows() const { return storage_->data.rows(); } -rotgen::Index CLASSNAME::cols() const +rotgen::Index CLASSNAME::_cols() const { return storage_->data.cols(); } -rotgen::Index CLASSNAME::size() const -{ - return storage_->data.size(); -} - void CLASSNAME::resize(Index new_rows, Index new_cols) { storage_->data.resize(new_rows, new_cols); } -void CLASSNAME::conservativeResize(Index new_rows, Index new_cols) +void CLASSNAME::_conservativeResize(Index new_rows, Index new_cols) { storage_->data.conservativeResize(new_rows, new_cols); } @@ -109,128 +109,128 @@ TYPE* CLASSNAME::data() return storage_->data.data(); } -CLASSNAME CLASSNAME::normalized() const +CLASSNAME CLASSNAME::_normalized() const { CLASSNAME result(*this); result.storage_->data.normalize(); return result; } -CLASSNAME CLASSNAME::transpose() const +CLASSNAME CLASSNAME::_transpose() const { CLASSNAME result; result.storage()->data = storage_->data.transpose(); return result; } -CLASSNAME CLASSNAME::conjugate() const +CLASSNAME CLASSNAME::_conjugate() const { CLASSNAME result(*this); result.storage_->data = storage_->data.conjugate(); return result; } -CLASSNAME CLASSNAME::adjoint() const +CLASSNAME CLASSNAME::_adjoint() const { CLASSNAME result; result.storage()->data = storage_->data.adjoint(); return result; } -void CLASSNAME::normalize() +void CLASSNAME::_normalize() { storage_->data.normalize(); } -void CLASSNAME::transposeInPlace() +void CLASSNAME::_transposeInPlace() { storage_->data.transposeInPlace(); } -void CLASSNAME::adjointInPlace() +void CLASSNAME::_adjointInPlace() { storage_->data.adjointInPlace(); } -CLASSNAME CLASSNAME::cwiseAbs() const +CLASSNAME CLASSNAME::_cwiseAbs() const { CLASSNAME result(*this); result.storage_->data = storage_->data.cwiseAbs(); return result; } -CLASSNAME CLASSNAME::cwiseAbs2() const +CLASSNAME CLASSNAME::_cwiseAbs2() const { CLASSNAME result(*this); result.storage_->data = storage_->data.cwiseAbs2(); return result; } -CLASSNAME CLASSNAME::cwiseInverse() const +CLASSNAME CLASSNAME::_cwiseInverse() const { CLASSNAME result(*this); result.storage_->data = storage_->data.cwiseInverse(); return result; } -CLASSNAME CLASSNAME::cwiseSqrt() const +CLASSNAME CLASSNAME::_cwiseSqrt() const { CLASSNAME result(*this); result.storage_->data = storage_->data.cwiseSqrt(); return result; } -TYPE CLASSNAME::sum() const +TYPE CLASSNAME::_sum() const { return storage_->data.sum(); } -TYPE CLASSNAME::prod() const +TYPE CLASSNAME::_prod() const { return storage_->data.prod(); } -TYPE CLASSNAME::mean() const +TYPE CLASSNAME::_mean() const { return storage_->data.mean(); } -TYPE CLASSNAME::trace() const +TYPE CLASSNAME::_trace() const { return storage_->data.trace(); } -TYPE CLASSNAME::minCoeff() const +TYPE CLASSNAME::_minCoeff() const { return storage_->data.minCoeff(); } -TYPE CLASSNAME::maxCoeff() const +TYPE CLASSNAME::_maxCoeff() const { return storage_->data.maxCoeff(); } -TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_minCoeff(Index* row, Index* col) const { return storage_->data.minCoeff(row, col); } -TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +TYPE CLASSNAME::_maxCoeff(Index* row, Index* col) const { return storage_->data.maxCoeff(row, col); } -TYPE CLASSNAME::squaredNorm() const +TYPE CLASSNAME::_squaredNorm() const { return storage_->data.squaredNorm(); } -TYPE CLASSNAME::norm() const +TYPE CLASSNAME::_norm() const { return storage_->data.norm(); } -TYPE CLASSNAME::lp_norm(int p) const +TYPE CLASSNAME::_lp_norm(int p) const { if (p == 1) return storage_->data.lpNorm<1>(); else if (p == 2) return storage_->data.lpNorm<2>(); @@ -301,27 +301,27 @@ CLASSNAME& CLASSNAME::operator/=(TYPE s) //============================================================================== // Generators functions //============================================================================== -void CLASSNAME::setOnes(Index rows, Index cols) +void CLASSNAME::_setOnes(Index rows, Index cols) { storage_->assign(payload::data_type::Ones(rows, cols).eval()); } -void CLASSNAME::setZero(Index rows, Index cols) +void CLASSNAME::_setZero(Index rows, Index cols) { storage_->assign(payload::data_type::Zero(rows, cols).eval()); } -void CLASSNAME::setConstant(Index rows, Index cols, TYPE value) +void CLASSNAME::_setConstant(Index rows, Index cols, TYPE value) { storage_->assign(payload::data_type::Constant(rows, cols, value).eval()); } -void CLASSNAME::setRandom(Index rows, Index cols) +void CLASSNAME::_setRandom(Index rows, Index cols) { storage_->assign(payload::data_type::Random(rows, cols).eval()); } -void CLASSNAME::setIdentity(Index rows, Index cols) +void CLASSNAME::_setIdentity(Index rows, Index cols) { storage_->assign(payload::data_type::Identity(rows, cols).eval()); } @@ -329,21 +329,21 @@ void CLASSNAME::setIdentity(Index rows, Index cols) //============================================================================== // Static functions //============================================================================== -CLASSNAME CLASSNAME::Ones(Index rows, Index cols) +CLASSNAME CLASSNAME::_Ones(Index rows, Index cols) { CLASSNAME m; m.storage_ = std::make_unique(payload::data_type::Ones(rows, cols)); return m; } -CLASSNAME CLASSNAME::Zero(Index rows, Index cols) +CLASSNAME CLASSNAME::_Zero(Index rows, Index cols) { CLASSNAME m; m.storage_ = std::make_unique(payload::data_type::Zero(rows, cols)); return m; } -CLASSNAME CLASSNAME::Constant(Index rows, Index cols, TYPE value) +CLASSNAME CLASSNAME::_Constant(Index rows, Index cols, TYPE value) { CLASSNAME m; m.storage_ = @@ -351,7 +351,7 @@ CLASSNAME CLASSNAME::Constant(Index rows, Index cols, TYPE value) return m; } -CLASSNAME CLASSNAME::Random(Index rows, Index cols) +CLASSNAME CLASSNAME::_Random(Index rows, Index cols) { CLASSNAME m; m.storage_ = @@ -359,7 +359,7 @@ CLASSNAME CLASSNAME::Random(Index rows, Index cols) return m; } -CLASSNAME CLASSNAME::Identity(Index rows, Index cols) +CLASSNAME CLASSNAME::_Identity(Index rows, Index cols) { CLASSNAME m; m.storage_ = diff --git a/test/integration/extract.cpp b/test/integration/extract.cpp index 0884374..5f13def 100644 --- a/test/integration/extract.cpp +++ b/test/integration/extract.cpp @@ -14,34 +14,34 @@ TTS_CASE_TPL("Chains of extraction", rotgen::tests::types) (tts::type>) { constexpr int N = 8; - auto a = rotgen::matrix::Random(); + auto a = rotgen::setRandom>(); auto b = topLeftCorner(a, 5, 5); - TTS_EQUAL(b.startRow(), 0); - TTS_EQUAL(b.startCol(), 0); + TTS_EQUAL(startRow(b), 0); + TTS_EQUAL(startCol(b), 0); setConstant(b, -7); for (rotgen::Index r = 0; r < 5; r++) for (rotgen::Index c = 0; c < 5; c++) TTS_EQUAL(a(r, c), -7); auto bb = bottomRightCorner(b, 3, 3); - TTS_EQUAL(bb.startRow(), 2); - TTS_EQUAL(bb.startCol(), 2); + TTS_EQUAL(startRow(bb), 2); + TTS_EQUAL(startCol(bb), 2); setConstant(bb, 42); for (rotgen::Index r = 2; r < 5; r++) for (rotgen::Index c = 2; c < 5; c++) TTS_EQUAL(a(r, c), 42); auto bbb = row(bb, 1); - TTS_EQUAL(bbb.startRow(), 1); - TTS_EQUAL(bbb.startCol(), 0); + TTS_EQUAL(startRow(bbb), 1); + TTS_EQUAL(startCol(bbb), 0); setConstant(bbb, 99.5); for (rotgen::Index c = 3; c < 5; c++) TTS_EQUAL(a(3, c), 99.5); auto bbbb = col(bbb, 1); - TTS_EQUAL(bbbb.startRow(), 0); - TTS_EQUAL(bbbb.startCol(), 1); + TTS_EQUAL(startRow(bbbb), 0); + TTS_EQUAL(startCol(bbbb), 1); setConstant(bbbb, 0.125); TTS_EQUAL(a(3, 3), 0.125); @@ -94,7 +94,7 @@ TTS_CASE("Compound operators on extractions") setConstant(n, 10); setConstant(reference, 10); - for (int i = 0; i < m.cols(); i++) process_col(m, n, i); + for (int i = 0; i < cols(m); i++) process_col(m, n, i); TTS_EQUAL(m, reference); }; diff --git a/test/integration/outer_stride.cpp b/test/integration/outer_stride.cpp index 67938c7..6a6a42f 100644 --- a/test/integration/outer_stride.cpp +++ b/test/integration/outer_stride.cpp @@ -10,29 +10,29 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("outer_stride<0> interactions", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("outer_stride<0> interactions", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; T contiguous[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; rotgen::map> m(&contiguous[0], 4, 3); - TTS_EQUAL(m.innerStride(), 1); - TTS_EQUAL(m.outerStride(), O::value == rotgen::ColMajor ? 4 : 3); + TTS_EQUAL(innerStride(m), 1); + TTS_EQUAL(outerStride(m), O::value == rotgen::ColMajor ? 4 : 3); if constexpr (O::value == rotgen::ColMajor) { T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); - TTS_EQUAL(sp.innerStride(), 1); - TTS_EQUAL(sp.outerStride(), 5); + TTS_EQUAL(innerStride(sp), 1); + TTS_EQUAL(outerStride(sp), 5); rotgen::map> dp(&padded[0], 4, 3, rotgen::outer_stride(5)); - TTS_EQUAL(dp.innerStride(), 1); - TTS_EQUAL(dp.outerStride(), 5); + TTS_EQUAL(innerStride(dp), 1); + TTS_EQUAL(outerStride(dp), 5); TTS_EQUAL(m, sp); TTS_EQUAL(m, dp); @@ -42,13 +42,13 @@ TTS_CASE_TPL("outer_stride<0> interactions", { T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); - TTS_EQUAL(sp.innerStride(), 1); - TTS_EQUAL(sp.outerStride(), 4); + TTS_EQUAL(innerStride(sp), 1); + TTS_EQUAL(outerStride(sp), 4); rotgen::map> dp(&padded[0], 4, 3, rotgen::outer_stride(4)); - TTS_EQUAL(dp.innerStride(), 1); - TTS_EQUAL(dp.outerStride(), 4); + TTS_EQUAL(innerStride(dp), 1); + TTS_EQUAL(outerStride(dp), 4); TTS_EQUAL(m, sp); TTS_EQUAL(m, dp); diff --git a/test/integration/ref_magic.cpp b/test/integration/ref_magic.cpp index ca463d1..9b9a9ab 100644 --- a/test/integration/ref_magic.cpp +++ b/test/integration/ref_magic.cpp @@ -48,9 +48,9 @@ auto process(column_ref<> v) TTS_CASE("Reference of reference check") { - auto v1 = rotgen::matrix::Ones(); - auto v2 = rotgen::matrix::Random(); - auto v3 = rotgen::matrix::Constant(6.66); + auto v1 = rotgen::setOnes>(); + auto v2 = rotgen::setRandom>(); + auto v3 = rotgen::setConstant>(6.66); auto sum1 = v1(0); auto sum2 = v2(0) + v2(1); diff --git a/test/unit/block/basic_api.cpp b/test/unit/block/basic_api.cpp index c74515c..6f608e0 100644 --- a/test/unit/block/basic_api.cpp +++ b/test/unit/block/basic_api.cpp @@ -18,8 +18,9 @@ void fill(auto& m, int r, int c, auto data[]) for (int k = 0; k < r * c; ++k) m.data()[k] = data[k]; } -TTS_CASE_TPL("Function size", rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Function size", rotgen::tests::types) + +(tts::type>) { T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; @@ -28,44 +29,44 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)( fill(dm, 1, 12, data); auto b1 = rotgen::block( dm, 0, 0, 1, 12); - TTS_EQUAL(b1.rows(), rotgen::Index{1}); - TTS_EQUAL(b1.cols(), rotgen::Index{12}); + TTS_EQUAL(rows(b1), rotgen::Index{1}); + TTS_EQUAL(cols(b1), rotgen::Index{12}); // 1x5 dynamic block at (0,2) auto b2 = rotgen::block( dm, 0, 2, 1, 5); - TTS_EQUAL(b2.rows(), rotgen::Index{1}); - TTS_EQUAL(b2.cols(), rotgen::Index{5}); + TTS_EQUAL(rows(b2), rotgen::Index{1}); + TTS_EQUAL(cols(b2), rotgen::Index{5}); // 3x2 dynamic block at (1,4) in 4x6 rotgen::matrix dm2(4, 6); fill(dm2, 4, 6, data); auto b3 = rotgen::block( dm2, 1, 4, 3, 2); - TTS_EQUAL(b3.rows(), rotgen::Index{3}); - TTS_EQUAL(b3.cols(), rotgen::Index{2}); + TTS_EQUAL(rows(b3), rotgen::Index{3}); + TTS_EQUAL(cols(b3), rotgen::Index{2}); TTS_EQUAL(b3.size(), rotgen::Index{6}); // 3x4 static block rotgen::matrix sm; fill(sm, 3, 4, data); auto b4 = rotgen::block(sm, 0, 0); - TTS_EQUAL(b4.rows(), rotgen::Index{3}); - TTS_EQUAL(b4.cols(), rotgen::Index{4}); + TTS_EQUAL(rows(b4), rotgen::Index{3}); + TTS_EQUAL(cols(b4), rotgen::Index{4}); TTS_EQUAL(b4.size(), rotgen::Index{12}); // 6x2 static block rotgen::matrix sm2; fill(sm2, 6, 2, data); auto b5 = rotgen::block(sm2, 0, 0); - TTS_EQUAL(b5.rows(), rotgen::Index{6}); - TTS_EQUAL(b5.cols(), rotgen::Index{2}); + TTS_EQUAL(rows(b5), rotgen::Index{6}); + TTS_EQUAL(cols(b5), rotgen::Index{2}); TTS_EQUAL(b5.size(), rotgen::Index{12}); }; -TTS_CASE_TPL("Test coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) + +(tts::type>) { using base = rotgen::matrix; @@ -92,9 +93,9 @@ TTS_CASE_TPL("Test coefficient accessors", TTS_EQUAL(b(2, 2), 17); }; -TTS_CASE_TPL("Test one index coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) + +(tts::type>) { auto vs = [&]() { if constexpr (O::value == rotgen::ColMajor) diff --git a/test/unit/block/extract.cpp b/test/unit/block/extract.cpp index 236aa01..5609df4 100644 --- a/test/unit/block/extract.cpp +++ b/test/unit/block/extract.cpp @@ -13,15 +13,15 @@ template void for_each_element(EigenType const& m, F&& f) { - for (rotgen::Index i = 0; i < m.rows(); ++i) - for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j)); + for (rotgen::Index i = 0; i < rows(m); ++i) + for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); } template void for_each_element(EigenType& m, F&& f) { - for (rotgen::Index i = 0; i < m.rows(); ++i) - for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j)); + for (rotgen::Index i = 0; i < rows(m); ++i) + for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); } template @@ -53,8 +53,8 @@ void validate_block_behavior(MatrixType& matrix, rotgen::Index block_n) { using T = typename MatrixType::value_type; - TTS_EQUAL(block.rows(), block_m); - TTS_EQUAL(block.cols(), block_n); + TTS_EQUAL(rows(block), block_m); + TTS_EQUAL(cols(block), block_n); TTS_EQUAL(block.size(), block_m * block_n); // test block values @@ -144,31 +144,31 @@ void test_dynamic_block_extraction( std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(c_block_top_right_corner, 0, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(c_block_bottom_left_corner, - matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(c_block_bottom_right_corner, - matrix.rows() - matrix_construct.ni, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), - std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), + std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, - matrix_construct.ni, matrix.cols(), rotgen::Dynamic, + matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix.cols(), rotgen::Dynamic, + std::make_tuple(c_block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, + matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, + std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(), + std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, + std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, + rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), // --- REGULAR TESTS @@ -178,31 +178,31 @@ void test_dynamic_block_extraction( std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(block_top_right_corner, 0, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(block_bottom_left_corner, - matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(block_bottom_right_corner, - matrix.rows() - matrix_construct.ni, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), - std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), + std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), std::make_tuple(block_middle_rows, matrix_construct.i0, 0, - matrix_construct.ni, matrix.cols(), rotgen::Dynamic, + matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix.cols(), rotgen::Dynamic, + std::make_tuple(block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, + matrix_construct.ni, cols(matrix), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, + std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(), + std::make_tuple(block_middle_cols, 0, matrix_construct.j0, rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, + std::make_tuple(block_right_cols, 0, cols(matrix) - matrix_construct.nj, + rows(matrix), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic)); std::apply( @@ -276,68 +276,68 @@ void test_static_block_extraction( std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(c_block_top_right_corner, 0, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(c_block_bottom_left_corner, - matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(c_block_bottom_right_corner, - matrix.rows() - matrix_construct.ni, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), + std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), int(NI), rotgen::Dynamic), std::make_tuple(c_block_middle_rows, i0, 0, matrix_construct.ni, - matrix.cols(), int(NI), rotgen::Dynamic), - std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix.cols(), int(NI), + cols(matrix), int(NI), rotgen::Dynamic), + std::make_tuple(c_block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, + matrix_construct.ni, cols(matrix), int(NI), rotgen::Dynamic), - std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, + std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_middle_cols, 0, j0, matrix.rows(), + std::make_tuple(c_block_middle_cols, 0, j0, rows(matrix), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, + std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, + rows(matrix), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic), - std::make_tuple(c_block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1), + std::make_tuple(c_block_row, i0, 0, 1, cols(matrix), 1, rotgen::Dynamic), + std::make_tuple(c_block_col, 0, j0, rows(matrix), 1, rotgen::Dynamic, 1), // -- Block to NON CONST std::make_tuple(block_main, i0, j0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_top_right_corner, 0, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_bottom_left_corner, - matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_bottom_right_corner, - matrix.rows() - matrix_construct.ni, - matrix.cols() - matrix_construct.nj, matrix_construct.ni, + rows(matrix) - matrix_construct.ni, + cols(matrix) - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), + std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), int(NI), rotgen::Dynamic), - std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni, - matrix.cols(), int(NI), rotgen::Dynamic), - std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix.cols(), int(NI), + std::make_tuple(block_middle_rows, i0, 0, matrix_construct.ni, cols(matrix), + int(NI), rotgen::Dynamic), + std::make_tuple(block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, + matrix_construct.ni, cols(matrix), int(NI), rotgen::Dynamic), - std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, + std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(block_middle_cols, 0, j0, matrix.rows(), - matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, + std::make_tuple(block_middle_cols, 0, j0, rows(matrix), matrix_construct.nj, + rotgen::Dynamic, int(NJ)), + std::make_tuple(block_right_cols, 0, cols(matrix) - matrix_construct.nj, + rows(matrix), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic), - std::make_tuple(block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1)); + std::make_tuple(block_row, i0, 0, 1, cols(matrix), 1, rotgen::Dynamic), + std::make_tuple(block_col, 0, j0, rows(matrix), 1, rotgen::Dynamic, 1)); std::apply( [&](auto&&... block_entries) { @@ -358,7 +358,9 @@ void test_static_block_extraction( TTS_CASE_TPL( "Check all dynamic block extractions on a dynamic row-major matrix", - rotgen::tests::types)(tts::type>) + rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; @@ -394,7 +396,9 @@ TTS_CASE_TPL( TTS_CASE_TPL( "Check all dynamic block extractions on a static column-major matrix", - rotgen::tests::types)(tts::type>) + rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; @@ -417,9 +421,9 @@ TTS_CASE_TPL( } }; -TTS_CASE_TPL("Check all static block extractions", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; @@ -446,9 +450,9 @@ TTS_CASE_TPL("Check all static block extractions", 0}); }; -TTS_CASE_TPL("Check vector-only extractions", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check vector-only extractions", rotgen::tests::types) + +(tts::type>) { auto run_case = [](auto&& matrix, auto&& block, int i_offset, int j_offset, int ni, int nj, auto const& rows_ct, auto const& cols_ct) { diff --git a/test/unit/block/generators.cpp b/test/unit/block/generators.cpp index e6f8fc3..0b44b42 100644 --- a/test/unit/block/generators.cpp +++ b/test/unit/block/generators.cpp @@ -48,9 +48,9 @@ void test_random(auto const& matrix, } } -TTS_CASE_TPL("Test dynamic block::setZero", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic block::setZero", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) @@ -64,14 +64,14 @@ TTS_CASE_TPL("Test dynamic block::setZero", test_value(m, T{0}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Zero(ni, nj); + auto values = rotgen::setZero(ni, nj); test_value(values, T{0}, 0, 0, ni, nj); } }; -TTS_CASE_TPL("Test static block::setZero", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static block::setZero", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); @@ -87,16 +87,16 @@ TTS_CASE_TPL("Test static block::setZero", test_value(m, T{0}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = input_type::Zero(); + auto values = rotgen::setZero(); test_value(values, T{0}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setOnes", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) @@ -110,14 +110,14 @@ TTS_CASE_TPL("Test dynamic block::setOnes", test_value(m, T{1}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Ones(ni, nj); + auto values = rotgen::setOnes(ni, nj); test_value(values, T{1}, 0, 0, ni, nj); } }; -TTS_CASE_TPL("Test static block::setOnes", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static block::setOnes", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); @@ -133,16 +133,16 @@ TTS_CASE_TPL("Test static block::setOnes", test_value(m, T{1}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = input_type::Ones(); + auto values = rotgen::setOnes(); test_value(values, T{1}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setConstant", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) @@ -156,14 +156,14 @@ TTS_CASE_TPL("Test dynamic block::setConstant", test_value(m, T{13.37f}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Constant(ni, nj, T{13.37f}); + auto values = rotgen::setConstant(ni, nj, T{13.37f}); test_value(values, T{13.37f}, 0, 0, ni, nj); } }; -TTS_CASE_TPL("Test static block::setConstant", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static block::setConstant", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); @@ -179,16 +179,16 @@ TTS_CASE_TPL("Test static block::setConstant", test_value(m, T{13.37f}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = input_type::Constant(T{13.37f}); + auto values = rotgen::setConstant(T{13.37f}); test_value(values, T{13.37f}, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setIdentity", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) @@ -202,14 +202,14 @@ TTS_CASE_TPL("Test dynamic block::setIdentity", test_identity(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Identity(ni, nj); + auto values = rotgen::setIdentity(ni, nj); test_identity(values, 0, 0, ni, nj); } }; -TTS_CASE_TPL("Test static block::setIdentity", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static block::setIdentity", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); @@ -225,16 +225,16 @@ TTS_CASE_TPL("Test static block::setIdentity", test_identity(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = input_type::Identity(); + auto values = rotgen::setIdentity(); test_identity(values, 0, 0, D::ni, D::nj); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setRandom", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_block_references(); for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) @@ -248,14 +248,14 @@ TTS_CASE_TPL("Test dynamic block::setRandom", test_random(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Random(ni, nj); + auto values = rotgen::setRandom(ni, nj); test_random(values, 0, 0, ni, nj); } }; -TTS_CASE_TPL("Test static block::setRandom", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static block::setRandom", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_block_references(); @@ -271,7 +271,7 @@ TTS_CASE_TPL("Test static block::setRandom", test_random(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = input_type::Random(); + auto values = rotgen::setRandom(); test_random(values, 0, 0, D::ni, D::nj); }; diff --git a/test/unit/common/arithmetic.hpp b/test/unit/common/arithmetic.hpp index 4899850..f199cd2 100644 --- a/test/unit/common/arithmetic.hpp +++ b/test/unit/common/arithmetic.hpp @@ -21,7 +21,7 @@ namespace rotgen::tests using eigen_mat_t = matrix; - eigen_mat_t eigen_result(rotgen_input.cols(), rotgen_input.rows()); + eigen_mat_t eigen_result(cols(rotgen_input), rows(rotgen_input)); prepare([&](auto r, auto c) { return rotgen_input(c, r); }, eigen_result); TTS_EQUAL(transpose(rotgen_input), eigen_result); @@ -42,7 +42,7 @@ namespace rotgen::tests } else { - if (rotgen_input.rows() == rotgen_input.cols()) + if (rows(rotgen_input) == cols(rotgen_input)) { eigen_mat_t eigen_ref = rotgen_input; transposeInPlace(rotgen_input); @@ -66,7 +66,7 @@ namespace rotgen::tests using eigen_mat_t = Eigen::Matrix; - eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); + eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref); TTS_ULP_EQUAL(sum(rotgen_input), eigen_ref.sum(), 2); diff --git a/test/unit/common/cwise.hpp b/test/unit/common/cwise.hpp index 313361c..645fdb9 100644 --- a/test/unit/common/cwise.hpp +++ b/test/unit/common/cwise.hpp @@ -25,10 +25,10 @@ namespace rotgen::tests TTS_WHEN("Unary Cwise operations") { - eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); + eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref); - rotgen_mat_t rotgen_ref(rotgen_input.rows(), rotgen_input.cols()); + rotgen_mat_t rotgen_ref(rows(rotgen_input), cols(rotgen_input)); TTS_AND_THEN("abs()") { @@ -57,8 +57,8 @@ namespace rotgen::tests auto mat = rotgen::abs(rotgen_input); auto proper_input = rotgen::sqrt(mat); - for (rotgen::Index r = 0; r < rotgen_input.rows(); ++r) - for (rotgen::Index c = 0; c < rotgen_input.cols(); ++c) + for (rotgen::Index r = 0; r < rows(rotgen_input); ++r) + for (rotgen::Index c = 0; c < cols(rotgen_input); ++c) TTS_ULP_EQUAL(proper_input(r, c), eigen_ref(r, c), 1); } } diff --git a/test/unit/common/norms.hpp b/test/unit/common/norms.hpp index 711c190..b8750e4 100644 --- a/test/unit/common/norms.hpp +++ b/test/unit/common/norms.hpp @@ -20,7 +20,7 @@ namespace rotgen::tests using eigen_mat_t = Eigen::Matrix; - eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); + eigen_mat_t eigen_ref(rows(rotgen_input), cols(rotgen_input)); prepare([&](auto row, auto col) { return rotgen_input(row, col); }, eigen_ref); @@ -38,7 +38,7 @@ namespace rotgen::tests using rotgen_mat_t = rotgen::matrix; - rotgen_mat_t rotgen_norm_ref(rotgen_input.rows(), rotgen_input.cols()); + rotgen_mat_t rotgen_norm_ref(rows(rotgen_input), cols(rotgen_input)); prepare([&](auto row, auto col) { return eigen_normalized(row, col); }, rotgen_norm_ref); diff --git a/test/unit/common/references.hpp b/test/unit/common/references.hpp index 08a07d6..dcf361d 100644 --- a/test/unit/common/references.hpp +++ b/test/unit/common/references.hpp @@ -55,8 +55,13 @@ namespace rotgen::tests void prepare(auto fn, auto& output) { - for (rotgen::Index r = 0; r < output.rows(); ++r) - for (rotgen::Index c = 0; c < output.cols(); ++c) output(r, c) = fn(r, c); + for (rotgen::Index r = 0; r < rows(output); ++r) + { + for (rotgen::Index c = 0; c < cols(output); ++c) + { + output(r, c) = fn(r, c); + } + } } auto default_init_function = [](auto row, auto col) { diff --git a/test/unit/functions/rowwise.cpp b/test/unit/functions/rowwise.cpp index 9f67e41..ba4c829 100644 --- a/test/unit/functions/rowwise.cpp +++ b/test/unit/functions/rowwise.cpp @@ -10,8 +10,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("rowwise API", rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("rowwise API", rotgen::tests::types) + +(tts::type>) { using eigen_mat_t = Eigen::Matrix; @@ -25,24 +26,25 @@ TTS_CASE_TPL("rowwise API", rotgen::tests::types)( auto rotgen_rw = rotgen::rowwise(rotgen_mat); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) + for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i)); }; -TTS_CASE_TPL("colwise API", rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("colwise API", rotgen::tests::types) + +(tts::type>) { using eigen_mat_t = Eigen::Matrix; @@ -56,18 +58,18 @@ TTS_CASE_TPL("colwise API", rotgen::tests::types)( auto rotgen_rw = rotgen::colwise(rotgen_mat); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); - for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) + for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) TTS_EQUAL(rotgen::norm(rotgen_rw)(i), eigen_ref_rw.norm()(i)); }; diff --git a/test/unit/functions/svd.cpp b/test/unit/functions/svd.cpp index 55a643c..f0412ac 100644 --- a/test/unit/functions/svd.cpp +++ b/test/unit/functions/svd.cpp @@ -16,8 +16,8 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) int rank, i = 5; auto eps = std::numeric_limits::epsilon(); - auto m = - rotgen::matrix::Random(5, 5); + auto m = rotgen::setRandom< + rotgen::matrix>(5, 5); auto decomp = rotgen::svd(m); do @@ -55,7 +55,7 @@ TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types) int rank, i = 5; auto eps = std::numeric_limits::epsilon(); - auto m = rotgen::matrix::Random(); + auto m = rotgen::setRandom>(); auto decomp = rotgen::svd(m); do diff --git a/test/unit/map/arithmetic_functions.cpp b/test/unit/map/arithmetic_functions.cpp index 7544014..153fbb0 100644 --- a/test/unit/map/arithmetic_functions.cpp +++ b/test/unit/map/arithmetic_functions.cpp @@ -36,7 +36,7 @@ TTS_CASE_TPL("Test static map transposition-like operations", auto process = [](D const& desc) { rotgen::matrix base(D::rows, D::cols); - rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); + rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::map> input( base.data()); @@ -72,7 +72,7 @@ TTS_CASE_TPL("Test static map reduction-like operations", auto process = [](D const& desc) { rotgen::matrix base(D::rows, D::cols); - rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); + rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::map> input( base.data()); diff --git a/test/unit/map/basic_api.cpp b/test/unit/map/basic_api.cpp index 773f6ad..9566d11 100644 --- a/test/unit/map/basic_api.cpp +++ b/test/unit/map/basic_api.cpp @@ -9,40 +9,41 @@ #include "unit/tests.hpp" -TTS_CASE_TPL("Function size", rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Function size", rotgen::tests::types) + +(tts::type>) { T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; rotgen::map> dyn_map(data, 1, 12); - TTS_EQUAL(dyn_map.rows(), rotgen::Index{1}); - TTS_EQUAL(dyn_map.cols(), rotgen::Index{12}); + TTS_EQUAL(rows(dyn_map), rotgen::Index{1}); + TTS_EQUAL(cols(dyn_map), rotgen::Index{12}); rotgen::map> s112_map(data); - TTS_EQUAL(s112_map.rows(), rotgen::Index{1}); - TTS_EQUAL(s112_map.cols(), rotgen::Index{12}); + TTS_EQUAL(rows(s112_map), rotgen::Index{1}); + TTS_EQUAL(cols(s112_map), rotgen::Index{12}); TTS_EQUAL(s112_map.size(), rotgen::Index{12}); rotgen::map> s121_map(data); - TTS_EQUAL(s121_map.rows(), rotgen::Index{12}); - TTS_EQUAL(s121_map.cols(), rotgen::Index{1}); + TTS_EQUAL(rows(s121_map), rotgen::Index{12}); + TTS_EQUAL(cols(s121_map), rotgen::Index{1}); TTS_EQUAL(s121_map.size(), rotgen::Index{12}); rotgen::map> s34_map(data); - TTS_EQUAL(s34_map.rows(), rotgen::Index{3}); - TTS_EQUAL(s34_map.cols(), rotgen::Index{4}); + TTS_EQUAL(rows(s34_map), rotgen::Index{3}); + TTS_EQUAL(cols(s34_map), rotgen::Index{4}); TTS_EQUAL(s34_map.size(), rotgen::Index{12}); rotgen::map> s62_map(data); - TTS_EQUAL(s62_map.rows(), rotgen::Index{6}); - TTS_EQUAL(s62_map.cols(), rotgen::Index{2}); + TTS_EQUAL(rows(s62_map), rotgen::Index{6}); + TTS_EQUAL(cols(s62_map), rotgen::Index{2}); TTS_EQUAL(s62_map.size(), rotgen::Index{12}); }; -TTS_CASE_TPL("Test coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) + +(tts::type>) { using base = rotgen::matrix; @@ -66,9 +67,9 @@ TTS_CASE_TPL("Test coefficient accessors", TTS_EQUAL(a(2, 2), 17); }; -TTS_CASE_TPL("Test one index coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) + +(tts::type>) { T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; diff --git a/test/unit/map/cwise.cpp b/test/unit/map/cwise.cpp index 9dda215..5442fea 100644 --- a/test/unit/map/cwise.cpp +++ b/test/unit/map/cwise.cpp @@ -11,9 +11,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("Test dynamic map cwise operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic map cwise operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -28,16 +28,16 @@ TTS_CASE_TPL("Test dynamic map cwise operations", } }; -TTS_CASE_TPL("Test static map cwise operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static map cwise operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix base(D::rows, D::cols); - rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); + rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::map> input( base.data()); diff --git a/test/unit/map/norms.cpp b/test/unit/map/norms.cpp index 2b93205..01b933f 100644 --- a/test/unit/map/norms.cpp +++ b/test/unit/map/norms.cpp @@ -11,9 +11,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("Test dynamic map norm operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic map norm operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -28,16 +28,16 @@ TTS_CASE_TPL("Test dynamic map norm operations", } }; -TTS_CASE_TPL("Test static map norm operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static map norm operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix base(D::rows, D::cols); - rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); + rotgen::tests::prepare(rows(base), cols(base), desc.init_fn, base); rotgen::map> input( base.data()); diff --git a/test/unit/map/strides.cpp b/test/unit/map/strides.cpp index e0bf50a..23b30ef 100644 --- a/test/unit/map/strides.cpp +++ b/test/unit/map/strides.cpp @@ -40,8 +40,8 @@ TTS_CASE("Validate Column Major Map with regular stride behavior") r_map_t> r_map(buffer.data(), rows, cols); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride(), 3); + TTS_EQUAL(innerStride(r_map), 1); + TTS_EQUAL(outerStride(r_map), 3); e_map_t> e_map(buffer.data(), rows, cols); @@ -59,8 +59,8 @@ TTS_CASE("Validate Column Major Map with specific outer stride behavior") r_map_t, rotgen::outer_stride<>> r_map( buffer.data(), rows, cols, rotgen::outer_stride<>(rows + 1)); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride(), 4); + TTS_EQUAL(innerStride(r_map), 1); + TTS_EQUAL(outerStride(r_map), 4); e_map_t, Eigen::OuterStride<>> e_map( buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1)); @@ -79,8 +79,8 @@ TTS_CASE("Validate Column Major Map with specific inner stride behavior") r_map_t, rotgen::dynamic_stride> r_map( buffer.data(), rows, cols, rotgen::dynamic_stride(rows, 2)); - TTS_EQUAL(r_map.innerStride(), 2); - TTS_EQUAL(r_map.outerStride(), 3); + TTS_EQUAL(innerStride(r_map), 2); + TTS_EQUAL(outerStride(r_map), 3); e_map_t, Eigen::Stride> @@ -100,8 +100,8 @@ TTS_CASE("Validate Row Major Map with regular stride behavior") r_map_t> r_map(buffer.data(), rows, cols); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride(), 4); + TTS_EQUAL(innerStride(r_map), 1); + TTS_EQUAL(outerStride(r_map), 4); e_map_t> e_map(buffer.data(), rows, cols); @@ -119,8 +119,8 @@ TTS_CASE("Validate Row Major Map with specific outer stride behavior") r_map_t, rotgen::outer_stride<>> r_map( buffer.data(), rows, cols, rotgen::outer_stride<>(cols + 1)); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride(), 5); + TTS_EQUAL(innerStride(r_map), 1); + TTS_EQUAL(outerStride(r_map), 5); e_map_t, Eigen::OuterStride<>> e_map( buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1)); @@ -139,8 +139,8 @@ TTS_CASE("Validate Row Major Map with specific inner stride behavior") r_map_t, rotgen::dynamic_stride> r_map( buffer.data(), rows, cols, rotgen::dynamic_stride(2, cols)); - TTS_EQUAL(r_map.innerStride(), 4); - TTS_EQUAL(r_map.outerStride(), 2); + TTS_EQUAL(innerStride(r_map), 4); + TTS_EQUAL(outerStride(r_map), 2); e_map_t, Eigen::Stride> diff --git a/test/unit/matrix/arithmetic_functions.cpp b/test/unit/matrix/arithmetic_functions.cpp index 2930dd5..e986603 100644 --- a/test/unit/matrix/arithmetic_functions.cpp +++ b/test/unit/matrix/arithmetic_functions.cpp @@ -13,8 +13,9 @@ #include "unit/tests.hpp" TTS_CASE_TPL("Test dynamic matrix transposition-like operations", - rotgen::tests::types)( - tts::type>) + rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -27,14 +28,15 @@ TTS_CASE_TPL("Test dynamic matrix transposition-like operations", }; TTS_CASE_TPL("Test static matrix transposition-like operations", - rotgen::tests::types)( - tts::type>) + rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix input; - rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); + rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::check_shape_functions(input); }; @@ -42,8 +44,9 @@ TTS_CASE_TPL("Test static matrix transposition-like operations", }; TTS_CASE_TPL("Test dynamic matrix reduction-like operations", - rotgen::tests::types)( - tts::type>) + rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -56,21 +59,23 @@ TTS_CASE_TPL("Test dynamic matrix reduction-like operations", }; TTS_CASE_TPL("Test static matrix reduction-like operations", - rotgen::tests::types)( - tts::type>) + rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix input; - rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); + rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::check_reduction_functions(input); }; std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dot product", float, double)(tts::type){ +TTS_CASE_TPL("Test dot product", float, double) +(tts::type){ {auto a = rotgen::setConstant>(1, 8, 2); auto b = rotgen::setConstant>(1, 8, 2); diff --git a/test/unit/matrix/basic_api.cpp b/test/unit/matrix/basic_api.cpp index e54a59b..a4e4e24 100644 --- a/test/unit/matrix/basic_api.cpp +++ b/test/unit/matrix/basic_api.cpp @@ -9,8 +9,9 @@ #include "unit/tests.hpp" -TTS_CASE_TPL("Function size", rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Function size", rotgen::tests::types) + +(tts::type>) { rotgen::matrix empty_matrix; rotgen::matrix matrix(3, 4); @@ -25,87 +26,87 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)( TTS_EQUAL(column_vector.size(), rotgen::Index{5}); }; -TTS_CASE_TPL("Resizing dynamic matrix", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types) + +(tts::type>) { rotgen::matrix a(2, 3); - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = 42 + 2 * c + r; + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = 42 + 2 * c + r; rotgen::resize(a, 3, 2); - TTS_EQUAL(a.rows(), rotgen::Index(3)); - TTS_EQUAL(a.cols(), rotgen::Index(2)); + TTS_EQUAL(rows(a), rotgen::Index(3)); + TTS_EQUAL(cols(a), rotgen::Index(2)); - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0); + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) TTS_GREATER(a(r, c), 0); rotgen::resize(a, 2, 2); - TTS_EQUAL(a.rows(), rotgen::Index(2)); - TTS_EQUAL(a.cols(), rotgen::Index(2)); + TTS_EQUAL(rows(a), rotgen::Index(2)); + TTS_EQUAL(cols(a), rotgen::Index(2)); }; -TTS_CASE_TPL("Dynamix matrix conservative resizing", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types) + +(tts::type>) { rotgen::matrix a(2, 3); int i = 1; - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++; + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = i++; rotgen::conservativeResize(a, 2, 3); - TTS_EQUAL(a.rows(), rotgen::Index(2)); - TTS_EQUAL(a.cols(), rotgen::Index(3)); + TTS_EQUAL(rows(a), rotgen::Index(2)); + TTS_EQUAL(cols(a), rotgen::Index(3)); i = 1; - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++); + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) TTS_EQUAL(a(r, c), i++); rotgen::conservativeResize(a, 3, 2); - TTS_EQUAL(a.rows(), rotgen::Index(3)); - TTS_EQUAL(a.cols(), rotgen::Index(2)); + TTS_EQUAL(rows(a), rotgen::Index(3)); + TTS_EQUAL(cols(a), rotgen::Index(2)); int expected[3][2] = {{1, 2}, {4, 5}}; for (rotgen::Index r = 0; r < 2; ++r) for (rotgen::Index c = 0; c < 2; ++c) TTS_EQUAL(a(r, c), expected[r][c]); rotgen::conservativeResize(a, 4, 4); - TTS_EQUAL(a.rows(), rotgen::Index(4)); - TTS_EQUAL(a.cols(), rotgen::Index(4)); + TTS_EQUAL(rows(a), rotgen::Index(4)); + TTS_EQUAL(cols(a), rotgen::Index(4)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(3, 3), 0); rotgen::conservativeResize(a, 2, 2); - TTS_EQUAL(a.rows(), rotgen::Index(2)); - TTS_EQUAL(a.cols(), rotgen::Index(2)); + TTS_EQUAL(rows(a), rotgen::Index(2)); + TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(1, 1), 5); rotgen::conservativeResize(a, 1, 2); - TTS_EQUAL(a.rows(), rotgen::Index(1)); - TTS_EQUAL(a.cols(), rotgen::Index(2)); + TTS_EQUAL(rows(a), rotgen::Index(1)); + TTS_EQUAL(cols(a), rotgen::Index(2)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(0, 1), 2); rotgen::conservativeResize(a, 0, 0); - TTS_EQUAL(a.rows(), rotgen::Index(0)); - TTS_EQUAL(a.cols(), rotgen::Index(0)); + TTS_EQUAL(rows(a), rotgen::Index(0)); + TTS_EQUAL(cols(a), rotgen::Index(0)); rotgen::conservativeResize(a, 3, 3); - TTS_EQUAL(a.rows(), rotgen::Index(3)); - TTS_EQUAL(a.cols(), rotgen::Index(3)); + TTS_EQUAL(rows(a), rotgen::Index(3)); + TTS_EQUAL(cols(a), rotgen::Index(3)); }; -TTS_CASE_TPL("Test coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) + +(tts::type>) { rotgen::matrix a(3, 5); - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = r + 2 * c + 3; + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = r + 2 * c + 3; TTS_EQUAL(a(0, 0), 3); TTS_EQUAL(a(1, 1), 6); @@ -121,9 +122,9 @@ TTS_CASE_TPL("Test coefficient accessors", TTS_EQUAL(a(2, 2), 17); }; -TTS_CASE_TPL("Test one index coefficient accessors", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) + +(tts::type>) { auto a = [&]() { if constexpr (O::value == rotgen::ColMajor) diff --git a/test/unit/matrix/constructors.cpp b/test/unit/matrix/constructors.cpp index 0471a2b..90a8029 100644 --- a/test/unit/matrix/constructors.cpp +++ b/test/unit/matrix/constructors.cpp @@ -15,8 +15,8 @@ TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types) { rotgen::matrix matrix; - TTS_EQUAL(matrix.rows(), rotgen::Index{0}); - TTS_EQUAL(matrix.cols(), rotgen::Index{0}); + TTS_EQUAL(rows(matrix), rotgen::Index{0}); + TTS_EQUAL(cols(matrix), rotgen::Index{0}); }; TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types) @@ -25,8 +25,8 @@ TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types) { rotgen::matrix matrix; - TTS_EQUAL(matrix.rows(), rotgen::Index{4}); - TTS_EQUAL(matrix.cols(), rotgen::Index{9}); + TTS_EQUAL(rows(matrix), rotgen::Index{4}); + TTS_EQUAL(cols(matrix), rotgen::Index{9}); }; TTS_CASE_TPL("Dynamic matrix constructor with row and columns", @@ -36,8 +36,8 @@ TTS_CASE_TPL("Dynamic matrix constructor with row and columns", { rotgen::matrix matrix(10, 5); - TTS_EQUAL(matrix.rows(), rotgen::Index{10}); - TTS_EQUAL(matrix.cols(), rotgen::Index{5}); + TTS_EQUAL(rows(matrix), rotgen::Index{10}); + TTS_EQUAL(cols(matrix), rotgen::Index{5}); }; TTS_CASE_TPL("Static matrix constructor with row and columns", float, double) @@ -72,16 +72,16 @@ TTS_CASE_TPL("Copy constructor produces identical but independent matrix", { rotgen::matrix a(3, 3); - for (rotgen::Index r = 0; r < a.rows(); r++) - for (rotgen::Index c = 0; c < a.cols(); c++) a(r, c) = r + c; + for (rotgen::Index r = 0; r < rows(a); r++) + for (rotgen::Index c = 0; c < cols(a); c++) a(r, c) = r + c; rotgen::matrix b = a; - TTS_EQUAL(b.rows(), a.rows()); - TTS_EQUAL(b.cols(), a.cols()); + TTS_EQUAL(rows(b), rows(a)); + TTS_EQUAL(cols(b), cols(a)); - for (rotgen::Index r = 0; r < a.rows(); r++) - for (rotgen::Index c = 0; c < a.cols(); c++) TTS_EQUAL(b(r, c), a(r, c)); + for (rotgen::Index r = 0; r < rows(a); r++) + for (rotgen::Index c = 0; c < cols(a); c++) TTS_EQUAL(b(r, c), a(r, c)); TTS_EQUAL(b(0, 0), 0.0); TTS_EQUAL(b(1, 0), 1.0); @@ -97,8 +97,8 @@ TTS_CASE_TPL("Copy constructor on default matrix", rotgen::tests::types) { rotgen::matrix a; rotgen::matrix b = a; - TTS_EQUAL(b.rows(), rotgen::Index{0}); - TTS_EQUAL(b.cols(), rotgen::Index{0}); + TTS_EQUAL(rows(b), rotgen::Index{0}); + TTS_EQUAL(cols(b), rotgen::Index{0}); }; TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types) @@ -107,8 +107,8 @@ TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types) { rotgen::matrix const a(2, 2); auto b = a; - TTS_EQUAL(b.rows(), rotgen::Index{2}); - TTS_EQUAL(b.cols(), rotgen::Index{2}); + TTS_EQUAL(rows(b), rotgen::Index{2}); + TTS_EQUAL(cols(b), rotgen::Index{2}); }; TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types) @@ -117,8 +117,8 @@ TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types) { rotgen::matrix a; rotgen::matrix b = a; - TTS_EQUAL(b.rows(), rotgen::Index{2}); - TTS_EQUAL(b.cols(), rotgen::Index{5}); + TTS_EQUAL(rows(b), rotgen::Index{2}); + TTS_EQUAL(cols(b), rotgen::Index{5}); }; TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types) @@ -127,8 +127,8 @@ TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types) { rotgen::matrix a; rotgen::matrix b = a; - TTS_EQUAL(b.rows(), 11); - TTS_EQUAL(b.cols(), 4); + TTS_EQUAL(rows(b), 11); + TTS_EQUAL(cols(b), 4); }; TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types) @@ -137,8 +137,8 @@ TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types) { rotgen::matrix a(5, 7); rotgen::matrix b = a; - TTS_EQUAL(b.rows(), 5); - TTS_EQUAL(b.cols(), 7); + TTS_EQUAL(rows(b), 5); + TTS_EQUAL(cols(b), 7); }; TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types) @@ -153,8 +153,8 @@ TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types) std::move(a); TTS_EQUAL(b(1, 1), 7); - TTS_EQUAL(b.rows(), rotgen::Index{3}); - TTS_EQUAL(b.cols(), rotgen::Index{3}); + TTS_EQUAL(rows(b), rotgen::Index{3}); + TTS_EQUAL(cols(b), rotgen::Index{3}); TTS_EXPECT(b.data() == ptr); }; @@ -164,8 +164,8 @@ TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types) { rotgen::matrix b = rotgen::matrix(2, 2); - TTS_EQUAL(b.rows(), rotgen::Index{2}); - TTS_EQUAL(b.cols(), rotgen::Index{2}); + TTS_EQUAL(rows(b), rotgen::Index{2}); + TTS_EQUAL(cols(b), rotgen::Index{2}); }; TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types) @@ -173,24 +173,24 @@ TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types) (tts::type>) { rotgen::matrix b1{3.5}; - TTS_EQUAL(b1.rows(), rotgen::Index{1}); - TTS_EQUAL(b1.cols(), rotgen::Index{1}); + TTS_EQUAL(rows(b1), rotgen::Index{1}); + TTS_EQUAL(cols(b1), rotgen::Index{1}); TTS_EQUAL(b1(0), 3.5); rotgen::matrix b9{0.25, 0.5, 1, 2, 4}; - TTS_EQUAL(b9.rows(), rotgen::Index{5}); - TTS_EQUAL(b9.cols(), rotgen::Index{1}); + TTS_EQUAL(rows(b9), rotgen::Index{5}); + TTS_EQUAL(cols(b9), rotgen::Index{1}); T i = 0.25; - for (rotgen::Index r = 0; r < b9.rows(); ++r) + for (rotgen::Index r = 0; r < rows(b9); ++r) { TTS_EQUAL(b9(r, 0), i); i *= 2; } rotgen::matrix b13{1.2, 2.3, 3.4}; - TTS_EQUAL(b13.rows(), rotgen::Index{1}); - TTS_EQUAL(b13.cols(), rotgen::Index{3}); + TTS_EQUAL(rows(b13), rotgen::Index{1}); + TTS_EQUAL(cols(b13), rotgen::Index{3}); TTS_EQUAL(b13(0), T(1.2)); TTS_EQUAL(b13(1), T(2.3)); TTS_EQUAL(b13(2), T(3.4)); @@ -201,16 +201,16 @@ TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types) (tts::type>) { rotgen::matrix b1{{3.5}}; - TTS_EQUAL(b1.rows(), rotgen::Index{1}); - TTS_EQUAL(b1.cols(), rotgen::Index{1}); + TTS_EQUAL(rows(b1), rotgen::Index{1}); + TTS_EQUAL(cols(b1), rotgen::Index{1}); TTS_EQUAL(b1(0, 0), T(3.5)); rotgen::matrix b23{ {1.2, 2.3, 3.4}, {10, 200, 3000}}; - TTS_EQUAL(b23.rows(), rotgen::Index{2}); - TTS_EQUAL(b23.cols(), rotgen::Index{3}); + TTS_EQUAL(rows(b23), rotgen::Index{2}); + TTS_EQUAL(cols(b23), rotgen::Index{3}); TTS_EQUAL(b23(0, 0), T(1.2)); TTS_EQUAL(b23(0, 1), T(2.3)); TTS_EQUAL(b23(0, 2), T(3.4)); diff --git a/test/unit/matrix/cwise.cpp b/test/unit/matrix/cwise.cpp index ede5967..025cadd 100644 --- a/test/unit/matrix/cwise.cpp +++ b/test/unit/matrix/cwise.cpp @@ -11,9 +11,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("Test dynamic matrix cwise operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -25,15 +25,15 @@ TTS_CASE_TPL("Test dynamic matrix cwise operations", } }; -TTS_CASE_TPL("Test static matrix cwise operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static matrix cwise operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix input; - rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); + rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::check_cwise_functions(input); }; diff --git a/test/unit/matrix/inverse.cpp b/test/unit/matrix/inverse.cpp index dd9dacb..2bca121 100644 --- a/test/unit/matrix/inverse.cpp +++ b/test/unit/matrix/inverse.cpp @@ -10,9 +10,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("Test dynamic matrix inverse", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; auto eps = std::numeric_limits::epsilon(); @@ -23,7 +23,7 @@ TTS_CASE_TPL("Test dynamic matrix inverse", auto inv = rotgen::inverse(input); auto rec = input * inv; - auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec)); + auto id = rotgen::setIdentity(rotgen::rows(rec), rotgen::cols(rec)); auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.) @@ -43,7 +43,7 @@ template void check_static_inverse() auto inv = rotgen::inverse(input); auto rec = input * inv; - auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec)); + auto id = rotgen::setIdentity(rotgen::rows(rec), rotgen::cols(rec)); auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 256.) @@ -53,9 +53,9 @@ template void check_static_inverse() << error << "\n"; } -TTS_CASE_TPL("Test static matrix inverse", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types) + +(tts::type>) { check_static_inverse(); check_static_inverse(); diff --git a/test/unit/matrix/norms.cpp b/test/unit/matrix/norms.cpp index cf9f812..09816b2 100644 --- a/test/unit/matrix/norms.cpp +++ b/test/unit/matrix/norms.cpp @@ -11,9 +11,9 @@ #include "unit/common/references.hpp" #include "unit/tests.hpp" -TTS_CASE_TPL("Test dynamic matrix norm operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); for (auto const& [rows, cols, fn] : cases) @@ -25,15 +25,15 @@ TTS_CASE_TPL("Test dynamic matrix norm operations", } }; -TTS_CASE_TPL("Test static matrix norm operations", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Test static matrix norm operations", rotgen::tests::types) + +(tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); auto process = [](D const& desc) { rotgen::matrix input; - rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); + rotgen::tests::prepare(rows(input), cols(input), desc.init_fn, input); rotgen::tests::check_norms_functions(input); }; diff --git a/test/unit/matrix/operators.cpp b/test/unit/matrix/operators.cpp index e0b8c93..d01efb3 100644 --- a/test/unit/matrix/operators.cpp +++ b/test/unit/matrix/operators.cpp @@ -10,20 +10,20 @@ #include "unit/tests.hpp" template -void test_matrix_operations(rotgen::Index rows, - rotgen::Index cols, +void test_matrix_operations(rotgen::Index rr, + rotgen::Index cc, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops) { - MatrixType a(rows, cols); - MatrixType b(rows, cols); - MatrixType ref(rows, cols); + MatrixType a(rr, cc); + MatrixType b(rr, cc); + MatrixType ref(rr, cc); - for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index r = 0; r < rr; ++r) { - for (rotgen::Index c = 0; c < cols; ++c) + for (rotgen::Index c = 0; c < cc; ++c) { a(r, c) = a_init_fn(r, c); b(r, c) = b_init_fn(r, c); @@ -40,19 +40,19 @@ void test_matrix_operations(rotgen::Index rows, } template -void test_scalar_operations(rotgen::Index rows, - rotgen::Index cols, +void test_scalar_operations(rotgen::Index rr, + rotgen::Index cc, auto a_init_fn, auto s, auto ops, auto self_ops) { - MatrixType a(rows, cols); - MatrixType ref(rows, cols); + MatrixType a(rr, cc); + MatrixType ref(rr, cc); - for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index r = 0; r < rr; ++r) { - for (rotgen::Index c = 0; c < cols; ++c) + for (rotgen::Index c = 0; c < cc; ++c) { a(r, c) = a_init_fn(r, c); ref(r, c) = ops(a(r, c), s); @@ -68,17 +68,17 @@ void test_scalar_operations(rotgen::Index rows, } template -void test_scalar_multiplications(rotgen::Index rows, - rotgen::Index cols, +void test_scalar_multiplications(rotgen::Index rr, + rotgen::Index cc, auto fn, auto s) { - MatrixType a(rows, cols); - MatrixType ref(rows, cols); + MatrixType a(rr, cc); + MatrixType ref(rr, cc); - for (rotgen::Index r = 0; r < rows; ++r) + for (rotgen::Index r = 0; r < rr; ++r) { - for (rotgen::Index c = 0; c < cols; ++c) + for (rotgen::Index c = 0; c < cc; ++c) { a(r, c) = fn(r, c); ref(r, c) = a(r, c) * s; @@ -96,27 +96,27 @@ void test_scalar_multiplications(rotgen::Index rows, } template -void test_matrix_multiplication(rotgen::Index rows, - rotgen::Index cols, +void test_matrix_multiplication(rotgen::Index rr, + rotgen::Index cc, auto a_init_fn, auto b_init_fn) { - MatrixType a(rows, cols); - MatrixType b(cols, rows); - MatrixType ref(rows, rows); + MatrixType a(rr, cc); + MatrixType b(cc, rr); + MatrixType ref(rr, rr); - for (rotgen::Index r = 0; r < a.rows(); ++r) - for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = a_init_fn(r, c); + for (rotgen::Index r = 0; r < rows(a); ++r) + for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = a_init_fn(r, c); - for (rotgen::Index r = 0; r < b.rows(); ++r) - for (rotgen::Index c = 0; c < b.cols(); ++c) b(r, c) = b_init_fn(r, c); + for (rotgen::Index r = 0; r < rows(b); ++r) + for (rotgen::Index c = 0; c < cols(b); ++c) b(r, c) = b_init_fn(r, c); - for (rotgen::Index i = 0; i < a.rows(); ++i) + for (rotgen::Index i = 0; i < rows(a); ++i) { - for (rotgen::Index j = 0; j < b.cols(); ++j) + for (rotgen::Index j = 0; j < cols(b); ++j) { ref(i, j) = 0; - for (rotgen::Index k = 0; k < a.cols(); ++k) + for (rotgen::Index k = 0; k < cols(a); ++k) ref(i, j) += a(i, k) * b(k, j); } } @@ -134,9 +134,9 @@ inline constexpr auto init_b = [](auto r, auto c) { }; inline constexpr auto init_0 = [](auto, auto) { return 0; }; -TTS_CASE_TPL("Check matrix addition", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check matrix addition", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; auto op = [](auto a, auto b) { return a + b; }; @@ -153,9 +153,9 @@ TTS_CASE_TPL("Check matrix addition", test_matrix_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check matrix substraction", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; auto op = [](auto a, auto b) { return a - b; }; @@ -172,9 +172,9 @@ TTS_CASE_TPL("Check matrix substraction", test_matrix_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check matrix multiplications", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; }; @@ -193,9 +193,9 @@ TTS_CASE_TPL("Check matrix multiplications", test_matrix_multiplication(5, 5, init_a, init_0); }; -TTS_CASE_TPL("Check matrix multiplication with scalar", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; @@ -209,9 +209,9 @@ TTS_CASE_TPL("Check matrix multiplication with scalar", test_scalar_multiplications(1, 10, init_a, T{-0.5}); }; -TTS_CASE_TPL("Check matrix division with scalar", - rotgen::tests::types)( - tts::type>) +TTS_CASE_TPL("Check matrix division with scalar", rotgen::tests::types) + +(tts::type>) { using mat_t = rotgen::matrix; auto op = [](auto a, auto b) { return a / b; }; diff --git a/test/unit/meta/ref.cpp b/test/unit/meta/ref.cpp index ed19e7c..5513015 100644 --- a/test/unit/meta/ref.cpp +++ b/test/unit/meta/ref.cpp @@ -22,7 +22,7 @@ template void check_acceptance(Generator f) TTS_EQUAL(v.data(), ptr); // Setup the data correctly - data.resize(v.rows(), v.cols()); + data.resize(rows(v), cols(v)); rotgen::setRandom(data); // Assign through the ref @@ -34,7 +34,7 @@ template void check_acceptance(Generator f) }; acceptor(in, in.data()); - data.resize(in.rows(), in.cols()); + data.resize(rows(in), cols(in)); TTS_EQUAL(in, data); TTS_EQUAL(constant_acceptor(in), minCoeff(data)) << in << "\n"