diff --git a/.clangd b/.clangd deleted file mode 100644 index b976251..0000000 --- a/.clangd +++ /dev/null @@ -1,10 +0,0 @@ -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 1e26de1..cc13b24 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,3 @@ _deps build/* .idea .vscode/* -.clangd diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d164291..da88d5f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,11 +39,11 @@ test-native-debug: CXX: clang++ CMAKE_PRESET: debug -test-native-debug-fixed: +test-native-debug-static: <<: *test-native variables: CXX: clang++ - CMAKE_PRESET: debug-fixed + CMAKE_PRESET: debug-static test-native-debug-et: <<: *test-native @@ -57,11 +57,11 @@ test-native-release: CXX: clang++ CMAKE_PRESET: release -test-native-release-fixed: +test-native-release-static: <<: *test-native variables: CXX: clang++ - CMAKE_PRESET: release-fixed + CMAKE_PRESET: release-static test-native-release-et: <<: *test-native @@ -78,12 +78,12 @@ test-ubuntu-clang14-debug: CXXFLAGS: --stdlib=libc++ CMAKE_PRESET: debug -test-ubuntu-clang14-debug-fixed: +test-ubuntu-clang14-debug-static: <<: *test-ubuntu2404 variables: CXX: clang++-14 CXXFLAGS: --stdlib=libc++ - CMAKE_PRESET: debug-fixed + CMAKE_PRESET: debug-static 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-fixed: +test-ubuntu-clang14-release-static: <<: *test-ubuntu2404 variables: CXX: clang++-14 CXXFLAGS: --stdlib=libc++ - CMAKE_PRESET: release-fixed + CMAKE_PRESET: release-static test-ubuntu-clang14-release-et: <<: *test-ubuntu2404 @@ -121,11 +121,11 @@ test-ubuntu-gcc-debug: CXX: g++ CMAKE_PRESET: debug -test-ubuntu-gcc-debug-fixed: +test-ubuntu-gcc-debug-static: <<: *test-ubuntu2404 variables: CXX: g++ - CMAKE_PRESET: debug-fixed + CMAKE_PRESET: debug-static test-ubuntu-gcc-debug-et: <<: *test-ubuntu2404 @@ -139,11 +139,11 @@ test-ubuntu-gcc-release: CXX: g++ CMAKE_PRESET: release -test-ubuntu-gcc-release-fixed: +test-ubuntu-gcc-release-static: <<: *test-ubuntu2404 variables: CXX: g++ - CMAKE_PRESET: release-fixed + CMAKE_PRESET: release-static test-ubuntu-gcc-release-et: <<: *test-ubuntu2404 diff --git a/CMakeLists.txt b/CMakeLists.txt index a608bfb..a8a307b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,8 +96,3 @@ include(${ROTGEN_SOURCE_DIR}/cmake/config/rotgen-install.cmake) ## Setup the library's Tests ##============================================================================== add_subdirectory(test) - -##============================================================================== -## Setup the library's documentation -##============================================================================== -include(${ROTGEN_SOURCE_DIR}/cmake/docs.cmake) diff --git a/CMakePresets.json b/CMakePresets.json index b3b93dd..49a1a51 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -42,21 +42,21 @@ } }, { - "name": "release-fixed", - "displayName": "Release (Fixed size)", - "description": "Release (Fixed size) build", + "name": "release-static", + "displayName": "Release (Static size)", + "description": "Release (Static size) build", "generator": "Ninja", - "binaryDir": "${sourceDir}/build/release-fixed", + "binaryDir": "${sourceDir}/build/release-static", "cacheVariables": { "ROTGEN_MAX_SIZE": "16" } }, { - "name": "debug-fixed", - "displayName": "Debug (Fixed size)", - "description": "Debug (Fixed size) build", + "name": "debug-static", + "displayName": "Debug (Static size)", + "description": "Debug (Static size) build", "generator": "Ninja", - "binaryDir": "${sourceDir}/build/debug-fixed", + "binaryDir": "${sourceDir}/build/debug-static", "cacheVariables": { "ROTGEN_MAX_SIZE": "16" } @@ -90,8 +90,8 @@ "configurePreset": "release" }, { - "name": "release-fixed", - "configurePreset": "release-fixed" + "name": "release-static", + "configurePreset": "release-static" }, { "name": "release-et", @@ -102,8 +102,8 @@ "configurePreset": "debug" }, { - "name": "debug-fixed", - "configurePreset": "debug-fixed" + "name": "debug-static", + "configurePreset": "debug-static" }, { "name": "debug-et", diff --git a/cmake/docs.cmake b/cmake/docs.cmake deleted file mode 100644 index 65ae50b..0000000 --- a/cmake/docs.cmake +++ /dev/null @@ -1,41 +0,0 @@ -##============================================================================== -## ROTGEN - Runtime Overlay for Eigen -## Copyright : CODE RECKONS -## SPDX-License-Identifier: BSL-1.0 -##============================================================================== - -find_package(Doxygen COMPONENTS dot OPTIONAL_COMPONENTS mscgen dia) - -if(Doxygen_FOUND) - - # Documentation options - set(DOXYGEN_EXTRACT_ALL YES) - set(DOXYGEN_GENERATE_TREEVIEW YES) - set(DOXYGEN_EXCLUDE_PATTERNS */build/* */test/*) - set(DOXYGEN_USE_MDFILE_AS_MAINPAGE ${CMAKE_SOURCE_DIR}/README.md) - set(DOXYGEN_EXAMPLE_PATH ${CMAKE_SOURCE_DIR}) - set(DOXYGEN_DOT_TRANSPARENT YES) - set(DOXYGEN_IMAGE_PATH ${CMAKE_SOURCE_DIR}) - - # ============================================================================ - # Doxygen Awesome CSS - - include(FetchContent) - - FetchContent_Declare( - doxygen_awesome_content - GIT_REPOSITORY https://github.com/jothepro/doxygen-awesome-css.git - GIT_TAG v2.4.1 - GIT_SHALLOW) - - FetchContent_GetProperties(doxygen_awesome_content) - if(NOT doxygen_awesome_content_POPULATED) - FetchContent_Populate(doxygen_awesome_content) - endif() - - set(DOXYGEN_HTML_EXTRA_STYLESHEET - ${doxygen_awesome_content_SOURCE_DIR}/doxygen-awesome.css) - - doxygen_add_docs(docs) - -endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index 134bf58..c47c01f 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 fixed size options were provided") + message(STATUS " Reason : No static size options were provided") endif() else() - message(STATUS " Configuration mode: FIXED SIZE") + message(STATUS " Configuration mode: STATIC") message(STATUS " Expression Templates: ${ROTGEN_ENABLE_EXPRESSION_TEMPLATES}") endif() diff --git a/include/rotgen/algebra/svd/dynamic.hpp b/include/rotgen/algebra/svd/dynamic.hpp index 48b3f0b..12d98b5 100644 --- a/include/rotgen/algebra/svd/dynamic.hpp +++ b/include/rotgen/algebra/svd/dynamic.hpp @@ -25,20 +25,20 @@ namespace rotgen int rank() const { return parent::rank(); } - m_type matrixU() const { return parent::U(); } + m_type U() const { return parent::U(); } - m_type matrixD() const { return parent::D(); } + m_type D() const { return parent::D(); } - m_type matrixV() const { return parent::V(); } + m_type V() const { return parent::V(); } - d_type singularValues() const { return parent::singular_values(); } + d_type singular_values() const { return parent::singular_values(); } - m_type matrixU(int r) const { return parent::U(r); } + m_type U(int r) const { return parent::U(r); } - m_type matrixD(int r) const { return parent::D(r); } + m_type D(int r) const { return parent::D(r); } - m_type matrixV(int r) const { return parent::V(r); } + m_type V(int r) const { return parent::V(r); } - m_type singularValues(int r) const { return parent::singular_values(r); } + m_type singular_values(int r) const { return parent::singular_values(r); } }; } diff --git a/include/rotgen/algebra/svd/fixed.hpp b/include/rotgen/algebra/svd/fixed.hpp index 0230898..5adcbaf 100644 --- a/include/rotgen/algebra/svd/fixed.hpp +++ b/include/rotgen/algebra/svd/fixed.hpp @@ -31,28 +31,28 @@ namespace rotgen int rank() const { return svd_.rank(); } - auto singularValues() const + auto singular_values() const { if constexpr (!use_expression_templates) return detail::as_concrete_t{svd_.singularValues()}; else return svd_.singularValues(); } - auto matrixU() const + auto U() const { if constexpr (!use_expression_templates) return detail::as_concrete_t{svd_.matrixU()}; else return svd_.matrixU(); } - auto matrixV() const + auto V() const { if constexpr (!use_expression_templates) return detail::as_concrete_t{svd_.matrixV()}; else return svd_.matrixV(); } - auto matrixD() const + auto D() const { auto d = svd_.singularValues().asDiagonal(); if constexpr (!use_expression_templates) @@ -61,7 +61,7 @@ namespace rotgen else return d; } - auto singularValues(int r) const + auto singular_values(int r) const { auto that = svd_.singularValues().head(r); if constexpr (!use_expression_templates) @@ -69,7 +69,7 @@ namespace rotgen else return svd_.singularValues(); } - auto matrixU(int r) const + auto U(int r) const { auto that = svd_.matrixU().leftCols(r); if constexpr (!use_expression_templates) @@ -77,7 +77,7 @@ namespace rotgen else return that; } - auto matrixV(int r) const + auto V(int r) const { auto that = svd_.matrixV().leftCols(r); if constexpr (!use_expression_templates) @@ -85,7 +85,7 @@ namespace rotgen else return that; } - auto matrixD(int r) const + auto D(int r) const { auto d = svd_.singularValues().head(r).asDiagonal(); if constexpr (!use_expression_templates) diff --git a/include/rotgen/concepts.hpp b/include/rotgen/concepts.hpp index 26f4773..9029597 100644 --- a/include/rotgen/concepts.hpp +++ b/include/rotgen/concepts.hpp @@ -12,26 +12,6 @@ namespace rotgen::concepts { - //================================================================================================ - //! @brief Check if a type is a Rotgen block. - //================================================================================================ - template - concept block = - requires { typename std::remove_cvref_t::rotgen_block_tag; }; - - //================================================================================================ - //! @brief Check if a type is a Rotgen matrix. - //================================================================================================ - template - concept matrix = - requires { typename std::remove_cvref_t::rotgen_matrix_tag; }; - - //================================================================================================ - //! @brief Check if a type is a Rotgen map. - //================================================================================================ - template - concept map = requires { typename std::remove_cvref_t::rotgen_map_tag; }; - //================================================================================================ //! @brief Check if a type is a Rotgen reference. //================================================================================================ @@ -56,8 +36,10 @@ namespace rotgen::concepts //! @brief Check if a type is a ROTGEN type. //================================================================================================ template - concept entity = - requires(T const&) { typename std::remove_cvref_t::rotgen_tag; }; + concept entity = requires(T const&) { + typename std::remove_cvref_t::rotgen_tag; + typename std::remove_cvref_t::parent; + }; //================================================================================================ //! @brief Check if a type is an EIGEN type. diff --git a/include/rotgen/container/block/dynamic.hpp b/include/rotgen/container/block/dynamic.hpp index 794575f..504a15e 100644 --- a/include/rotgen/container/block/dynamic.hpp +++ b/include/rotgen/container/block/dynamic.hpp @@ -7,12 +7,11 @@ //================================================================================================== #pragma once -#include - #include #include #include +#include #include namespace rotgen @@ -77,37 +76,14 @@ namespace rotgen using parent::operator=; - template - block& operator=(Src const& other) + block& operator=(concepts::entity auto const& other) requires(!is_immutable) { - if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime) - { - ROTGEN_ASSERT(parent::size() == other.size(), - "Block assignment from 1D source doesn't match size"); - for (rotgen::Index i = 0; i < parent::size(); ++i) - (*this)[i] = other[i]; - } - else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime) - { - auto r = other._rows(); - auto c = other._cols(); + assert(parent::rows() == other.rows() && parent::cols() == other.cols()); + for (rotgen::Index r = 0; r < parent::rows(); ++r) + for (rotgen::Index c = 0; c < parent::cols(); ++c) + (*this)(r, c) = other(r, c); - 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(), - "Block assignment size mismatch"); - 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; } @@ -191,6 +167,13 @@ namespace rotgen block(parent const& base) : parent(base) {} + bool is_contiguous_linear() const + { + if (parent::innerStride() != 1) return false; + if constexpr (IsRowMajor) return parent::outerStride() == parent::cols(); + else return parent::outerStride() == parent::rows(); + } + value_type& operator()(Index i, Index j) requires(!is_immutable) { @@ -200,6 +183,7 @@ namespace rotgen value_type& operator()(Index i) requires(!is_immutable && IsVectorAtCompileTime) { + assert(is_contiguous_linear()); return parent::operator()(i); } @@ -217,6 +201,7 @@ namespace rotgen value_type operator()(Index i) const requires(IsVectorAtCompileTime) { + assert(is_contiguous_linear()); return parent::operator()(i); } @@ -226,69 +211,66 @@ namespace rotgen return (*this)(i); } - concrete_type _evaluate() const { return concrete_type{*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; } - 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 + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + + concrete_type cwiseAbs2() const { - return concrete_type(base()._cwiseAbs()); + return concrete_type(base().cwiseAbs2()); } - concrete_type _cwiseAbs2() const + concrete_type cwiseInverse() const { - return concrete_type(base()._cwiseAbs2()); + return concrete_type(base().cwiseInverse()); } - concrete_type _cwiseInverse() const + concrete_type cwiseSqrt() const { - return concrete_type(base()._cwiseInverse()); + return concrete_type(base().cwiseSqrt()); } - concrete_type _cwiseSqrt() const - { - return concrete_type(base()._cwiseSqrt()); - } - - 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(); } friend bool operator==(block const& lhs, block const& rhs) @@ -296,19 +278,17 @@ namespace rotgen return static_cast(lhs) == static_cast(rhs); } - template - block& operator+=(E const& rhs) + block& operator+=(block const& rhs) requires(!is_immutable) { - base() += rhs.base(); + base() += static_cast(rhs); return *this; } - template - block& operator-=(E const& rhs) + block& operator-=(block const& rhs) requires(!is_immutable) { - base() -= rhs.base(); + base() -= static_cast(rhs); return *this; } @@ -317,11 +297,10 @@ namespace rotgen return concrete_type(static_cast(*this).operator-()); } - template - block& operator*=(E const& rhs) + block& operator*=(block const& rhs) requires(!is_immutable) { - base() *= rhs.base(); + base() *= static_cast(rhs); return *this; } @@ -339,155 +318,154 @@ 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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)); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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); + assert(P == 1 || P == 2 || P == Infinity); + return parent::lpNorm(P); } parent& base() { return static_cast(*this); } @@ -499,41 +477,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/indirect.hpp b/include/rotgen/container/block/dynamic/indirect.hpp index b081f55..ad7ae77 100644 --- a/include/rotgen/container/block/dynamic/indirect.hpp +++ b/include/rotgen/container/block/dynamic/indirect.hpp @@ -2,36 +2,28 @@ #define TYPE double #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #include #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSCLASSNAME #undef TRANSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #include #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSCLASSNAME #undef TRANSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef SIZE #undef TYPE @@ -40,36 +32,28 @@ #define TYPE float #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #include #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSCLASSNAME #undef TRANSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #include #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSCLASSNAME #undef TRANSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef SIZE #undef TYPE diff --git a/include/rotgen/container/block/dynamic/model.hpp b/include/rotgen/container/block/dynamic/model.hpp index f557847..ed04c01 100644 --- a/include/rotgen/container/block/dynamic/model.hpp +++ b/include/rotgen/container/block/dynamic/model.hpp @@ -23,7 +23,6 @@ public: CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(CLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(TRANSCLASSNAME CONST& r, Index i0, Index j0, Index ni, Index nj); - CLASSNAME(TRANSMAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(CLASSNAME const& other); CLASSNAME(CLASSNAME&&) noexcept; @@ -39,61 +38,51 @@ public: void assign(SOURCENAME const&); #endif + Index rows() const; + Index cols() const; Index size() const; - Index _rows() const; - Index _cols() const; + Index innerStride() const; + Index outerStride() const; - Index _innerStride() const; - Index _outerStride() const; + Index startRow() const; + Index startCol() const; - Index _startRow() const; - Index _startCol() const; + SOURCENAME normalized() const; + SOURCENAME transpose() const; + SOURCENAME conjugate() const; + SOURCENAME adjoint() 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; + 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); TYPE& operator()(Index index); CLASSNAME& operator+=(CLASSNAME const& rhs); - CLASSNAME& operator+=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator+=(SOURCENAME const& rhs); - CLASSNAME& operator+=(TRANSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); - CLASSNAME& operator-=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator-=(SOURCENAME const& rhs); - CLASSNAME& operator-=(TRANSNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs); - CLASSNAME& operator*=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator*=(SOURCENAME const& rhs); - CLASSNAME& operator*=(TRANSNAME const& rhs); CLASSNAME& operator*=(TYPE d); CLASSNAME& operator/=(TYPE d); #endif @@ -102,11 +91,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&); @@ -122,23 +111,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 0c4708d..9263b2d 100644 --- a/include/rotgen/container/block/fixed.hpp +++ b/include/rotgen/container/block/fixed.hpp @@ -193,21 +193,25 @@ namespace rotgen parent const& base() const { return static_cast(*this); } - auto _evaluate() const { return concrete_type(base().eval()); } + auto evaluate() const + { + auto res = base().eval(); + return as_concrete_type(res); + } - 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 +220,7 @@ namespace rotgen base().normalized()); } - auto _transpose() const + auto transpose() const { if constexpr (use_expression_templates) return base().transpose(); else @@ -224,14 +228,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,208 +243,208 @@ 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, - "Mismatched between dynamic and static row size"); + 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"); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); 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, - "Mismatched between dynamic and static row size"); + 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"); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); 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, - "Mismatched between dynamic and static row size"); + 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"); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); 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, - "Mismatched between dynamic and static row size"); + 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"); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); 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, - "Mismatched between dynamic and static row size"); + 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"); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); 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,35 +482,25 @@ 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; - Index _cols() const { return parent::cols(); } + auto minCoeff() const { return parent::minCoeff(); } - 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(); } + 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); @@ -516,7 +510,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); @@ -525,23 +519,21 @@ 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) + block& operator+=(block const& rhs) requires(!is_immutable) { - base() += rhs.base(); + static_cast(*this) += static_cast(rhs); return *this; } - template - block& operator-=(E const& rhs) + block& operator-=(block const& rhs) requires(!is_immutable) { - base() -= rhs.base(); + static_cast(*this) -= static_cast(rhs); return *this; } @@ -550,11 +542,10 @@ namespace rotgen return concrete_type(static_cast(*this).operator-()); } - template - block& operator*=(E const& rhs) + block& operator*=(block const& rhs) requires(!is_immutable) { - base() *= rhs.base(); + static_cast(*this) *= static_cast(rhs); return *this; } diff --git a/include/rotgen/container/map/dynamic.hpp b/include/rotgen/container/map/dynamic.hpp index 30d0dab..e9c7b55 100644 --- a/include/rotgen/container/map/dynamic.hpp +++ b/include/rotgen/container/map/dynamic.hpp @@ -7,14 +7,14 @@ //================================================================================================== #pragma once -#include #include -#include #include #include #include +#include + namespace rotgen { namespace detail @@ -35,7 +35,6 @@ namespace rotgen using parent = find_map; using rotgen_tag = void; - using rotgen_map_tag = void; using value_type = typename std::remove_const_t::value_type; using concrete_type = typename std::remove_const_t::concrete_type; @@ -53,7 +52,6 @@ namespace rotgen static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; - static constexpr int SizeAtCompileTime = Ref::SizeAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool is_defined_static = RowsAtCompileTime != -1 && ColsAtCompileTime != -1; @@ -77,12 +75,12 @@ namespace rotgen : parent(ptr, r, c, strides(s, r, c)) { if constexpr (RowsAtCompileTime != -1) - ROTGEN_ASSERT(r == RowsAtCompileTime, - "Mismatched between dynamic and static row size"); + 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"); + assert(c == ColsAtCompileTime && + "Mismatched between dynamic and static column size"); } // Used to properly delay ref dynamic construction @@ -97,13 +95,8 @@ 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); }()) { } @@ -132,9 +125,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()}) { } @@ -142,52 +135,26 @@ namespace rotgen map(map const& other) : parent(other) {} - map(map&& other) : parent(std::move(other)) {} - map& operator=(map const& other) requires(!is_immutable) { - base() = other.base(); + base() = static_cast(other); return *this; } - map& operator=(map&& other) + map& operator=(concepts::entity auto const& other) requires(!is_immutable) { - base() = std::move(other.base()); - return *this; - } - - template - map& operator=(Src const& other) - requires(!is_immutable) - { - if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime) + assert(parent::rows() == other.rows() && parent::cols() == other.cols()); + if constexpr (IsVectorAtCompileTime) { - ROTGEN_ASSERT(parent::size() == other.size(), - "Map assignment from 1D source doesn't match size"); for (rotgen::Index i = 0; i < parent::size(); ++i) - (*this)[i] = other[i]; - } - else if constexpr (IsVectorAtCompileTime && !Src::IsVectorAtCompileTime) - { - auto r = other._rows(); - auto c = other._cols(); - - ROTGEN_ASSERT( - r == 1 || c == 1, - "Map 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); + (*this)(i) = other(i); } else { - 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); } @@ -229,89 +196,86 @@ namespace rotgen return (*this)(i); } - concrete_type _evaluate() const { return concrete_type{*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; } - 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 + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + + concrete_type cwiseAbs2() const { - return concrete_type(base()._cwiseAbs()); + return concrete_type(base().cwiseAbs2()); } - concrete_type _cwiseAbs2() const + concrete_type cwiseInverse() const { - return concrete_type(base()._cwiseAbs2()); + return concrete_type(base().cwiseInverse()); } - concrete_type _cwiseInverse() const + concrete_type cwiseSqrt() const { - return concrete_type(base()._cwiseInverse()); + return concrete_type(base().cwiseSqrt()); } - concrete_type _cwiseSqrt() const + concrete_type cwiseMin(map const& rhs) const { - return concrete_type(base()._cwiseSqrt()); + return concrete_type(base().cwiseMin(rhs.base())); } - concrete_type _cwiseMin(map const& rhs) const + concrete_type cwiseMax(map const& rhs) const { - return concrete_type(base()._cwiseMin(rhs.base())); + return concrete_type(base().cwiseMax(rhs.base())); } - concrete_type _cwiseMax(map const& rhs) const + concrete_type cwiseQuotient(map const& rhs) const { - return concrete_type(base()._cwiseMax(rhs.base())); + return concrete_type(base().cwiseQuotient(rhs.base())); } - concrete_type _cwiseQuotient(map const& rhs) const + concrete_type cwiseProduct(map const& rhs) const { - return concrete_type(base()._cwiseQuotient(rhs.base())); + return concrete_type(base().cwiseProduct(rhs.base())); } - concrete_type _cwiseProduct(map const& rhs) const + concrete_type cwiseMin(value_type s) const { - return concrete_type(base()._cwiseProduct(rhs.base())); + return concrete_type(base().cwiseMin(s)); } - concrete_type _cwiseMin(value_type s) const + concrete_type cwiseMax(value_type s) const { - return concrete_type(base()._cwiseMin(s)); + return concrete_type(base().cwiseMax(s)); } - concrete_type _cwiseMax(value_type s) const - { - return concrete_type(base()._cwiseMax(s)); - } + concrete_type inverse() const { return concrete_type(base().inverse()); } - concrete_type _inverse() const { return concrete_type(base()._inverse()); } - - concrete_type _cross(map const& other) const + concrete_type cross(map const& other) const { concrete_type that; - if constexpr (ColsAtCompileTime == 1) + if constexpr (RowsAtCompileTime == -1) { that(0, 0) = (*this)(1, 0) * other(2, 0) - (*this)(2, 0) * other(1, 0); that(1, 0) = (*this)(2, 0) * other(0, 0) - (*this)(0, 0) * other(2, 0); @@ -326,29 +290,28 @@ 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 map& operator+=(map const& rhs) requires(!is_immutable) { - validate_compound_operator(rhs); base() += rhs.base(); return *this; } @@ -357,7 +320,6 @@ namespace rotgen map& operator-=(map const& rhs) requires(!is_immutable) { - validate_compound_operator(rhs); base() -= rhs.base(); return *this; } @@ -371,9 +333,6 @@ namespace rotgen map& operator*=(map const& rhs) requires(!is_immutable) { - ROTGEN_ASSERT(parent::_cols() == rhs._rows() && - parent::_cols() == rhs._cols(), - "Incompatible dimensions for compound matrix-product"); base() *= rhs.base(); return *this; } @@ -392,121 +351,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 scalar) + map& setConstant(value_type s) requires(!is_immutable) { - parent::_setConstant(scalar); + parent::setConstant(s); 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); + assert(P == 1 || P == 2 || P == Infinity); + return parent::lpNorm(P); } parent& base() { return static_cast(*this); } @@ -517,32 +476,6 @@ namespace rotgen { return concrete_type(base().qr_solve(rhs.base())); }; - - template - void validate_compound_operator(map const& rhs) - { - if constexpr (IsVectorAtCompileTime && R2::IsVectorAtCompileTime) - { - if constexpr (is_defined_static && R2::is_defined_static) - { - static_assert( - SizeAtCompileTime == R2::SizeAtCompileTime, - "Compile-time size mismatch in compound assignment operator"); - } - else - { - ROTGEN_ASSERT(parent::size() == rhs.size(), - "Size mismatch in compound assignment operator"); - } - } - else - { - ROTGEN_ASSERT(parent::_rows() == rhs._rows(), - "Mismatched rows count in compound assignment operator"); - ROTGEN_ASSERT(parent::_cols() == rhs._cols(), - "Mismatched cols count in compound assignment operator"); - } - } }; template @@ -552,7 +485,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 @@ -562,34 +495,22 @@ 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 - auto operator*(map const& lhs, map const& rhs) + matrix + operator*(map const& lhs, map const& rhs) { using map1_type = map; using map2_type = map; using concrete_type = matrix; - if constexpr (concrete_type::SizeAtCompileTime == 0) - { - return concrete_type{}; - } - else - { - 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; - } - } + return concrete_type(map1_type(lhs).base().mul(map2_type(rhs).base())); } template @@ -597,7 +518,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 @@ -605,7 +526,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 @@ -613,7 +534,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/indirect.hpp b/include/rotgen/container/map/dynamic/indirect.hpp index ebd2801..90e0c50 100644 --- a/include/rotgen/container/map/dynamic/indirect.hpp +++ b/include/rotgen/container/map/dynamic/indirect.hpp @@ -3,39 +3,27 @@ #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #include #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef SOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #include #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef SOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef SIZE #undef TYPE @@ -45,39 +33,27 @@ #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #include #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef SOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #include #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef SOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef SIZE #undef TYPE diff --git a/include/rotgen/container/map/dynamic/model.hpp b/include/rotgen/container/map/dynamic/model.hpp index 4c41423..7790efd 100644 --- a/include/rotgen/container/map/dynamic/model.hpp +++ b/include/rotgen/container/map/dynamic/model.hpp @@ -28,53 +28,50 @@ public: ~CLASSNAME(); + Index rows() const; + Index cols() const; Index size() const; - Index _rows() const; - Index _cols() const; + Index innerStride() const; + Index outerStride() const; - Index _innerStride() const; - Index _outerStride() const; + SOURCENAME normalized() const; + SOURCENAME transpose() const; + SOURCENAME conjugate() const; + SOURCENAME adjoint() 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; - 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; + 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(CLASSNAME const&) const; + TYPE dot(TRANSCLASSNAME 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; @@ -89,31 +86,25 @@ public: #if !defined(USE_CONST) CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator+=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator+=(TRANSCLASSCONSTNAME const& rhs); - CLASSNAME& operator+=(TRANSCLASSNONCONSTNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator-=(TRANSCLASSCONSTNAME const& rhs); - CLASSNAME& operator-=(TRANSCLASSNONCONSTNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs); CLASSNAME& operator*=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator*=(TRANSCLASSCONSTNAME const& rhs); - CLASSNAME& operator*=(TRANSCLASSNONCONSTNAME const& rhs); CLASSNAME& operator*=(TYPE d); CLASSNAME& operator/=(TYPE d); #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&); @@ -123,11 +114,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 ad65b8d..70af3a2 100644 --- a/include/rotgen/container/map/fixed.hpp +++ b/include/rotgen/container/map/fixed.hpp @@ -7,8 +7,6 @@ //================================================================================================== #pragma once -#include - #include #include @@ -43,7 +41,6 @@ namespace rotgen { public: using rotgen_tag = void; - using rotgen_map_tag = void; using parent = detail:: map_type, Options, std::is_const_v, Stride>; using value_type = typename std::remove_const_t::value_type; @@ -53,7 +50,6 @@ namespace rotgen static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; - static constexpr int SizeAtCompileTime = Ref::SizeAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool has_static_storage = Ref::has_static_storage; static constexpr bool IsRowMajor = Ref::IsRowMajor; @@ -116,33 +112,29 @@ namespace rotgen return *this; } - template - map& operator=(Eigen::MatrixBase const& other) - { - parent::operator=(other); - return *this; - } - - template - map& operator=(Eigen::EigenBase const& other) - { - parent::operator=(other); - return *this; - } - parent& base() { return static_cast(*this); } parent const& base() const { return static_cast(*this); } - auto _evaluate() const { return concrete_type(base().eval()); } + auto evaluate() const + { + auto res = static_cast(*this).eval(); + return as_concrete_type(res); + } - decltype(auto) _noalias() const + auto evaluate() + { + auto res = static_cast(*this).eval(); + return as_concrete_type(res); + } + + 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; @@ -184,7 +176,6 @@ namespace rotgen map& operator+=(map const& rhs) requires(!is_immutable) { - validate_compound_operator(rhs); base() += rhs.base(); return *this; } @@ -193,7 +184,6 @@ namespace rotgen map& operator-=(map const& rhs) requires(!is_immutable) { - validate_compound_operator(rhs); base() -= rhs.base(); return *this; } @@ -202,9 +192,6 @@ namespace rotgen map& operator*=(map const& rhs) requires(!is_immutable) { - ROTGEN_ASSERT(parent::cols() == rhs.rows() && - parent::cols() == rhs.cols(), - "Incompatible dimensions for compound matrix-product"); base() *= rhs.base(); return *this; } @@ -221,91 +208,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 +301,7 @@ namespace rotgen base().normalized()); } - auto _transpose() const + auto transpose() const { if constexpr (use_expression_templates) return base().transpose(); else @@ -322,14 +309,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,126 +324,116 @@ 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; - Index _cols() const { return parent::cols(); } + auto minCoeff() const { return parent::minCoeff(); } - 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(); } + 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); @@ -466,7 +443,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); @@ -476,42 +453,16 @@ 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

(); } - - template - void validate_compound_operator(map const& rhs) - { - if constexpr (IsVectorAtCompileTime && R2::IsVectorAtCompileTime) - { - if constexpr (is_defined_static && R2::is_defined_static) - { - static_assert( - SizeAtCompileTime == R2::SizeAtCompileTime, - "Compile-time size mismatch in compound assignment operator"); - } - else - { - ROTGEN_ASSERT(parent::size() == rhs.size(), - "Size mismatch in compound assignment operator"); - } - } - else - { - ROTGEN_ASSERT(parent::rows() == rhs.rows(), - "Mismatched rows count in compound assignment operator"); - ROTGEN_ASSERT(parent::cols() == rhs.cols(), - "Mismatched cols count in compound assignment operator"); - } - } }; template @@ -583,14 +534,13 @@ namespace rotgen } template - auto operator*(map const& lhs, map const& rhs) + matrix + operator*(map const& lhs, map const& rhs) { - auto p = lhs.base() * rhs.base(); - using concrete_type = detail::as_concrete_t; + using concrete_type = matrix; - if constexpr (concrete_type::SizeAtCompileTime == 1) - return product{concrete_type{p}}; - else return concrete_type{p}; + return concrete_type(lhs.base() * rhs.base()); } template diff --git a/include/rotgen/container/matrix/dynamic.hpp b/include/rotgen/container/matrix/dynamic.hpp index dd323f3..ae0d1a6 100644 --- a/include/rotgen/container/matrix/dynamic.hpp +++ b/include/rotgen/container/matrix/dynamic.hpp @@ -7,12 +7,11 @@ //================================================================================================== #pragma once -#include #include - #include #include +#include #include namespace rotgen @@ -28,7 +27,6 @@ namespace rotgen public: using parent = find_matrix; using rotgen_tag = void; - using rotgen_matrix_tag = void; using concrete_type = matrix; using value_type = Scalar; @@ -50,40 +48,29 @@ namespace rotgen static constexpr bool has_static_storage = false; static constexpr bool is_immutable = false; static constexpr int InnerStrideAtCompileTime = 1; - static constexpr int OuterStrideAtCompileTime = IsRowMajor ? Cols : Rows; + static constexpr int OuterStrideAtCompileTime = + IsRowMajor ? ColsAtCompileTime : RowsAtCompileTime; using transposed_type = matrix; - static constexpr int AllocatedRows = - Rows == -1 ? (MaxRows == -1 ? 0 : MaxRows) : Rows; - static constexpr int AllocatedCols = - Cols == -1 ? (MaxCols == -1 ? 0 : MaxCols) : Cols; - - matrix() : parent(AllocatedRows, AllocatedCols) {} + matrix() : parent(Rows == -1 ? 0 : Rows, Cols == -1 ? 0 : Cols) {} matrix(Index r, Index c) : parent(r, c) { if constexpr (Rows != -1) - ROTGEN_ASSERT(r == Rows, - "Mismatched between dynamic and static row size"); + assert(r == Rows && "Mismatched between dynamic and static row size"); if constexpr (Cols != -1) - ROTGEN_ASSERT(c == Cols, - "Mismatched between dynamic and static column size"); + assert(c == Cols && + "Mismatched between dynamic and static column size"); } matrix(Index n) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) - : parent(Rows != 1 ? n : 1, Cols != 1 ? n : 1) + : parent(Rows != -1 ? 1 : n, Cols != -1 ? 1 : n) { - if constexpr (Rows == 1 && Cols != -1) - ROTGEN_ASSERT(Cols == n, - "Mismatched between dynamic and static col size"); - if constexpr (Cols == 1 && Rows != -1) - ROTGEN_ASSERT(Rows == n, - "Mismatched between dynamic and static row size"); } - explicit matrix(Scalar v) + matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent(1, 1, {v}) { @@ -102,14 +89,14 @@ namespace rotgen : parent(init) { if constexpr (Rows != -1) - ROTGEN_ASSERT(init.size() == Rows, - "Mismatched between dynamic and static row size"); + assert(init.size() == Rows && + "Mismatched between dynamic and static row size"); if constexpr (Cols != -1) { [[maybe_unused]] Index c = 0; if (init.size()) c = init.begin()->size(); - ROTGEN_ASSERT(c == Cols, - "Mismatched between dynamic and static column size"); + assert(c == Cols && + "Mismatched between dynamic and static column size"); } } @@ -119,28 +106,31 @@ namespace rotgen { } - template matrix(Src const& other) : parent() + matrix(concepts::entity auto const& e) : parent(e.rows(), e.cols()) { - if constexpr (IsVectorAtCompileTime && Src::IsVectorAtCompileTime) - { - resize(other.size()); - for (rotgen::Index i = 0; i < parent::size(); ++i) - (*this)[i] = other[i]; - } - else - { - resize(other._rows(), other._cols()); - - for (rotgen::Index r = 0; r < parent::_rows(); ++r) - for (rotgen::Index c = 0; c < parent::_cols(); ++c) - (*this)(r, c) = other(r, c); - } + if constexpr (Rows != -1) + assert(e.rows() == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(e.cols() == Cols && + "Mismatched between dynamic and static col size"); + for (rotgen::Index r = 0; r < e.rows(); ++r) + for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c); } - matrix& operator=(concepts::entity auto const& other) + matrix& operator=(concepts::entity auto const& e) { - matrix local(other); - swap(local); + if constexpr (Rows != -1) + assert(e.rows() == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(e.cols() == Cols && + "Mismatched between dynamic and static col size"); + resize(e.rows(), e.cols()); + + for (rotgen::Index r = 0; r < e.rows(); ++r) + for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c); + return *this; } @@ -156,39 +146,27 @@ namespace rotgen return (*this)(i); } - void swap(matrix& other) + auto evaluate() const { return *this; } + + decltype(auto) noalias() const { return *this; } + + decltype(auto) noalias() { return *this; } + + Index innerStride() const noexcept { return 1; } + + Index outerStride() const noexcept { - // TODO: Swap elements per elements if statically defined to preserve - // data location in memory as with actual statically defines matrix - base().swap(other.base()); - } - - auto _evaluate() const { return *this; } - - decltype(auto) _noalias() const { return *this; } - - decltype(auto) _noalias() { return *this; } - - Index _innerStride() const noexcept { return 1; } - - Index _outerStride() const noexcept - { - if constexpr (IsVectorAtCompileTime) return this->size(); - else - { - if constexpr (IsRowMajor) return this->_cols(); - else return this->_rows(); - } + return IsVectorAtCompileTime ? this->size() + : IsRowMajor ? this->cols() + : this->rows(); } void resize(int r, int c) { - if constexpr (Cols != -1) - ROTGEN_ASSERT(c == Cols, - "Mismatched between dynamic and static col size"); - if constexpr (Rows != -1) - ROTGEN_ASSERT(r == Rows, - "Mismatched between dynamic and static row size"); + if constexpr (Rows == 1) + assert(c == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(r == Rows && "Mismatched between dynamic and static row size"); parent::resize(r, c); } @@ -199,82 +177,80 @@ 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, - "Mismatched between dynamic and static col size"); - if constexpr (Rows != -1) - ROTGEN_ASSERT(r == Rows, - "Mismatched between dynamic and static row size"); - parent::_conservativeResize(r, c); + if constexpr (Rows == 1) + assert(c == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(r == Rows && "Mismatched between dynamic and static row size"); + 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) { - return lhs.base() == rhs.base(); + return static_cast(lhs) == static_cast(rhs); } matrix& operator+=(matrix const& rhs) { - base() += rhs.base(); + base() += static_cast(rhs); return *this; } matrix& operator-=(matrix const& rhs) { - base() -= rhs.base(); + base() -= static_cast(rhs); return *this; } - matrix operator-() const { return -base(); } + matrix operator-() const { return matrix(base().operator-()); } matrix& operator*=(matrix const& rhs) { - base() *= rhs.base(); + base() *= static_cast(rhs); return *this; } @@ -290,184 +266,231 @@ 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, - "Mismatched between dynamic and static row size"); + 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); + 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); + 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"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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)); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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, - "Mismatched between dynamic and static row size"); + 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); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + 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); } parent const& base() const { return static_cast(*this); } }; + + template + matrix operator+(matrix const& lhs, + matrix const& rhs) + { + matrix that(lhs); + return that += rhs; + } + + template + matrix operator-(matrix const& lhs, + matrix const& rhs) + { + matrix that(lhs); + return that -= rhs; + } + + template + matrix operator*(matrix const& lhs, + matrix const& rhs) + { + matrix that(lhs); + return that *= rhs; + } + + template + matrix operator*(matrix const& lhs, + double rhs) + { + matrix that(lhs); + return that *= rhs; + } + + template + matrix operator*(double lhs, + matrix const& rhs) + { + return rhs * lhs; + } + + template + matrix operator/(matrix const& lhs, + double rhs) + { + matrix that(lhs); + return that /= rhs; + } } diff --git a/include/rotgen/container/matrix/dynamic/model.hpp b/include/rotgen/container/matrix/dynamic/model.hpp index 3ee4d66..2520239 100644 --- a/include/rotgen/container/matrix/dynamic/model.hpp +++ b/include/rotgen/container/matrix/dynamic/model.hpp @@ -28,40 +28,39 @@ 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; @@ -88,19 +87,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 swap(CLASSNAME& other) { storage_.swap(other.storage_); } + 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); private: struct payload; diff --git a/include/rotgen/container/matrix/fixed.hpp b/include/rotgen/container/matrix/fixed.hpp index 4f96209..6c11b67 100644 --- a/include/rotgen/container/matrix/fixed.hpp +++ b/include/rotgen/container/matrix/fixed.hpp @@ -7,7 +7,6 @@ //================================================================================================== #pragma once -#include #include #include @@ -41,7 +40,6 @@ namespace rotgen { public: using rotgen_tag = void; - using rotgen_matrix_tag = void; using parent = detail::storage_type; using value_type = Scalar; @@ -51,9 +49,6 @@ namespace rotgen using concrete_type = matrix; using concrete_dynamic_type = matrix; - using exact_base = - Eigen::Matrix; - static constexpr int RowsAtCompileTime = Rows; static constexpr int ColsAtCompileTime = Cols; static constexpr int SizeAtCompileTime = detail::static_size(); @@ -80,11 +75,6 @@ namespace rotgen static constexpr bool has_static_storage = storage_status; - static constexpr int AllocatedRows = - Rows == -1 ? (MaxRows == -1 ? 0 : MaxRows) : Rows; - static constexpr int AllocatedCols = - Cols == -1 ? (MaxCols == -1 ? 0 : MaxCols) : Cols; - public: matrix() requires(has_static_storage) @@ -93,23 +83,19 @@ namespace rotgen matrix() requires(!has_static_storage) - : parent(AllocatedRows, AllocatedCols) + : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0) { } matrix(Index r, Index c) : parent(r, c) { if constexpr (RowsAtCompileTime != -1) - { - ROTGEN_ASSERT(r == RowsAtCompileTime, - "Mismatched between dynamic and static row size"); - } + 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"); - } + assert(c == ColsAtCompileTime && + "Mismatched between dynamic and static column size"); } matrix(matrix const& other) = default; @@ -131,11 +117,8 @@ 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; @@ -144,18 +127,12 @@ 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) @@ -197,34 +174,35 @@ 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; } - - decltype(auto) _noalias() const + auto evaluate() const { - if constexpr (use_expression_templates) { return base().noalias(); } - else - { - return *this; - } + auto res = base().eval(); + return as_concrete_type(res); } - decltype(auto) _noalias() + 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; } - auto _normalized() const + decltype(auto) noalias() + { + if constexpr (use_expression_templates) return base().noalias(); + else return *this; + } + + 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(); @@ -232,9 +210,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(); @@ -242,232 +220,180 @@ 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 new_size) + void resize(int s) requires(IsVectorAtCompileTime) { - if constexpr (Rows == 1) { parent::resize(1, new_size); } - else - { - parent::resize(new_size, 1); - } + if constexpr (Rows == 1) + assert(s == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(s == Rows && "Mismatched between dynamic and static row size"); + parent::resize(s); } - void resize(int new_row_count, int new_col_count) + void resize(int r, int c) { - if constexpr (Cols != -1) - { - ROTGEN_ASSERT(new_col_count == Cols, - "Mismatched between dynamic and static col size"); - } - if constexpr (Rows != -1) - { - ROTGEN_ASSERT(new_row_count == Rows, - "Mismatched between dynamic and static row size"); - } - parent::resize(new_row_count, new_col_count); + if constexpr (Rows == 1) + assert(c == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(r == Rows && "Mismatched between dynamic and static row size"); + parent::resize(r, c); } - void _conservativeResize(int new_size) + void conservativeResize(int s) requires(IsVectorAtCompileTime) { - if constexpr (Rows == 1) { parent::conservativeResize(1, new_size); } - else - { - parent::conservativeResize(new_size, 1); - } + if constexpr (Rows == 1) + assert(s == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(s == Rows && "Mismatched between dynamic and static row size"); + parent::conservativeResize(s); } - void _conservativeResize(int new_row_count, int new_col_count) + void conservativeResize(int r, int c) { - if constexpr (Cols != -1) - { - ROTGEN_ASSERT(new_col_count == Cols, - "Mismatched between dynamic and static col size"); - } - if constexpr (Rows != -1) - { - ROTGEN_ASSERT(new_row_count == Rows, - "Mismatched between dynamic and static row size"); - } - parent::conservativeResize(new_row_count, new_col_count); + if constexpr (Rows == 1) + assert(c == Cols && "Mismatched between dynamic and static col size"); + if constexpr (Cols == 1) + assert(r == Rows && "Mismatched between dynamic and static row size"); + parent::conservativeResize(r, c); } - static matrix _Constant(Scalar value) + static matrix Constant(Scalar value) requires(Rows != -1 && Cols != -1) { - return parent::Constant(Rows, Cols, 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, - "Mismatched between dynamic and static row size"); - } + 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, value); + assert(cols == Cols && + "Mismatched between dynamic and static column size"); + return parent::Constant(rows, cols, static_cast(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"); - } + 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"); - } + 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"); - } + 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"); - } + 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"); - } + 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"); - } + 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"); - } + 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"); - } + 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

(); @@ -486,111 +412,96 @@ 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; - Index _cols() const { return parent::cols(); } + auto minCoeff() const { return parent::minCoeff(); } - 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(); } + auto maxCoeff() const { return parent::maxCoeff(); } template - auto _minCoeff(IndexType* row, IndexType* col) const + 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; + Index 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 result_row, result_col; - auto result = parent::maxCoeff(&result_row, &result_col); - *row = result_row; - *col = result_col; + Index r, c; + auto result = parent::maxCoeff(&r, &c); + *row = r; + *col = c; 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(), value); + *this = parent::Constant(rows(), cols(), static_cast(value)); return *this; } - matrix& _setConstant(int r, int c, Scalar value) + matrix& setConstant(int r, int c, Scalar value) { - *this = parent::Constant(r, c, value); + *this = parent::Constant(r, c, static_cast(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; @@ -608,7 +519,7 @@ namespace rotgen return *this; } - matrix operator-() const { return -base(); } + matrix operator-() const { return matrix(base()(*this).operator-()); } matrix& operator*=(matrix const& rhs) { diff --git a/include/rotgen/container/ref.hpp b/include/rotgen/container/ref.hpp index 001dbbb..2d99197 100644 --- a/include/rotgen/container/ref.hpp +++ b/include/rotgen/container/ref.hpp @@ -7,13 +7,12 @@ //================================================================================================== #pragma once -#include - #include #include #include #include +#include #include #include diff --git a/include/rotgen/container/ref/dynamic.hpp b/include/rotgen/container/ref/dynamic.hpp index d861853..015e587 100644 --- a/include/rotgen/container/ref/dynamic.hpp +++ b/include/rotgen/container/ref/dynamic.hpp @@ -7,8 +7,7 @@ //================================================================================================== #pragma once -#include - +#include #include #if !defined(ROTGEN_FORCE_DYNAMIC) @@ -16,7 +15,6 @@ #endif #include -#include namespace rotgen { @@ -60,33 +58,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,30 +126,29 @@ 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-; template auto qr_solve(ref rhs) const @@ -169,18 +166,12 @@ namespace rotgen parent& as_map() { return base(); } - template - requires(is_immutable) - ref(product const& m) : ref(m.storage_) - { - } - template requires(detail::accept_as_ref>) ref(matrix& m) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, m); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } template @@ -211,7 +202,7 @@ namespace rotgen ref(block&& b) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } template @@ -219,7 +210,7 @@ namespace rotgen ref(block& b) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } template @@ -238,7 +229,7 @@ namespace rotgen ref(map& b) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } template @@ -268,15 +259,15 @@ namespace rotgen ref(ref& b) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } template - requires(detail::accept_as_ref>) + requires(detail::same_scalar>) ref(ref const& b) : parent(detail::postpone{}) { [[maybe_unused]] bool correct_ref_setup = detail::validate_ref(*this, b); - ROTGEN_ASSERT(correct_ref_setup, "Invalid reference binding"); + assert(correct_ref_setup); } ref(parent& m) : parent(m.data(), m.rows(), m.cols()) {} @@ -348,70 +339,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 b4974a0..3d5521d 100644 --- a/include/rotgen/container/ref/fixed.hpp +++ b/include/rotgen/container/ref/fixed.hpp @@ -8,7 +8,6 @@ #pragma once #include -#include #include #include @@ -53,9 +52,6 @@ namespace rotgen template using compile_ref_t = typename compile_ref::type; - - template - using compile_base_t = typename compile_ref::base; } template @@ -63,7 +59,6 @@ namespace rotgen { public: using parent = detail::compile_ref_t; - using exact_base = detail::compile_base_t; using referee = std::remove_const_t; using value_type = typename referee::value_type; using rotgen_tag = void; @@ -86,99 +81,56 @@ namespace rotgen // Access to values using parent::operator(); using parent::operator[]; - using parent::data; - using parent::size; // Size related functions - - 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(); }; + using parent::cols; + using parent::data; + using parent::innerStride; + using parent::outerStride; + using parent::rows; + using parent::size; // Aliasing handling + auto evaluate() const + { + auto res = static_cast(*this).eval(); + return as_concrete_type(res); + } - auto _evaluate() const { return T(base().eval()); } + auto evaluate() + { + auto res = static_cast(*this).eval(); + return as_concrete_type(res); + } - 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; } // Numeric functions - auto operator-() const { return detail::concretize(-base()); } - - auto _cwiseAbs() const - { - return detail::concretize(base().cwiseAbs()); - } - - auto _cwiseAbs2() const - { - return detail::concretize(base().cwiseAbs2()); - } - - auto _cwiseInverse() const - { - return detail::concretize(base().cwiseInverse()); - } - - auto _cwiseSqrt() const - { - return detail::concretize(base().cwiseSqrt()); - } + using parent::cwiseAbs; + using parent::cwiseAbs2; + using parent::cwiseInverse; + using parent::cwiseSqrt; // Reductions - value_type _mean() const { return parent::mean(); } - - value_type _norm() const { return parent::norm(); } - - template value_type _lpNorm() const - { - return parent::template 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; - } + 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; // Compound Operators template @@ -220,113 +172,27 @@ namespace rotgen } // Shape modifications - auto _normalized() const - requires(IsVectorAtCompileTime) - { - return detail::concretize(base().normalized()); - } - - auto _transpose() const - { - return detail::concretize(base().transpose()); - } - - auto _adjoint() const - { - return detail::concretize(base().adjoint()); - } - - auto _conjugate() const - { - return detail::concretize(base().conjugate()); - } + using parent::adjoint; + using parent::conjugate; + using parent::normalized; + using parent::transpose; // In-place Shape modifications - - void _adjointInPlace() { parent::adjointInPlace(); } - - void _normalize() - requires(IsVectorAtCompileTime) - { - parent::normalize(); - } - - void _transposeInPlace() { parent::transposeInPlace(); } + using parent::adjointInPlace; + using parent::normalize; + using parent::transposeInPlace; // Generators - static auto _Zero() { return detail::concretize(parent::Zero()); } - - 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(int rows, int cols) - { - return detail::concretize(parent::Ones(rows, cols)); - } - - static auto _Constant(value_type value) - { - return detail::concretize(parent::Constant(value)); - } - - static auto _Constant(int rows, int cols, value_type value) - { - return detail::concretize(parent::Constant(rows, cols, value)); - } - - static auto _Random() - { - return detail::concretize(parent::Random()); - } - - static auto _Random(int rows, int cols) - { - return detail::concretize(parent::Random(rows, cols)); - } - - static auto _Identity() - { - return detail::concretize(parent::Identity()); - } - - static auto _Identity(int rows, int cols) - { - return detail::concretize(parent::Identity(rows, cols)); - } - - ref& _setOnes() - { - base() = parent::Ones(base().rows(), base().cols()); - return *this; - } - - ref& _setZero() - { - base() = parent::Zero(base().rows(), base().cols()); - return *this; - } - - ref& _setConstant(value_type value) - { - base() = parent::Constant(base().rows(), base().cols(), value); - return *this; - } - - ref& _setRandom() - { - base() = parent::Random(base().rows(), base().cols()); - return *this; - } - - ref& _setIdentity() - { - base() = parent::Identity(base().rows(), base().cols()); - return *this; - } + 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; auto qr_solve(auto const& rhs) const { @@ -346,12 +212,6 @@ namespace rotgen parent& base() { return static_cast(*this); } - template - requires(is_immutable) - ref(product const& m) : ref(m.storage_) - { - } - template ref(matrix& m) requires(requires { parent(m.base()); }) @@ -447,14 +307,13 @@ namespace rotgen // Deduction Guides //============================================================================ template - ref(matrix&) -> ref>; + ref(matrix&) -> ref>; template ref(block& b) -> ref; template - ref(matrix const&) - -> ref const>; + ref(matrix const&) -> ref const>; template ref(block const& b) -> ref; @@ -477,14 +336,7 @@ namespace rotgen template auto operator*(ref lhs, ref rhs) { - auto p = lhs.base() * rhs.base(); - using concrete_type = detail::as_concrete_t; - - if constexpr (concrete_type::SizeAtCompileTime == 1) - return product{concrete_type{p}}; - else if constexpr (concrete_type::SizeAtCompileTime == 0) - return concrete_type{}; - else return concrete_type{p}; + return detail::concretize(lhs.base() * rhs.base()); } template @@ -559,6 +411,7 @@ namespace rotgen template auto cross(ref lhs, ref rhs) + -> decltype(lhs.base().cross(rhs.base())) { return detail::concretize(lhs.base().cross(rhs.base())); } @@ -579,8 +432,13 @@ namespace rotgen using type = std::conditional_t, ref>; }; - template decltype(auto) base_of(T&& a) + template auto const& base_of(T const& a) { - return ROTGEN_FWD(a); + return a; + } + + template auto& base_of(T& a) + { + return a; } } diff --git a/include/rotgen/container/ref/functions.hpp b/include/rotgen/container/ref/functions.hpp index e8425a1..4fa278d 100644 --- a/include/rotgen/container/ref/functions.hpp +++ b/include/rotgen/container/ref/functions.hpp @@ -7,67 +7,51 @@ //================================================================================================== #pragma once -#include - #include namespace rotgen { template - bool operator==(ref const& lhs, ref const& rhs) + bool operator==(ref lhs, ref rhs) { return lhs.base() == rhs.base(); } template - bool operator!=(ref const& lhs, ref const& rhs) + bool operator!=(ref lhs, ref rhs) { return lhs.base() != rhs.base(); } template auto operator*(std::convertible_to auto s, - ref const& rhs) + ref rhs) { - // void* _ = rhs; return rhs * s; } template - auto dot(ref const& lhs, ref const& rhs) + auto dot(ref lhs, ref rhs) { - 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(); - } + return lhs.base().dot(rhs.base()); } template - auto mul(ref const& lhs, - std::convertible_to auto s) + auto mul(ref lhs, std::convertible_to auto s) -> decltype(lhs * s) { return lhs * s; } template - auto mul(std::convertible_to auto s, - ref const& rhs) -> decltype(s * rhs) + auto mul(std::convertible_to auto s, ref rhs) + -> decltype(s * rhs) { return s * rhs; } template - auto div(ref const& lhs, - std::convertible_to auto s) + auto div(ref lhs, std::convertible_to auto s) -> decltype(lhs / s) { return lhs / s; diff --git a/include/rotgen/container/ref/generalize.hpp b/include/rotgen/container/ref/generalize.hpp index 855f452..b5ad520 100644 --- a/include/rotgen/container/ref/generalize.hpp +++ b/include/rotgen/container/ref/generalize.hpp @@ -1,16 +1,13 @@ -//============================================================================== +//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//============================================================================== +//================================================================================================== #pragma once -#include #include -#include -#include #include @@ -18,7 +15,7 @@ namespace rotgen { template class quaternion; - //---------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------- // Convert entity/eigen types to a proper ref so we can write less function // overloads @@ -35,12 +32,11 @@ namespace rotgen template struct generalize { - static constexpr bool is_const = - std::is_const_v>; - using base = matrix::value_type, - std::remove_cvref_t::RowsAtCompileTime, - std::remove_cvref_t::ColsAtCompileTime, - std::remove_cvref_t::storage_order>; + static constexpr bool is_const = std::is_const_v; + using base = matrix; using type = std::conditional_t, ref>; }; diff --git a/include/rotgen/detail/accept_as_ref.hpp b/include/rotgen/detail/accept_as_ref.hpp index 89c29de..0d71a22 100644 --- a/include/rotgen/detail/accept_as_ref.hpp +++ b/include/rotgen/detail/accept_as_ref.hpp @@ -7,10 +7,7 @@ //================================================================================================== #pragma once -#include - -#include - +#include #include namespace rotgen::detail @@ -75,34 +72,30 @@ namespace rotgen::detail using parent = typename Ref::parent; using map_base = typename parent::parent; - auto r = rows(in); - auto c = cols(in); + auto rows = in.rows(); + auto cols = in.cols(); if (Ref::RowsAtCompileTime == 1) { - ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, - "Incompatible rows/cols in ref binding"); - r = 1; - c = in.size(); + assert(in.rows() == 1 || in.cols() == 1); + rows = 1; + cols = in.size(); } else if (Ref::ColsAtCompileTime == 1) { - ROTGEN_ASSERT(rows(in) == 1 || cols(in) == 1, - "Incompatible rows/cols in ref binding"); - r = in.size(); - c = 1; + assert(in.rows() == 1 || in.cols() == 1); + rows = in.size(); + cols = 1; } // Verify that the sizes are valid. - ROTGEN_ASSERT((Ref::RowsAtCompileTime == Dynamic) || - (Ref::RowsAtCompileTime == r), - "Incompatible static rows/cols in ref binding"); - ROTGEN_ASSERT((Ref::ColsAtCompileTime == Dynamic) || - (Ref::ColsAtCompileTime == c), - "Incompatible static rows/cols in ref binding"); + assert((Ref::RowsAtCompileTime == Dynamic) || + (Ref::RowsAtCompileTime == rows)); + assert((Ref::ColsAtCompileTime == Dynamic) || + (Ref::ColsAtCompileTime == cols)); // Swap stride if we are a vector and we changed rows as such - bool transpose = Ref::IsVectorAtCompileTime && (r != rows(in)); + bool transpose = Ref::IsVectorAtCompileTime && (rows != in.rows()); // Swap stride if storage ordder doesn't match constexpr bool row_major = Ref::IsRowMajor; @@ -112,13 +105,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(innerStride(in)); + Index inner_actual = proper_inner_stride(in.innerStride()); Index outer_actual = - proper_outer_stride(inner_actual, outerStride(in), rows(in), cols(in), + proper_outer_stride(inner_actual, in.outerStride(), in.rows(), in.cols(), Input::IsVectorAtCompileTime, input_row_major); - bool row_vector = (r == 1); - bool col_vector = (c == 1); + bool row_vector = (rows == 1); + bool col_vector = (cols == 1); // Adapt inner stride based on row/col vector status Index inner_stride = @@ -134,7 +127,7 @@ namespace rotgen::detail ((!row_major && col_vector) || (row_major && row_vector)) ? (stride_type::OuterStrideAtCompileTime > 0 ? stride_type::OuterStrideAtCompileTime - : r * c * inner_stride) + : rows * cols * inner_stride) : swap_stride ? inner_actual : outer_actual; @@ -149,7 +142,7 @@ namespace rotgen::detail bool outer_valid = (stride_type::OuterStrideAtCompileTime == Dynamic) || (proper_outer_stride( - inner_stride, Index(stride_type::OuterStrideAtCompileTime), r, c, + inner_stride, Index(stride_type::OuterStrideAtCompileTime), rows, cols, Ref::IsVectorAtCompileTime != 0, row_major) == outer_stride); if (!outer_valid) return false; @@ -158,7 +151,7 @@ namespace rotgen::detail stride_type::OuterStrideAtCompileTime == 0 ? 1 : outer_stride, stride_type::InnerStrideAtCompileTime == 0 ? 1 : inner_stride); - auto actual = map_base(in.data(), r, c, proper_stride); + auto actual = map_base(in.data(), rows, cols, proper_stride); ref.base().base().storage().swap(actual.storage()); diff --git a/include/rotgen/detail/assert.hpp b/include/rotgen/detail/assert.hpp deleted file mode 100644 index 7469c98..0000000 --- a/include/rotgen/detail/assert.hpp +++ /dev/null @@ -1,22 +0,0 @@ -//================================================================================================== -/* - ROTGEN - Runtime Overlay for Eigen - Copyright : CODE RECKONS - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#if defined(ROTGEN_USE_LIBASSERT) -#include -#define ROTGEN_ASSERT(COND, ...) DEBUG_ASSERT(COND, __VA_ARGS__) - -#else -#include - -#if !defined(NDEBUG) -#define ROTGEN_ASSERT(COND, MSG, ...) assert((COND) && (MSG)) -#else -#define ROTGEN_ASSERT(COND, ...) (void)(COND) -#endif -#endif diff --git a/include/rotgen/detail/helpers.hpp b/include/rotgen/detail/helpers.hpp index 2003cf9..17fd00c 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,15 +15,6 @@ 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; @@ -40,7 +31,7 @@ namespace rotgen::detail using type = Wrapper; }; diff --git a/include/rotgen/detail/product.hpp b/include/rotgen/detail/product.hpp deleted file mode 100644 index 62237e2..0000000 --- a/include/rotgen/detail/product.hpp +++ /dev/null @@ -1,57 +0,0 @@ -//================================================================================================== -/* - ROTGEN - Runtime Overlay for Eigen - Copyright : CODE RECKONS - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -#include - -#include - -namespace rotgen -{ - // Emulate EIGEN 1x1 pseudo product type - template struct product - { - using rotgen_tag = void; - - using value_type = typename M::value_type; - using concrete_type = matrix; - - static constexpr auto storage_order = concrete_type::storage_order; - static constexpr int RowsAtCompileTime = 1; - static constexpr int ColsAtCompileTime = 1; - static constexpr int SizeAtCompileTime = 1; - static constexpr int MaxRowsAtCompileTime = 1; - static constexpr int MaxColsAtCompileTime = 1; - static constexpr bool IsVectorAtCompileTime = - concrete_type::IsVectorAtCompileTime; - - product(M const& m) : storage_(m) {} - - auto size() const { return storage_.size(); } - - auto _rows() const { return storage_._rows(); } - - auto _cols() const { return storage_._cols(); } - - auto operator()(int i) const { return storage_(i); } - - auto operator[](int i) const { return storage_(i); } - - auto operator()(int r, int c) const { return storage_(r, c); } - - auto _sum() const { return storage_._sum(); } - - auto const& base() const { return storage_.base(); } - - operator value_type const() const { return storage_(0); } - - operator concrete_type() const { return storage_; } - - concrete_type storage_; - }; -} diff --git a/include/rotgen/functions/extract.hpp b/include/rotgen/functions/extract.hpp index 492f0a7..73e7e4f 100644 --- a/include/rotgen/functions/extract.hpp +++ b/include/rotgen/functions/extract.hpp @@ -1,17 +1,13 @@ -//============================================================================== +//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ -//============================================================================== +//================================================================================================== #pragma once - -#include #include -#include - #include namespace rotgen @@ -25,12 +21,10 @@ namespace rotgen [[maybe_unused]] Index ni, [[maybe_unused]] Index nj) { - ROTGEN_ASSERT(i0 >= 0, "block extraction uses negative row index."); - ROTGEN_ASSERT(j0 >= 0, "block extraction uses negative col index."); - ROTGEN_ASSERT(i0 + ni <= rows(e), - "block extraction rows is out of range."); - ROTGEN_ASSERT(j0 + nj <= cols(e), - "block extraction cols is out of range."); + assert(i0 >= 0 && "block extraction uses negative row index."); + assert(j0 >= 0 && "block extraction uses negative col index."); + assert(i0 + ni <= e.rows() && "block extraction rows is out of range."); + assert(j0 + nj <= e.cols() && "block extraction cols is out of range."); } } @@ -87,55 +81,55 @@ namespace rotgen template auto topRightCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), 0, cols(e) - nj, ni, nj); + return extract(ROTGEN_FWD(e), 0, e.cols() - nj, ni, nj); } template auto topRightCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), 0, cols(e) - NJ); + return extract(ROTGEN_FWD(e), 0, e.cols() - NJ); } //======================== BOTTOM LEFT CORNER ======================== template auto bottomLeftCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, nj); + return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, nj); } template auto bottomLeftCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), rows(e) - NI, 0); + return extract(ROTGEN_FWD(e), e.rows() - NI, 0); } //======================== BOTTOM RIGHT CORNER ======================== template auto bottomRightCorner(Entity&& e, Index ni, Index nj) { - return extract(ROTGEN_FWD(e), rows(e) - ni, cols(e) - nj, ni, nj); + return extract(ROTGEN_FWD(e), e.rows() - ni, e.cols() - nj, ni, nj); } template auto bottomRightCorner(Entity&& e) { - return extract(ROTGEN_FWD(e), rows(e) - NI, cols(e) - NJ); + return extract(ROTGEN_FWD(e), e.rows() - NI, e.cols() - 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, cols(e)); + return extract(ROTGEN_FWD(e), 0, 0, ni, e.cols()); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), 0, 0, ni, cols(e)); + ROTGEN_FWD(e), 0, 0, ni, e.cols()); } template auto topRows(Entity&& e) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, 0, NI, cols(e)); + return extract(ROTGEN_FWD(e), 0, 0, NI, e.cols()); else return extract::ColsAtCompileTime>( ROTGEN_FWD(e), 0, 0); @@ -146,17 +140,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, cols(e)); + return extract(ROTGEN_FWD(e), i0, 0, ni, e.cols()); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), i0, 0, ni, cols(e)); + ROTGEN_FWD(e), i0, 0, ni, e.cols()); } template auto middleRows(Entity&& e, Index i0) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), i0, 0, NI, cols(e)); + return extract(ROTGEN_FWD(e), i0, 0, NI, e.cols()); else return extract::ColsAtCompileTime>( ROTGEN_FWD(e), i0, 0); @@ -166,35 +160,35 @@ namespace rotgen template auto bottomRows(Entity&& e, Index ni) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); + return extract(ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols()); else return extract<-1, std::remove_cvref_t::ColsAtCompileTime>( - ROTGEN_FWD(e), rows(e) - ni, 0, ni, cols(e)); + ROTGEN_FWD(e), e.rows() - ni, 0, ni, e.cols()); } template auto bottomRows(Entity&& e) { if constexpr (std::remove_cvref_t::ColsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), rows(e) - NI, 0, NI, cols(e)); + return extract(ROTGEN_FWD(e), e.rows() - NI, 0, NI, e.cols()); else return extract::ColsAtCompileTime>( - ROTGEN_FWD(e), rows(e) - NI, 0); + ROTGEN_FWD(e), e.rows() - 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, rows(e), nj); + return extract(ROTGEN_FWD(e), 0, 0, e.rows(), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, 0, rows(e), nj); + ROTGEN_FWD(e), 0, 0, e.rows(), nj); } template auto leftCols(Entity&& e) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, rows(e), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, 0, e.rows(), NJ); else return extract::RowsAtCompileTime, NJ>( ROTGEN_FWD(e), 0, 0); @@ -205,17 +199,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, rows(e), nj); + return extract(ROTGEN_FWD(e), 0, j0, e.rows(), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, j0, rows(e), nj); + ROTGEN_FWD(e), 0, j0, e.rows(), 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, rows(e), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, j0, e.rows(), NJ); else return extract::RowsAtCompileTime, NJ>( ROTGEN_FWD(e), 0, j0); @@ -225,27 +219,27 @@ namespace rotgen template auto rightCols(Entity&& e, Index nj) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract(ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); + return extract(ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj); else return extract::RowsAtCompileTime, -1>( - ROTGEN_FWD(e), 0, cols(e) - nj, rows(e), nj); + ROTGEN_FWD(e), 0, e.cols() - nj, e.rows(), nj); ; } template auto rightCols(Entity&& e) { if constexpr (std::remove_cvref_t::RowsAtCompileTime == -1) - return extract<-1, NJ>(ROTGEN_FWD(e), 0, cols(e) - NJ, rows(e), NJ); + return extract<-1, NJ>(ROTGEN_FWD(e), 0, e.cols() - NJ, e.rows(), NJ); else return extract::RowsAtCompileTime, NJ>( - ROTGEN_FWD(e), 0, cols(e) - NJ); + ROTGEN_FWD(e), 0, e.cols() - 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, cols(e)); + return extract<1, -1>(ROTGEN_FWD(e), i0, 0, 1, e.cols()); else return extract<1, std::remove_cvref_t::ColsAtCompileTime>( ROTGEN_FWD(e), i0, 0); @@ -255,7 +249,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, rows(e), 1); + return extract<-1, 1>(ROTGEN_FWD(e), 0, j0, e.rows(), 1); else return extract::RowsAtCompileTime, 1>( ROTGEN_FWD(e), 0, j0); @@ -291,9 +285,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, cols(e) - n, 1, n); + return extract<1, Dynamic>(ROTGEN_FWD(e), 0, e.cols() - n, 1, n); else if constexpr (std::remove_cvref_t::ColsAtCompileTime == 1) - return extract(ROTGEN_FWD(e), rows(e) - n, 0, n, 1); + return extract(ROTGEN_FWD(e), e.rows() - n, 0, n, 1); } template @@ -302,9 +296,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, cols(e) - N); + return extract<1, N>(ROTGEN_FWD(e), 0, e.cols() - N); else if constexpr (std::remove_cvref_t::ColsAtCompileTime == 1) - return extract(ROTGEN_FWD(e), rows(e) - N, 0); + return extract(ROTGEN_FWD(e), e.rows() - N, 0); } //======================== VECTOR SEGMENT ======================== diff --git a/include/rotgen/functions/functions.hpp b/include/rotgen/functions/functions.hpp index bb5c522..7733f2d 100644 --- a/include/rotgen/functions/functions.hpp +++ b/include/rotgen/functions/functions.hpp @@ -1,308 +1,187 @@ -//============================================================================== +//================================================================================================== /* 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(); }) { - if constexpr (requires { m.rows(); }) { return m.rows(); } - else if constexpr (requires { m._rows(); }) { return m._rows(); } - else { return detail::unsupported_parameters(); } + return m.rows(); } - /// Returns the column count of a matrix. Index cols(auto const& m) + requires(requires { m.cols(); }) { - - if constexpr (requires { m.cols(); }) { return m.cols(); } - else if constexpr (requires { m._cols(); }) { return m._cols(); } - else { return detail::unsupported_parameters(); } + return m.cols(); } - 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(); } - /// Resizes a matrix into a vector of size s. - void resize(auto& m, int s) - requires requires { m.resize(s); } + void resize(auto& a, int s) + requires requires { a.resize(s); } { - m.resize(s); + a.resize(s); } - /// 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); } + void resize(auto& a, int r, int c) + requires requires { a.resize(r, c); } { - m.resize(r, c); + a.resize(r, c); } void conservativeResize(auto& a, int s) + requires requires { 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(); } + a.conservativeResize(s); } void conservativeResize(auto& a, int r, int c) + requires requires { 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(); } + a.conservativeResize(r, c); } - Index innerStride(auto const& m) - { - 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) + requires(requires { m.normalized(); }) { - if constexpr (requires { m.normalized(); }) { return m.normalized(); } - else if constexpr (requires { m._normalized(); }) - { - return m._normalized(); - } - else { return detail::unsupported_parameters(); } + return m.normalized(); } decltype(auto) transpose(auto const& m) + requires(requires { m.transpose(); }) { - if constexpr (requires { m.transpose(); }) { return m.transpose(); } - else if constexpr (requires { m._transpose(); }) { return m._transpose(); } - else { return detail::unsupported_parameters(); } + return m.transpose(); } decltype(auto) conjugate(auto const& m) + requires(requires { m.conjugate(); }) { - if constexpr (requires { m.conjugate(); }) { return m.conjugate(); } - else if constexpr (requires { m._conjugate(); }) { return m._conjugate(); } + return m.conjugate(); } decltype(auto) adjoint(auto const& m) + requires(requires { m.adjoint(); }) { - if constexpr (requires { m.adjoint(); }) { return m.adjoint(); } - else if constexpr (requires { m._adjoint(); }) { return m._adjoint(); } - else { return detail::unsupported_parameters(); } + return m.adjoint(); } - template void normalize(C&& a) + void normalize(auto& a) + requires(requires { a.normalize(); }) { - if constexpr (requires { std::forward(a).normalize(); }) - { - std::forward(a).normalize(); - } - else if constexpr (requires { std::forward(a)._normalize(); }) - { - std::forward(a)._normalize(); - } - else { return detail::unsupported_parameters(); } + a.normalize(); } - template void transposeInPlace(C&& a) + void transposeInPlace(auto& a) + requires(requires { a.transposeInPlace(); }) { - if constexpr (requires { std::forward(a).transposeInPlace(); }) - { - std::forward(a).transposeInPlace(); - } - else if constexpr (requires { std::forward(a)._transposeInPlace(); }) - { - std::forward(a)._transposeInPlace(); - } - else { return detail::unsupported_parameters(); } + a.transposeInPlace(); } - template void adjointInPlace(C&& a) + void adjointInPlace(auto& a) + requires(requires { a.adjointInPlace(); }) { - if constexpr (requires { std::forward(a).adjointInPlace(); }) - { - std::forward(a).adjointInPlace(); - } - else if constexpr (requires { std::forward(a)._adjointInPlace(); }) - { - std::forward(a)._adjointInPlace(); - } - else { return detail::unsupported_parameters(); } + a.adjointInPlace(); } - //---------------------------------------------------------------------------- + //----------------------------------------------------------------------------------------------- // Component-wise functions - //---------------------------------------------------------------------------- - + //----------------------------------------------------------------------------------------------- auto abs(auto const& arg) + requires(requires { arg.cwiseAbs(); }) { - if constexpr (requires { arg.cwiseAbs(); }) { return arg.cwiseAbs(); } - else if constexpr (requires { arg._cwiseAbs(); }) - { - return arg._cwiseAbs(); - } - else { return detail::unsupported_parameters(); } + return arg.cwiseAbs(); } auto abs2(auto const& arg) + requires(requires { arg.cwiseAbs2(); }) { - if constexpr (requires { arg.cwiseAbs2(); }) { return arg.cwiseAbs2(); } - else if constexpr (requires { arg._cwiseAbs2(); }) - { - return arg._cwiseAbs2(); - } - else { return detail::unsupported_parameters(); } + return arg.cwiseAbs2(); } auto rec(auto const& arg) + requires(requires { arg.cwiseInverse(); }) { - if constexpr (requires { arg.cwiseInverse(); }) - { - return arg.cwiseInverse(); - } - else if constexpr (requires { arg._cwiseInverse(); }) - { - return arg._cwiseInverse(); - } - else { return detail::unsupported_parameters(); } + return arg.cwiseInverse(); } auto sqrt(auto const& arg) + requires(requires { arg.cwiseSqrt(); }) { - if constexpr (requires { arg.cwiseSqrt(); }) { return arg.cwiseSqrt(); } - else if constexpr (requires { arg._cwiseSqrt(); }) - { - return 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 @@ -321,10 +200,8 @@ 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 @@ -338,54 +215,43 @@ namespace rotgen return mul(a, a); } - //---------------------------------------------------------------------------- + //----------------------------------------------------------------------------------------------- // Reductions - //---------------------------------------------------------------------------- - + //----------------------------------------------------------------------------------------------- auto trace(auto const& arg) + requires requires { arg.trace(); } { - if constexpr (requires { arg.trace(); }) { return arg.trace(); } - else if constexpr (requires { arg._trace(); }) { return arg._trace(); } - else { return detail::unsupported_parameters(); } + return arg.trace(); } auto squaredNorm(auto const& arg) + requires requires { arg.squaredNorm(); } { - if constexpr (requires { arg.squaredNorm(); }) { return arg.squaredNorm(); } - else if constexpr (requires { arg._squaredNorm(); }) - { - return arg._squaredNorm(); - } - else { return detail::unsupported_parameters(); } + return arg.squaredNorm(); } auto norm(auto const& arg) + requires requires { arg.norm(); } { - if constexpr (requires { arg.norm(); }) { return arg.norm(); } - else if constexpr (requires { arg._norm(); }) { return arg._norm(); } - else { return detail::unsupported_parameters(); } + return arg.norm(); } auto sum(auto const& arg) - requires(requires { arg.sum(); } || requires { arg._sum(); }) + requires requires { arg.sum(); } { - if constexpr (requires { arg.sum(); }) { return arg.sum(); } - else if constexpr (requires { arg._sum(); }) { return arg._sum(); } - else { return detail::unsupported_parameters(); } + return arg.sum(); } auto prod(auto const& arg) + requires requires { arg.prod(); } { - if constexpr (requires { arg.prod(); }) { return arg.prod(); } - else if constexpr (requires { arg._prod(); }) { return arg._prod(); } - else { return detail::unsupported_parameters(); } + return arg.prod(); } auto mean(auto const& arg) + requires requires { arg.mean(); } { - if constexpr (requires { arg.mean(); }) { return arg.mean(); } - else if constexpr (requires { arg._mean(); }) { return arg._mean(); } - else { return detail::unsupported_parameters(); } + return arg.mean(); } template @@ -394,135 +260,89 @@ 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(); }) { - if constexpr (requires { arg.maxCoeff(); }) { return arg.maxCoeff(); } - else if constexpr (requires { arg._maxCoeff(); }) - { - return arg._maxCoeff(); - } - else { return detail::unsupported_parameters(); } + return arg.maxCoeff(); } auto minCoeff(auto const& arg) + requires(requires { arg.minCoeff(); }) { - if constexpr (requires { arg.minCoeff(); }) { return arg.minCoeff(); } - else if constexpr (requires { arg._minCoeff(); }) - { - return arg._minCoeff(); - } - else { return detail::unsupported_parameters(); } + return arg.minCoeff(); } template auto maxCoeff(auto const& arg, IndexType* row, IndexType* col) + requires(requires { 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(); } + return arg.maxCoeff(row, col); } template auto minCoeff(auto const& arg, IndexType* row, IndexType* col) + requires(requires { 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(); } + return arg.minCoeff(row, col); } - template auto lpNorm(T const& arg) + template + auto lpNorm(T const& arg) + requires(requires { 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(); } + static_assert(P == 1 || P == 2 || P == Infinity); + return arg.template lpNorm

(); } - //---------------------------------------------------------------------------- + //----------------------------------------------------------------------------------------------- // Expression handling - //---------------------------------------------------------------------------- - template decltype(auto) noalias(T&& t) + //----------------------------------------------------------------------------------------------- + template + decltype(auto) noalias(T&& t) + requires(requires { 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(); } + return std::forward(t).noalias(); } - template auto evaluate(T&& t) + template + auto evaluate(T&& t) + requires(requires { 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(); } + return std::forward(t).evaluate(); } - //---------------------------------------------------------------------------- + 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 b627626..b91e2d1 100644 --- a/include/rotgen/functions/generators.hpp +++ b/include/rotgen/functions/generators.hpp @@ -1,288 +1,156 @@ -//============================================================================== +//================================================================================================== /* 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; - using map_t = rotgen::map>; - - ROTGEN_ASSERT(sizeof...(v) == m.size(), - "Incorrect quantity of coefficients for initialization"); - type data[] = {static_cast(v)...}; - m = map_t(data, rows(m), cols(m)); - } - - //---------------------------------------------------------------------------- + //----------------------------------------------------------------------------------------------- // Generators - //---------------------------------------------------------------------------- - - template auto setZero(T&& t) + //----------------------------------------------------------------------------------------------- + template + auto setZero(T&& t) + requires(requires { 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(); - } + return std::forward(t).setZero(); } - template auto setZero() + template + auto setZero() + requires(requires { T::Zero(); }) { - if constexpr (requires { T::Zero(); }) { return T::Zero(); } - else if constexpr (requires { T::_Zero(); }) { return T::_Zero(); } - else - { - return detail::unsupported_parameters(); - } + return T::Zero(); } - template auto setZero(std::integral auto n) + template + auto setZero(std::integral auto n) + requires(requires { 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(); - } + return T::Zero(n); } - template auto setZero(std::integral auto r, std::integral auto c) + template + auto setZero(std::integral auto r, std::integral auto c) + requires(requires { 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(); - } + return T::Zero(r, c); } - template auto setOnes(T&& t) + template + auto setOnes(T&& t) + requires(requires { 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(); - } + return std::forward(t).setOnes(); } - template auto setOnes() + template + auto setOnes() + requires(requires { T::Ones(); }) { - if constexpr (requires { T::Ones(); }) { return T::Ones(); } - else if constexpr (requires { T::_Ones(); }) { return T::_Ones(); } - else - { - return detail::unsupported_parameters(); - } + return T::Ones(); } - template auto setOnes(std::integral auto n) + template + auto setOnes(std::integral auto n) + requires(requires { 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(); - } + return T::Ones(n); } - template auto setOnes(std::integral auto r, std::integral auto c) + template + auto setOnes(std::integral auto r, std::integral auto c) + requires(requires { 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(); - } + return T::Ones(r, c); } - template auto setIdentity(T&& t) + template + auto setIdentity(T&& t) + requires(requires { 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(); - } + return std::forward(t).setIdentity(); } - template auto setIdentity() + template + auto setIdentity() + requires(requires { T::Identity(); }) { - if constexpr (requires { T::Identity(); }) { return T::Identity(); } - else if constexpr (requires { T::_Identity(); }) { return T::_Identity(); } - else - { - return detail::unsupported_parameters(); - } + return T::Identity(); } - template auto setIdentity(std::integral auto n) + template + auto setIdentity(std::integral auto n) + requires(requires { 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(); - } + return T::Identity(n); } template auto setIdentity(std::integral auto r, std::integral auto c) + requires(requires { 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(); - } + return T::Identity(r, c); } - template auto setRandom(T&& t) + template + auto setRandom(T&& t) + requires(requires { 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(); - } + return std::forward(t).setRandom(); } - template auto setRandom() + template + auto setRandom() + requires(requires { T::Random(); }) { - if constexpr (requires { T::Random(); }) { return T::Random(); } - else if constexpr (requires { T::_Random(); }) { return T::_Random(); } - else - { - return detail::unsupported_parameters(); - } + return T::Random(); } - template auto setRandom(std::integral auto n) + template + auto setRandom(std::integral auto n) + requires(requires { 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(); - } + return T::Random(n); } template auto setRandom(std::integral auto r, std::integral auto c) + requires(requires { 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(); - } + return T::Random(r, c); } - template auto setConstant(T&& t, auto v) + template + auto setConstant(T&& t, auto v) + requires(requires { 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(); - } + return std::forward(t).setConstant(v); } - template auto setConstant(auto v) + template + auto setConstant(auto v) + requires(requires { 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(); - } + return T::Constant(v); } - template auto setConstant(std::integral auto n, auto v) + template + auto setConstant(std::integral auto n, auto v) + requires(requires { 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(); - } + return T::Constant(n, v); } template auto setConstant(std::integral auto r, std::integral auto c, auto v) + requires(requires { 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(); - } + return T::Constant(r, c, v); } } diff --git a/include/rotgen/functions/operators.hpp b/include/rotgen/functions/operators.hpp index afd66bc..e56fb82 100644 --- a/include/rotgen/functions/operators.hpp +++ b/include/rotgen/functions/operators.hpp @@ -7,10 +7,9 @@ //================================================================================================== #pragma once -#include - #include +#include #include namespace rotgen @@ -81,27 +80,30 @@ namespace rotgen //------------------------------------------------------------------------------------------------ // Compounds operators across types - template - decltype(auto) operator+=(A&& a, B const& b) - requires(!concepts::block) + template + auto operator+=(A& a, B const& b) + requires(concepts::entity && concepts::entity) { - generalize_t(ROTGEN_FWD(a)) += generalize_t(b); - return ROTGEN_FWD(a); + if constexpr (!use_expression_templates) + return generalize_t(a) += generalize_t(b); + else return base_of(a) += base_of(b); } - template - decltype(auto) operator-=(A&& a, B const& b) - requires(!concepts::block) + template + auto operator-=(A& a, B const& b) + requires(concepts::entity && concepts::entity) { - generalize_t(ROTGEN_FWD(a)) -= generalize_t(b); - return ROTGEN_FWD(a); + if constexpr (!use_expression_templates) + return generalize_t(a) -= generalize_t(b); + else return base_of(a) -= base_of(b); } - template - decltype(auto) operator*=(A&& a, B const& b) - requires(!concepts::block) + template + auto operator*=(A& a, B const& b) + requires(concepts::entity && concepts::entity) { - generalize_t(ROTGEN_FWD(a)) *= generalize_t(b); - return ROTGEN_FWD(a); + if constexpr (!use_expression_templates) + return generalize_t(a) *= generalize_t(b); + else return base_of(a) *= base_of(b); } } diff --git a/include/rotgen/functions/reshaper.hpp b/include/rotgen/functions/reshaper.hpp index 89a030b..b47d347 100644 --- a/include/rotgen/functions/reshaper.hpp +++ b/include/rotgen/functions/reshaper.hpp @@ -7,11 +7,6 @@ //================================================================================================== #pragma once -#include -#include - -#include - namespace rotgen { template struct rowwise_adaptor @@ -19,64 +14,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(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.sum(); }); return res; } - concrete_type _mean() const + concrete_type mean() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.mean(); }); return res; } - concrete_type _prod() const + concrete_type prod() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.prod(); }); return res; } - concrete_type _maxCoeff() const + concrete_type maxCoeff() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); return res; } - concrete_type _minCoeff() const + concrete_type minCoeff() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.minCoeff(); }); return res; } - concrete_type _squaredNorm() const + concrete_type squaredNorm() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); return res; } - concrete_type _norm() const + concrete_type norm() const { - concrete_type res(rows(target_), 1); - apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.norm(); }); return res; } private: template void apply(Func f) { - for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } + for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i); } template void apply(Func f) const { - for (Index i = 0; i < rows(target_); ++i) { f(row(target_, i), i); } + for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i); } }; @@ -85,82 +80,76 @@ 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, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::sum(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.sum(); }); return res; } - concrete_type _mean() const + concrete_type mean() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::mean(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.mean(); }); return res; } - concrete_type _prod() const + concrete_type prod() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::prod(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.prod(); }); return res; } - concrete_type _maxCoeff() const + concrete_type maxCoeff() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::maxCoeff(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); return res; } - concrete_type _minCoeff() const + concrete_type minCoeff() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::minCoeff(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.minCoeff(); }); return res; } - concrete_type _squaredNorm() const + concrete_type squaredNorm() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::squaredNorm(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); return res; } - concrete_type _norm() const + concrete_type norm() const { - concrete_type res(1, cols(target_)); - apply([&](auto r, auto i) { res(i) = rotgen::norm(r); }); + concrete_type res(1, target_.cols()); + apply([&](auto r, auto i) { res(i) = r.norm(); }); return res; } private: template void apply(Func f) { - for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } + for (Index i = 0; i < target_.cols(); ++i) f(col(target_, i), i); } template void apply(Func f) const { - for (Index i = 0; i < cols(target_); ++i) { f(col(target_, i), i); } + for (Index i = 0; i < target_.cols(); ++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/generate.cpp b/src/block/generate.cpp index 43b9bdc..3d3faf0 100644 --- a/src/block/generate.cpp +++ b/src/block/generate.cpp @@ -10,38 +10,30 @@ #define STORAGE_ORDER Eigen::ColMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #include "model.cpp" #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSNAME #undef TRANSCLASSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #include "model.cpp" #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSNAME #undef TRANSCLASSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef STORAGE_ORDER #undef SIZE @@ -52,38 +44,30 @@ #define STORAGE_ORDER Eigen::ColMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) #include "model.cpp" #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSNAME #undef TRANSCLASSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define CLASSCONSTNAME ROTGEN_MATRIX_NAME(block_const_impl, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define TRANSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _row) -#define TRANSMAPNAME ROTGEN_MATRIX_NAME(BASEMAP, SIZE, _col) #include "model.cpp" #undef CLASSNAME -#undef CLASSCONSTNAME #undef TRANSNAME #undef TRANSCLASSNAME #undef SOURCENAME #undef MAPNAME -#undef TRANSMAPNAME #undef STORAGE_ORDER #undef SIZE diff --git a/src/block/model.cpp b/src/block/model.cpp index 983602b..dc01f1d 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_( @@ -33,12 +33,6 @@ CLASSNAME::CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj) { } -CLASSNAME::CLASSNAME( - TRANSMAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj) - : storage_(std::make_unique(r, i0, j0, ni, nj, map_t{}, trans_t{})) -{ -} - // We're building a block from a block - So we have to dig around the internals CLASSNAME::CLASSNAME( TRANSCLASSNAME CONST& p, Index i0, Index j0, Index ni, Index nj) @@ -134,9 +128,22 @@ 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 { @@ -145,40 +152,26 @@ rotgen::Index CLASSNAME::size() const return that; } -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 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; } @@ -204,17 +197,17 @@ 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; - return (*this)(r, c); + TYPE* ptr = nullptr; + storage_->apply([&](auto& blk) { ptr = blk.data() + index; }); + return *ptr; } #endif TYPE CLASSNAME::operator()(Index index) const { - auto r = _rows() == 1 ? 0 : index; - auto c = _cols() == 1 ? 0 : index; - return (*this)(r, c); + TYPE ptr; + storage_->apply([&](auto const& blk) { ptr = *(blk.data() + index); }); + return ptr; } // Raw pointer access @@ -234,10 +227,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) { @@ -246,7 +239,7 @@ SOURCENAME CLASSNAME::_normalized() const return result; } -SOURCENAME CLASSNAME::_transpose() const +SOURCENAME CLASSNAME::transpose() const { SOURCENAME result; storage_->apply( @@ -254,7 +247,7 @@ SOURCENAME CLASSNAME::_transpose() const return result; } -SOURCENAME CLASSNAME::_conjugate() const +SOURCENAME CLASSNAME::conjugate() const { SOURCENAME result; storage_->apply( @@ -262,7 +255,7 @@ SOURCENAME CLASSNAME::_conjugate() const return result; } -SOURCENAME CLASSNAME::_adjoint() const +SOURCENAME CLASSNAME::adjoint() const { SOURCENAME result; storage_->apply( @@ -270,7 +263,7 @@ SOURCENAME CLASSNAME::_adjoint() const return result; } -SOURCENAME CLASSNAME::_cwiseAbs() const +SOURCENAME CLASSNAME::cwiseAbs() const { SOURCENAME result; storage_->apply( @@ -278,7 +271,7 @@ SOURCENAME CLASSNAME::_cwiseAbs() const return result; } -SOURCENAME CLASSNAME::_cwiseAbs2() const +SOURCENAME CLASSNAME::cwiseAbs2() const { SOURCENAME result; storage_->apply( @@ -286,7 +279,7 @@ SOURCENAME CLASSNAME::_cwiseAbs2() const return result; } -SOURCENAME CLASSNAME::_cwiseInverse() const +SOURCENAME CLASSNAME::cwiseInverse() const { SOURCENAME result; storage_->apply([&](auto const& blk) { @@ -295,7 +288,7 @@ SOURCENAME CLASSNAME::_cwiseInverse() const return result; } -SOURCENAME CLASSNAME::_cwiseSqrt() const +SOURCENAME CLASSNAME::cwiseSqrt() const { SOURCENAME result; storage_->apply( @@ -304,96 +297,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) { @@ -404,9 +397,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; }); @@ -455,28 +448,6 @@ CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs) -{ - std::visit( - [](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first += rhs_blk.first; }, - storage_->data, rhs.storage()->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator+=(SOURCENAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first += rhs.storage()->data; }, - storage_->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator+=(TRANSNAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first += rhs.storage()->data; }, - storage_->data); - return *this; -} - CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) { std::visit( @@ -485,28 +456,6 @@ CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs) -{ - std::visit( - [](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first -= rhs_blk.first; }, - storage_->data, rhs.storage()->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator-=(SOURCENAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first -= rhs.storage()->data; }, - storage_->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator-=(TRANSNAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first -= rhs.storage()->data; }, - storage_->data); - return *this; -} - CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) { std::visit( @@ -515,28 +464,6 @@ CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs) -{ - std::visit( - [](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first *= rhs_blk.first; }, - storage_->data, rhs.storage()->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator*=(SOURCENAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first *= rhs.storage()->data; }, - storage_->data); - return *this; -} - -CLASSNAME& CLASSNAME::operator*=(TRANSNAME const& rhs) -{ - std::visit([&](auto& lhs_blk) { lhs_blk.first *= rhs.storage()->data; }, - storage_->data); - return *this; -} - CLASSNAME& CLASSNAME::operator*=(TYPE s) { storage_->apply([&](auto& blk) { blk *= s; }); @@ -550,7 +477,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( @@ -561,7 +488,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( @@ -572,7 +499,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( @@ -583,7 +510,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( @@ -594,7 +521,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/generate.cpp b/src/map/generate.cpp index 6cdf555..c6ede29 100644 --- a/src/map/generate.cpp +++ b/src/map/generate.cpp @@ -11,41 +11,29 @@ #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef SOURCENAME #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef SOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef STORAGE_ORDER #undef SIZE @@ -57,40 +45,28 @@ #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef SOURCENAME #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) -#define TRANSCLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _col) -#define TRANSCLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl, SIZE, _row) -#define CLASSNONCONSTNAME ROTGEN_MATRIX_NAME(map_impl, SIZE, _row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME -#undef TRANSCLASSCONSTNAME -#undef TRANSCLASSNONCONSTNAME #undef TRANSSOURCENAME #undef CLASSCONSTNAME -#undef CLASSNONCONSTNAME #undef SOURCENAME #undef STORAGE_ORDER diff --git a/src/map/model.cpp b/src/map/model.cpp index 0983011..1aefec6 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,83 @@ 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(CLASSNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::_dot(CLASSCONSTNAME const& rhs) const +TYPE CLASSNAME::dot(TRANSCLASSNAME const& rhs) const { return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); } -TYPE CLASSNAME::_dot(TRANSCLASSNONCONSTNAME const& rhs) const -{ - return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); -} - -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 +307,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); } @@ -388,7 +378,7 @@ SOURCENAME CLASSNAME::operator-() const #if !defined(USE_CONST) CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) { - storage_->data += rhs.storage()->data; + storage_->data += rhs.storage_->data; return *this; } @@ -398,21 +388,9 @@ CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator+=(TRANSCLASSNONCONSTNAME const& rhs) -{ - storage_->data.reshaped() += rhs.storage()->data.reshaped(); - return *this; -} - -CLASSNAME& CLASSNAME::operator+=(TRANSCLASSCONSTNAME const& rhs) -{ - storage_->data.reshaped() += rhs.storage()->data.reshaped(); - return *this; -} - CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) { - storage_->data -= rhs.storage()->data; + storage_->data -= rhs.storage_->data; return *this; } @@ -422,21 +400,9 @@ CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator-=(TRANSCLASSNONCONSTNAME const& rhs) -{ - storage_->data.reshaped() -= rhs.storage()->data.reshaped(); - return *this; -} - -CLASSNAME& CLASSNAME::operator-=(TRANSCLASSCONSTNAME const& rhs) -{ - storage_->data.reshaped() -= rhs.storage()->data.reshaped(); - return *this; -} - CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) { - storage_->data *= rhs.storage()->data; + storage_->data *= rhs.storage_->data; return *this; } @@ -446,18 +412,6 @@ CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs) return *this; } -CLASSNAME& CLASSNAME::operator*=(TRANSCLASSNONCONSTNAME const& rhs) -{ - storage_->data *= rhs.storage()->data; - return *this; -} - -CLASSNAME& CLASSNAME::operator*=(TRANSCLASSCONSTNAME const& rhs) -{ - storage_->data *= rhs.storage()->data; - return *this; -} - CLASSNAME& CLASSNAME::operator*=(TYPE s) { storage_->data *= s; @@ -471,56 +425,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 98d2230..937e6d9 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::size() const -{ - return storage_->data.size(); -} - -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(); } +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 5f13def..3e0a33f 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::setRandom>(); + auto a = rotgen::matrix::Random(); auto b = topLeftCorner(a, 5, 5); - TTS_EQUAL(startRow(b), 0); - TTS_EQUAL(startCol(b), 0); + TTS_EQUAL(b.startRow(), 0); + TTS_EQUAL(b.startCol(), 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(startRow(bb), 2); - TTS_EQUAL(startCol(bb), 2); + TTS_EQUAL(bb.startRow(), 2); + TTS_EQUAL(bb.startCol(), 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(startRow(bbb), 1); - TTS_EQUAL(startCol(bbb), 0); + TTS_EQUAL(bbb.startRow(), 1); + TTS_EQUAL(bbb.startCol(), 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(startRow(bbbb), 0); - TTS_EQUAL(startCol(bbbb), 1); + TTS_EQUAL(bbbb.startRow(), 0); + TTS_EQUAL(bbbb.startCol(), 1); setConstant(bbbb, 0.125); TTS_EQUAL(a(3, 3), 0.125); @@ -77,39 +77,3 @@ TTS_CASE("Extraction of ref/ref const") for (rotgen::Index r = 0; r < 4; r++) for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f); }; - -void process_col(rotgen::matrix& m, - rotgen::matrix const& n, - int c) -{ - col(m, c) += n; -} - -TTS_CASE("Compound operators on extractions") -{ - rotgen::matrix m; - rotgen::matrix reference; - rotgen::matrix n; - setZero(m); - setConstant(n, 10); - setConstant(reference, 10); - - for (int i = 0; i < cols(m); i++) process_col(m, n, i); - - TTS_EQUAL(m, reference); -}; - -TTS_CASE("Compatibility of 1D blocks") -{ - rotgen::matrix V; - setConstant(V, 99); - rotgen::matrix C{12, 34, 56}; - - extract<1, 2>(V, 0, 0) = segment<2>(C, 0); - extract<2, 1>(V, 1, 0) = segment<2>(C, 1); - - TTS_EQUAL(V(0, 0), C(0)); - TTS_EQUAL(V(0, 1), C(1)); - TTS_EQUAL(V(1, 0), C(1)); - TTS_EQUAL(V(2, 0), C(2)); -}; diff --git a/test/integration/initialize_with.cpp b/test/integration/initialize_with.cpp deleted file mode 100644 index 4e918f0..0000000 --- a/test/integration/initialize_with.cpp +++ /dev/null @@ -1,123 +0,0 @@ -//================================================================================================== -/* - ROTGEN - Runtime Overlay for Eigen - Copyright : CODE RECKONS - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#include - -#include "unit/tests.hpp" -#include - -TTS_CASE_TPL("Initialize a matrix with a list of scalars", rotgen::tests::types) - -(tts::type>) -{ - using eigen_t = Eigen::Matrix; - using rotgen_t = rotgen::matrix; - - eigen_t reference(3, 3); - reference << 1, 2, 3, 4, 5, 6, 7, 8, 9; - - rotgen_t values(3, 3); - initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9); - - for (int r = 0; r < 3; r++) - for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c)); -}; - -TTS_CASE_TPL("Initialize a sub-matrix with a list of scalars", - rotgen::tests::types) - -(tts::type>) -{ - using eigen_t = Eigen::Matrix; - using rotgen_t = rotgen::matrix; - - eigen_t reference(6, 6); - reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9; - - rotgen_t values(6, 6); - initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9); - - for (int r = 0; r < 3; r++) - for (int c = 0; c < 3; c++) - TTS_EQUAL(values(r + 1, c + 1), reference(r + 1, c + 1)); -}; - -TTS_CASE_TPL("Initialize a map with a list of scalars", rotgen::tests::types) - -(tts::type>) -{ - using eigen_t = Eigen::Matrix; - using rotgen_t = rotgen::matrix; - - T eigen_data[9] = {}; - T rotgen_data[9] = {}; - - Eigen::Map reference(eigen_data, 3, 3); - reference << 1, 2, 3, 4, 5, 6, 7, 8, 9; - - rotgen::map values(rotgen_data, 3, 3); - initialize_with(values, 1, 2, 3, 4, 5, 6, 7, 8, 9); - - for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]); -}; - -TTS_CASE_TPL("Initialize a sub-map with a list of scalars", - rotgen::tests::types) - -(tts::type>) -{ - using eigen_t = Eigen::Matrix; - using rotgen_t = rotgen::matrix; - - T eigen_data[36] = {}; - T rotgen_data[36] = {}; - - Eigen::Map reference(eigen_data, 6, 6); - reference.block(1, 1, 3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9; - - rotgen::map values(rotgen_data, 6, 6); - initialize_with(extract(values, 1, 1, 3, 3), 1, 2, 3, 4, 5, 6, 7, 8, 9); - - for (int i = 0; i < 9; i++) TTS_EQUAL(eigen_data[i], rotgen_data[i]); -}; - -void process(rotgen::ref r) -{ - rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9); -} - -void process(rotgen::ref r) -{ - rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9); -} - -void process(rotgen::ref> r) -{ - rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9); -} - -void process(rotgen::ref> r) -{ - rotgen::initialize_with(r, 1, 2, 3, 4, 5, 6, 7, 8, 9); -} - -TTS_CASE_TPL("Initialize a ref with a list of scalars", rotgen::tests::types) - -(tts::type>) -{ - using eigen_t = Eigen::Matrix; - using rotgen_t = rotgen::matrix; - - eigen_t reference(3, 3); - reference << 1, 2, 3, 4, 5, 6, 7, 8, 9; - - rotgen_t values(3, 3); - process(values); - - for (int r = 0; r < 3; r++) - for (int c = 0; c < 3; c++) TTS_EQUAL(values(r, c), reference(r, c)); -}; diff --git a/test/integration/outer_stride.cpp b/test/integration/outer_stride.cpp index 6a6a42f..67938c7 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(innerStride(m), 1); - TTS_EQUAL(outerStride(m), O::value == rotgen::ColMajor ? 4 : 3); + TTS_EQUAL(m.innerStride(), 1); + TTS_EQUAL(m.outerStride(), 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(innerStride(sp), 1); - TTS_EQUAL(outerStride(sp), 5); + TTS_EQUAL(sp.innerStride(), 1); + TTS_EQUAL(sp.outerStride(), 5); rotgen::map> dp(&padded[0], 4, 3, rotgen::outer_stride(5)); - TTS_EQUAL(innerStride(dp), 1); - TTS_EQUAL(outerStride(dp), 5); + TTS_EQUAL(dp.innerStride(), 1); + TTS_EQUAL(dp.outerStride(), 5); TTS_EQUAL(m, sp); TTS_EQUAL(m, dp); @@ -42,13 +42,13 @@ TTS_CASE_TPL("outer_stride<0> interactions", rotgen::tests::types) { 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(innerStride(sp), 1); - TTS_EQUAL(outerStride(sp), 4); + TTS_EQUAL(sp.innerStride(), 1); + TTS_EQUAL(sp.outerStride(), 4); rotgen::map> dp(&padded[0], 4, 3, rotgen::outer_stride(4)); - TTS_EQUAL(innerStride(dp), 1); - TTS_EQUAL(outerStride(dp), 4); + TTS_EQUAL(dp.innerStride(), 1); + TTS_EQUAL(dp.outerStride(), 4); TTS_EQUAL(m, sp); TTS_EQUAL(m, dp); diff --git a/test/integration/ref_magic.cpp b/test/integration/ref_magic.cpp index 9b9a9ab..ca463d1 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::setOnes>(); - auto v2 = rotgen::setRandom>(); - auto v3 = rotgen::setConstant>(6.66); + auto v1 = rotgen::matrix::Ones(); + auto v2 = rotgen::matrix::Random(); + auto v3 = rotgen::matrix::Constant(6.66); auto sum1 = v1(0); auto sum2 = v2(0) + v2(1); diff --git a/test/integration/specifics.cpp b/test/integration/specifics.cpp deleted file mode 100644 index 0bdea4d..0000000 --- a/test/integration/specifics.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//================================================================================================== -/* - ROTGEN - Runtime Overlay for Eigen - Copyright : CODE RECKONS - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#include - -#include "unit/tests.hpp" - -bool categorize_as_scalar(double) -{ - return true; -} - -bool categorize_as_scalar(rotgen::ref>) -{ - return false; -} - -TTS_CASE("Matrix product of 1xN by Nx1 yields a scalar-convertible object") -{ - rotgen::matrix a = {1, 2}; - rotgen::matrix b = {10, 20}; - - double n = a * b; - - TTS_EQUAL(n, 50); - TTS_EXPECT(categorize_as_scalar(a * b)); -}; - -TTS_CASE_TPL("Static 1x1 matrix-like objects can be assigned as-if", - rotgen::tests::types) - -(tts::type>) -{ - rotgen::matrix a = {1, 2}; - rotgen::matrix b = {10, 20}; - - rotgen::matrix big(10, 10); - auto bk = extract<1, 1>(big, 2, 2); - bk = a * b; - TTS_EQUAL(big(2, 2), 50); - - rotgen::map> big_map(big.data(), 1, 1); - - big_map = a * b; - TTS_EQUAL(big(0, 0), 50); -}; diff --git a/test/unit/block/basic_api.cpp b/test/unit/block/basic_api.cpp index 6f608e0..c74515c 100644 --- a/test/unit/block/basic_api.cpp +++ b/test/unit/block/basic_api.cpp @@ -18,9 +18,8 @@ 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}; @@ -29,44 +28,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(rows(b1), rotgen::Index{1}); - TTS_EQUAL(cols(b1), rotgen::Index{12}); + TTS_EQUAL(b1.rows(), rotgen::Index{1}); + TTS_EQUAL(b1.cols(), rotgen::Index{12}); // 1x5 dynamic block at (0,2) auto b2 = rotgen::block( dm, 0, 2, 1, 5); - TTS_EQUAL(rows(b2), rotgen::Index{1}); - TTS_EQUAL(cols(b2), rotgen::Index{5}); + TTS_EQUAL(b2.rows(), rotgen::Index{1}); + TTS_EQUAL(b2.cols(), 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(rows(b3), rotgen::Index{3}); - TTS_EQUAL(cols(b3), rotgen::Index{2}); + TTS_EQUAL(b3.rows(), rotgen::Index{3}); + TTS_EQUAL(b3.cols(), 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(rows(b4), rotgen::Index{3}); - TTS_EQUAL(cols(b4), rotgen::Index{4}); + TTS_EQUAL(b4.rows(), rotgen::Index{3}); + TTS_EQUAL(b4.cols(), 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(rows(b5), rotgen::Index{6}); - TTS_EQUAL(cols(b5), rotgen::Index{2}); + TTS_EQUAL(b5.rows(), rotgen::Index{6}); + TTS_EQUAL(b5.cols(), 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; @@ -93,9 +92,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) 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 5609df4..236aa01 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 < rows(m); ++i) - for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); + for (rotgen::Index i = 0; i < m.rows(); ++i) + for (rotgen::Index j = 0; j < m.cols(); ++j) f(i, j, m(i, j)); } template void for_each_element(EigenType& m, F&& f) { - for (rotgen::Index i = 0; i < rows(m); ++i) - for (rotgen::Index j = 0; j < cols(m); ++j) f(i, j, m(i, j)); + for (rotgen::Index i = 0; i < m.rows(); ++i) + for (rotgen::Index j = 0; j < m.cols(); ++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(rows(block), block_m); - TTS_EQUAL(cols(block), block_n); + TTS_EQUAL(block.rows(), block_m); + TTS_EQUAL(block.cols(), 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, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(c_block_bottom_left_corner, - rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(c_block_bottom_right_corner, - rows(matrix) - matrix_construct.ni, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, + matrix.cols() - 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, cols(matrix), + std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, - matrix_construct.ni, cols(matrix), rotgen::Dynamic, + matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(c_block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, - matrix_construct.ni, cols(matrix), rotgen::Dynamic, + std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, + matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, + std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, rows(matrix), + std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, - rows(matrix), matrix_construct.nj, + std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, + matrix.rows(), 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, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(block_bottom_left_corner, - rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), std::make_tuple(block_bottom_right_corner, - rows(matrix) - matrix_construct.ni, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, rotgen::Dynamic, rotgen::Dynamic), - std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), + std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), std::make_tuple(block_middle_rows, matrix_construct.i0, 0, - matrix_construct.ni, cols(matrix), rotgen::Dynamic, + matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(block_bottom_rows, rows(matrix) - matrix_construct.ni, 0, - matrix_construct.ni, cols(matrix), rotgen::Dynamic, + std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, + matrix_construct.ni, matrix.cols(), rotgen::Dynamic, MatrixType::ColsAtCompileTime), - std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, + std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(block_middle_cols, 0, matrix_construct.j0, rows(matrix), + std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj, MatrixType::RowsAtCompileTime, rotgen::Dynamic), - std::make_tuple(block_right_cols, 0, cols(matrix) - matrix_construct.nj, - rows(matrix), matrix_construct.nj, + std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, + matrix.rows(), 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, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(c_block_bottom_left_corner, - rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(c_block_bottom_right_corner, - rows(matrix) - matrix_construct.ni, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, + matrix.cols() - 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, cols(matrix), + std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic), std::make_tuple(c_block_middle_rows, i0, 0, matrix_construct.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), + 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), rotgen::Dynamic), - std::make_tuple(c_block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, + std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_middle_cols, 0, j0, rows(matrix), + std::make_tuple(c_block_middle_cols, 0, j0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_right_cols, 0, cols(matrix) - matrix_construct.nj, - rows(matrix), matrix_construct.nj, rotgen::Dynamic, + std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, + matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - 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), + 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), // -- 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, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_bottom_left_corner, - rows(matrix) - matrix_construct.ni, 0, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), std::make_tuple(block_bottom_right_corner, - rows(matrix) - matrix_construct.ni, - cols(matrix) - matrix_construct.nj, matrix_construct.ni, + matrix.rows() - matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, cols(matrix), + std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic), - 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), + 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), rotgen::Dynamic), - std::make_tuple(block_left_cols, 0, 0, rows(matrix), matrix_construct.nj, + std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - 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, + 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, int(NJ)), - 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::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::apply( [&](auto&&... block_entries) { @@ -358,9 +358,7 @@ 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; @@ -396,9 +394,7 @@ 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; @@ -421,9 +417,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; @@ -450,9 +446,9 @@ TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types) 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 0b44b42..e6f8fc3 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", rotgen::tests::types) test_value(m, T{0}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = rotgen::setZero(ni, nj); + auto values = input_type::Zero(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", rotgen::tests::types) test_value(m, T{0}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = rotgen::setZero(); + auto values = input_type::Zero(); 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", rotgen::tests::types) test_value(m, T{1}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = rotgen::setOnes(ni, nj); + auto values = input_type::Ones(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", rotgen::tests::types) test_value(m, T{1}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = rotgen::setOnes(); + auto values = input_type::Ones(); 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", rotgen::tests::types) test_value(m, T{13.37f}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = rotgen::setConstant(ni, nj, T{13.37f}); + auto values = input_type::Constant(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", rotgen::tests::types) test_value(m, T{13.37f}, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = rotgen::setConstant(T{13.37f}); + auto values = input_type::Constant(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", rotgen::tests::types) test_identity(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = rotgen::setIdentity(ni, nj); + auto values = input_type::Identity(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", rotgen::tests::types) test_identity(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = rotgen::setIdentity(); + auto values = input_type::Identity(); 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", rotgen::tests::types) test_random(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = rotgen::setRandom(ni, nj); + auto values = input_type::Random(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", rotgen::tests::types) test_random(m, i0, j0, D::ni, D::nj); using input_type = decltype(rotgen::extract(m, i0, j0)); - auto values = rotgen::setRandom(); + auto values = input_type::Random(); test_random(values, 0, 0, D::ni, D::nj); }; diff --git a/test/unit/common/arithmetic.hpp b/test/unit/common/arithmetic.hpp index f199cd2..4899850 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(cols(rotgen_input), rows(rotgen_input)); + eigen_mat_t eigen_result(rotgen_input.cols(), rotgen_input.rows()); 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 (rows(rotgen_input) == cols(rotgen_input)) + if (rotgen_input.rows() == rotgen_input.cols()) { 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(rows(rotgen_input), cols(rotgen_input)); + eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); 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 645fdb9..313361c 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(rows(rotgen_input), cols(rotgen_input)); + eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); prepare([&](auto r, auto c) { return rotgen_input(r, c); }, eigen_ref); - rotgen_mat_t rotgen_ref(rows(rotgen_input), cols(rotgen_input)); + rotgen_mat_t rotgen_ref(rotgen_input.rows(), rotgen_input.cols()); 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 < rows(rotgen_input); ++r) - for (rotgen::Index c = 0; c < cols(rotgen_input); ++c) + for (rotgen::Index r = 0; r < rotgen_input.rows(); ++r) + for (rotgen::Index c = 0; c < rotgen_input.cols(); ++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 b8750e4..711c190 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(rows(rotgen_input), cols(rotgen_input)); + eigen_mat_t eigen_ref(rotgen_input.rows(), rotgen_input.cols()); 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(rows(rotgen_input), cols(rotgen_input)); + rotgen_mat_t rotgen_norm_ref(rotgen_input.rows(), rotgen_input.cols()); 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 dcf361d..08a07d6 100644 --- a/test/unit/common/references.hpp +++ b/test/unit/common/references.hpp @@ -55,13 +55,8 @@ namespace rotgen::tests void prepare(auto fn, auto& output) { - for (rotgen::Index r = 0; r < rows(output); ++r) - { - for (rotgen::Index c = 0; c < cols(output); ++c) - { - output(r, c) = fn(r, c); - } - } + for (rotgen::Index r = 0; r < output.rows(); ++r) + for (rotgen::Index c = 0; c < output.cols(); ++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 ba4c829..9f67e41 100644 --- a/test/unit/functions/rowwise.cpp +++ b/test/unit/functions/rowwise.cpp @@ -10,9 +10,8 @@ #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; @@ -26,25 +25,24 @@ TTS_CASE_TPL("rowwise API", rotgen::tests::types) auto rotgen_rw = rotgen::rowwise(rotgen_mat); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++i) TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); - for (rotgen::Index i = 0; i < rows(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.rows(); ++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; @@ -58,18 +56,18 @@ TTS_CASE_TPL("colwise API", rotgen::tests::types) auto rotgen_rw = rotgen::colwise(rotgen_mat); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::sum(rotgen_rw)(i), eigen_ref_rw.sum()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::mean(rotgen_rw)(i), eigen_ref_rw.mean()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::prod(rotgen_rw)(i), eigen_ref_rw.prod()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::maxCoeff(rotgen_rw)(i), eigen_ref_rw.maxCoeff()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::minCoeff(rotgen_rw)(i), eigen_ref_rw.minCoeff()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++i) TTS_EQUAL(rotgen::squaredNorm(rotgen_rw)(i), eigen_ref_rw.squaredNorm()(i)); - for (rotgen::Index i = 0; i < cols(rotgen_mat); ++i) + for (rotgen::Index i = 0; i < rotgen_mat.cols(); ++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 f0412ac..23671a1 100644 --- a/test/unit/functions/svd.cpp +++ b/test/unit/functions/svd.cpp @@ -9,25 +9,25 @@ #include "unit/tests.hpp" -TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) - -(tts::type>) +TTS_CASE_TPL("SVD decomposition - Dynamic case", + rotgen::tests::types)( + tts::type>) { int rank, i = 5; auto eps = std::numeric_limits::epsilon(); - auto m = rotgen::setRandom< - rotgen::matrix>(5, 5); + auto m = + rotgen::matrix::Random(5, 5); auto decomp = rotgen::svd(m); do { rank = decomp.rank(); - auto u = decomp.matrixU(rank); - auto d = decomp.singularValues(rank); - auto dd = decomp.matrixD(rank); - auto v = decomp.matrixV(rank); + auto u = decomp.U(rank); + auto d = decomp.singular_values(rank); + auto dd = decomp.D(rank); + auto v = decomp.V(rank); TTS_EQUAL(rank, i); @@ -48,24 +48,24 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) } while (rank != 1); }; -TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types) - -(tts::type>) +TTS_CASE_TPL("SVD decomposition - Static case", + rotgen::tests::types)( + tts::type>) { int rank, i = 5; auto eps = std::numeric_limits::epsilon(); - auto m = rotgen::setRandom>(); + auto m = rotgen::matrix::Random(); auto decomp = rotgen::svd(m); do { rank = decomp.rank(); - auto u = decomp.matrixU(rank); - auto d = decomp.singularValues(rank); - auto dd = decomp.matrixD(rank); - auto v = decomp.matrixV(rank); + auto u = decomp.U(rank); + auto d = decomp.singular_values(rank); + auto dd = decomp.D(rank); + auto v = decomp.V(rank); TTS_EQUAL(rank, i); diff --git a/test/unit/map/arithmetic_functions.cpp b/test/unit/map/arithmetic_functions.cpp index 153fbb0..7544014 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(rows(base), cols(base), desc.init_fn, base); + rotgen::tests::prepare(base.rows(), base.cols(), 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(rows(base), cols(base), desc.init_fn, base); + rotgen::tests::prepare(base.rows(), base.cols(), 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 9566d11..773f6ad 100644 --- a/test/unit/map/basic_api.cpp +++ b/test/unit/map/basic_api.cpp @@ -9,41 +9,40 @@ #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(rows(dyn_map), rotgen::Index{1}); - TTS_EQUAL(cols(dyn_map), rotgen::Index{12}); + TTS_EQUAL(dyn_map.rows(), rotgen::Index{1}); + TTS_EQUAL(dyn_map.cols(), rotgen::Index{12}); rotgen::map> s112_map(data); - TTS_EQUAL(rows(s112_map), rotgen::Index{1}); - TTS_EQUAL(cols(s112_map), rotgen::Index{12}); + TTS_EQUAL(s112_map.rows(), rotgen::Index{1}); + TTS_EQUAL(s112_map.cols(), rotgen::Index{12}); TTS_EQUAL(s112_map.size(), rotgen::Index{12}); rotgen::map> s121_map(data); - TTS_EQUAL(rows(s121_map), rotgen::Index{12}); - TTS_EQUAL(cols(s121_map), rotgen::Index{1}); + TTS_EQUAL(s121_map.rows(), rotgen::Index{12}); + TTS_EQUAL(s121_map.cols(), rotgen::Index{1}); TTS_EQUAL(s121_map.size(), rotgen::Index{12}); rotgen::map> s34_map(data); - TTS_EQUAL(rows(s34_map), rotgen::Index{3}); - TTS_EQUAL(cols(s34_map), rotgen::Index{4}); + TTS_EQUAL(s34_map.rows(), rotgen::Index{3}); + TTS_EQUAL(s34_map.cols(), rotgen::Index{4}); TTS_EQUAL(s34_map.size(), rotgen::Index{12}); rotgen::map> s62_map(data); - TTS_EQUAL(rows(s62_map), rotgen::Index{6}); - TTS_EQUAL(cols(s62_map), rotgen::Index{2}); + TTS_EQUAL(s62_map.rows(), rotgen::Index{6}); + TTS_EQUAL(s62_map.cols(), 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; @@ -67,9 +66,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) 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 5442fea..9dda215 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", rotgen::tests::types) } }; -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(rows(base), cols(base), desc.init_fn, base); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); rotgen::map> input( base.data()); diff --git a/test/unit/map/norms.cpp b/test/unit/map/norms.cpp index 01b933f..2b93205 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", rotgen::tests::types) } }; -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(rows(base), cols(base), desc.init_fn, base); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); rotgen::map> input( base.data()); diff --git a/test/unit/map/strides.cpp b/test/unit/map/strides.cpp index 23b30ef..e0bf50a 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(innerStride(r_map), 1); - TTS_EQUAL(outerStride(r_map), 3); + TTS_EQUAL(r_map.innerStride(), 1); + TTS_EQUAL(r_map.outerStride(), 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(innerStride(r_map), 1); - TTS_EQUAL(outerStride(r_map), 4); + TTS_EQUAL(r_map.innerStride(), 1); + TTS_EQUAL(r_map.outerStride(), 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(innerStride(r_map), 2); - TTS_EQUAL(outerStride(r_map), 3); + TTS_EQUAL(r_map.innerStride(), 2); + TTS_EQUAL(r_map.outerStride(), 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(innerStride(r_map), 1); - TTS_EQUAL(outerStride(r_map), 4); + TTS_EQUAL(r_map.innerStride(), 1); + TTS_EQUAL(r_map.outerStride(), 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(innerStride(r_map), 1); - TTS_EQUAL(outerStride(r_map), 5); + TTS_EQUAL(r_map.innerStride(), 1); + TTS_EQUAL(r_map.outerStride(), 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(innerStride(r_map), 4); - TTS_EQUAL(outerStride(r_map), 2); + TTS_EQUAL(r_map.innerStride(), 4); + TTS_EQUAL(r_map.outerStride(), 2); e_map_t, Eigen::Stride> diff --git a/test/unit/matrix/arithmetic_functions.cpp b/test/unit/matrix/arithmetic_functions.cpp index e986603..2930dd5 100644 --- a/test/unit/matrix/arithmetic_functions.cpp +++ b/test/unit/matrix/arithmetic_functions.cpp @@ -13,9 +13,8 @@ #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) @@ -28,15 +27,14 @@ 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(rows(input), cols(input), desc.init_fn, input); + rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); rotgen::tests::check_shape_functions(input); }; @@ -44,9 +42,8 @@ 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) @@ -59,23 +56,21 @@ 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(rows(input), cols(input), desc.init_fn, input); + rotgen::tests::prepare(input.rows(), input.cols(), 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 a4e4e24..e54a59b 100644 --- a/test/unit/matrix/basic_api.cpp +++ b/test/unit/matrix/basic_api.cpp @@ -9,9 +9,8 @@ #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); @@ -26,87 +25,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 < rows(a); ++r) - for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = 42 + 2 * c + r; + 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; rotgen::resize(a, 3, 2); - TTS_EQUAL(rows(a), rotgen::Index(3)); - TTS_EQUAL(cols(a), rotgen::Index(2)); + TTS_EQUAL(a.rows(), rotgen::Index(3)); + TTS_EQUAL(a.cols(), rotgen::Index(2)); - for (rotgen::Index r = 0; r < rows(a); ++r) - for (rotgen::Index c = 0; c < cols(a); ++c) TTS_GREATER(a(r, c), 0); + for (rotgen::Index r = 0; r < a.rows(); ++r) + for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_GREATER(a(r, c), 0); rotgen::resize(a, 2, 2); - TTS_EQUAL(rows(a), rotgen::Index(2)); - TTS_EQUAL(cols(a), rotgen::Index(2)); + TTS_EQUAL(a.rows(), rotgen::Index(2)); + TTS_EQUAL(a.cols(), 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 < rows(a); ++r) - for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = i++; + for (rotgen::Index r = 0; r < a.rows(); ++r) + for (rotgen::Index c = 0; c < a.cols(); ++c) a(r, c) = i++; rotgen::conservativeResize(a, 2, 3); - TTS_EQUAL(rows(a), rotgen::Index(2)); - TTS_EQUAL(cols(a), rotgen::Index(3)); + TTS_EQUAL(a.rows(), rotgen::Index(2)); + TTS_EQUAL(a.cols(), rotgen::Index(3)); i = 1; - for (rotgen::Index r = 0; r < rows(a); ++r) - for (rotgen::Index c = 0; c < cols(a); ++c) TTS_EQUAL(a(r, c), i++); + for (rotgen::Index r = 0; r < a.rows(); ++r) + for (rotgen::Index c = 0; c < a.cols(); ++c) TTS_EQUAL(a(r, c), i++); rotgen::conservativeResize(a, 3, 2); - TTS_EQUAL(rows(a), rotgen::Index(3)); - TTS_EQUAL(cols(a), rotgen::Index(2)); + TTS_EQUAL(a.rows(), rotgen::Index(3)); + TTS_EQUAL(a.cols(), 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(rows(a), rotgen::Index(4)); - TTS_EQUAL(cols(a), rotgen::Index(4)); + TTS_EQUAL(a.rows(), rotgen::Index(4)); + TTS_EQUAL(a.cols(), rotgen::Index(4)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(3, 3), 0); rotgen::conservativeResize(a, 2, 2); - TTS_EQUAL(rows(a), rotgen::Index(2)); - TTS_EQUAL(cols(a), rotgen::Index(2)); + TTS_EQUAL(a.rows(), rotgen::Index(2)); + TTS_EQUAL(a.cols(), rotgen::Index(2)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(1, 1), 5); rotgen::conservativeResize(a, 1, 2); - TTS_EQUAL(rows(a), rotgen::Index(1)); - TTS_EQUAL(cols(a), rotgen::Index(2)); + TTS_EQUAL(a.rows(), rotgen::Index(1)); + TTS_EQUAL(a.cols(), rotgen::Index(2)); TTS_EQUAL(a(0, 0), 1); TTS_EQUAL(a(0, 1), 2); rotgen::conservativeResize(a, 0, 0); - TTS_EQUAL(rows(a), rotgen::Index(0)); - TTS_EQUAL(cols(a), rotgen::Index(0)); + TTS_EQUAL(a.rows(), rotgen::Index(0)); + TTS_EQUAL(a.cols(), rotgen::Index(0)); rotgen::conservativeResize(a, 3, 3); - TTS_EQUAL(rows(a), rotgen::Index(3)); - TTS_EQUAL(cols(a), rotgen::Index(3)); + TTS_EQUAL(a.rows(), rotgen::Index(3)); + TTS_EQUAL(a.cols(), 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 < rows(a); ++r) - for (rotgen::Index c = 0; c < cols(a); ++c) a(r, c) = r + 2 * c + 3; + 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; TTS_EQUAL(a(0, 0), 3); TTS_EQUAL(a(1, 1), 6); @@ -122,9 +121,9 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) 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 90a8029..0471a2b 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(rows(matrix), rotgen::Index{0}); - TTS_EQUAL(cols(matrix), rotgen::Index{0}); + TTS_EQUAL(matrix.rows(), rotgen::Index{0}); + TTS_EQUAL(matrix.cols(), 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(rows(matrix), rotgen::Index{4}); - TTS_EQUAL(cols(matrix), rotgen::Index{9}); + TTS_EQUAL(matrix.rows(), rotgen::Index{4}); + TTS_EQUAL(matrix.cols(), 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(rows(matrix), rotgen::Index{10}); - TTS_EQUAL(cols(matrix), rotgen::Index{5}); + TTS_EQUAL(matrix.rows(), rotgen::Index{10}); + TTS_EQUAL(matrix.cols(), 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 < rows(a); r++) - for (rotgen::Index c = 0; c < cols(a); c++) a(r, c) = r + c; + for (rotgen::Index r = 0; r < a.rows(); r++) + for (rotgen::Index c = 0; c < a.cols(); c++) a(r, c) = r + c; rotgen::matrix b = a; - TTS_EQUAL(rows(b), rows(a)); - TTS_EQUAL(cols(b), cols(a)); + TTS_EQUAL(b.rows(), a.rows()); + TTS_EQUAL(b.cols(), a.cols()); - 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)); + 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)); 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(rows(b), rotgen::Index{0}); - TTS_EQUAL(cols(b), rotgen::Index{0}); + TTS_EQUAL(b.rows(), rotgen::Index{0}); + TTS_EQUAL(b.cols(), 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(rows(b), rotgen::Index{2}); - TTS_EQUAL(cols(b), rotgen::Index{2}); + TTS_EQUAL(b.rows(), rotgen::Index{2}); + TTS_EQUAL(b.cols(), 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(rows(b), rotgen::Index{2}); - TTS_EQUAL(cols(b), rotgen::Index{5}); + TTS_EQUAL(b.rows(), rotgen::Index{2}); + TTS_EQUAL(b.cols(), 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(rows(b), 11); - TTS_EQUAL(cols(b), 4); + TTS_EQUAL(b.rows(), 11); + TTS_EQUAL(b.cols(), 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(rows(b), 5); - TTS_EQUAL(cols(b), 7); + TTS_EQUAL(b.rows(), 5); + TTS_EQUAL(b.cols(), 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(rows(b), rotgen::Index{3}); - TTS_EQUAL(cols(b), rotgen::Index{3}); + TTS_EQUAL(b.rows(), rotgen::Index{3}); + TTS_EQUAL(b.cols(), 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(rows(b), rotgen::Index{2}); - TTS_EQUAL(cols(b), rotgen::Index{2}); + TTS_EQUAL(b.rows(), rotgen::Index{2}); + TTS_EQUAL(b.cols(), 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(rows(b1), rotgen::Index{1}); - TTS_EQUAL(cols(b1), rotgen::Index{1}); + TTS_EQUAL(b1.rows(), rotgen::Index{1}); + TTS_EQUAL(b1.cols(), rotgen::Index{1}); TTS_EQUAL(b1(0), 3.5); rotgen::matrix b9{0.25, 0.5, 1, 2, 4}; - TTS_EQUAL(rows(b9), rotgen::Index{5}); - TTS_EQUAL(cols(b9), rotgen::Index{1}); + TTS_EQUAL(b9.rows(), rotgen::Index{5}); + TTS_EQUAL(b9.cols(), rotgen::Index{1}); T i = 0.25; - for (rotgen::Index r = 0; r < rows(b9); ++r) + for (rotgen::Index r = 0; r < b9.rows(); ++r) { TTS_EQUAL(b9(r, 0), i); i *= 2; } rotgen::matrix b13{1.2, 2.3, 3.4}; - TTS_EQUAL(rows(b13), rotgen::Index{1}); - TTS_EQUAL(cols(b13), rotgen::Index{3}); + TTS_EQUAL(b13.rows(), rotgen::Index{1}); + TTS_EQUAL(b13.cols(), 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(rows(b1), rotgen::Index{1}); - TTS_EQUAL(cols(b1), rotgen::Index{1}); + TTS_EQUAL(b1.rows(), rotgen::Index{1}); + TTS_EQUAL(b1.cols(), 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(rows(b23), rotgen::Index{2}); - TTS_EQUAL(cols(b23), rotgen::Index{3}); + TTS_EQUAL(b23.rows(), rotgen::Index{2}); + TTS_EQUAL(b23.cols(), 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 025cadd..ede5967 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", rotgen::tests::types) } }; -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(rows(input), cols(input), desc.init_fn, input); + rotgen::tests::prepare(input.rows(), input.cols(), 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 2bca121..dd9dacb 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", rotgen::tests::types) auto inv = rotgen::inverse(input); auto rec = input * inv; - auto id = rotgen::setIdentity(rotgen::rows(rec), rotgen::cols(rec)); + auto id = mat_t::Identity(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 = rotgen::setIdentity(rotgen::rows(rec), rotgen::cols(rec)); + auto id = mat_t::Identity(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 09816b2..cf9f812 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", rotgen::tests::types) } }; -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(rows(input), cols(input), desc.init_fn, input); + rotgen::tests::prepare(input.rows(), input.cols(), 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 d01efb3..e0b8c93 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 rr, - rotgen::Index cc, +void test_matrix_operations(rotgen::Index rows, + rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops) { - MatrixType a(rr, cc); - MatrixType b(rr, cc); - MatrixType ref(rr, cc); + MatrixType a(rows, cols); + MatrixType b(rows, cols); + MatrixType ref(rows, cols); - for (rotgen::Index r = 0; r < rr; ++r) + for (rotgen::Index r = 0; r < rows; ++r) { - for (rotgen::Index c = 0; c < cc; ++c) + for (rotgen::Index c = 0; c < cols; ++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 rr, } template -void test_scalar_operations(rotgen::Index rr, - rotgen::Index cc, +void test_scalar_operations(rotgen::Index rows, + rotgen::Index cols, auto a_init_fn, auto s, auto ops, auto self_ops) { - MatrixType a(rr, cc); - MatrixType ref(rr, cc); + MatrixType a(rows, cols); + MatrixType ref(rows, cols); - for (rotgen::Index r = 0; r < rr; ++r) + for (rotgen::Index r = 0; r < rows; ++r) { - for (rotgen::Index c = 0; c < cc; ++c) + for (rotgen::Index c = 0; c < cols; ++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 rr, } template -void test_scalar_multiplications(rotgen::Index rr, - rotgen::Index cc, +void test_scalar_multiplications(rotgen::Index rows, + rotgen::Index cols, auto fn, auto s) { - MatrixType a(rr, cc); - MatrixType ref(rr, cc); + MatrixType a(rows, cols); + MatrixType ref(rows, cols); - for (rotgen::Index r = 0; r < rr; ++r) + for (rotgen::Index r = 0; r < rows; ++r) { - for (rotgen::Index c = 0; c < cc; ++c) + for (rotgen::Index c = 0; c < cols; ++c) { a(r, c) = fn(r, c); ref(r, c) = a(r, c) * s; @@ -96,27 +96,27 @@ void test_scalar_multiplications(rotgen::Index rr, } template -void test_matrix_multiplication(rotgen::Index rr, - rotgen::Index cc, +void test_matrix_multiplication(rotgen::Index rows, + rotgen::Index cols, auto a_init_fn, auto b_init_fn) { - MatrixType a(rr, cc); - MatrixType b(cc, rr); - MatrixType ref(rr, rr); + MatrixType a(rows, cols); + MatrixType b(cols, rows); + MatrixType ref(rows, rows); - 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 < 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(b); ++r) - for (rotgen::Index c = 0; c < cols(b); ++c) b(r, c) = b_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 i = 0; i < rows(a); ++i) + for (rotgen::Index i = 0; i < a.rows(); ++i) { - for (rotgen::Index j = 0; j < cols(b); ++j) + for (rotgen::Index j = 0; j < b.cols(); ++j) { ref(i, j) = 0; - for (rotgen::Index k = 0; k < cols(a); ++k) + for (rotgen::Index k = 0; k < a.cols(); ++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", rotgen::tests::types) 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", rotgen::tests::types) 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", rotgen::tests::types) 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", rotgen::tests::types) 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 5513015..ed19e7c 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(rows(v), cols(v)); + data.resize(v.rows(), v.cols()); rotgen::setRandom(data); // Assign through the ref @@ -34,7 +34,7 @@ template void check_acceptance(Generator f) }; acceptor(in, in.data()); - data.resize(rows(in), cols(in)); + data.resize(in.rows(), in.cols()); TTS_EQUAL(in, data); TTS_EQUAL(constant_acceptor(in), minCoeff(data)) << in << "\n"