diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f8be83..59f422d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,12 +40,11 @@ handle_option(ROTGEN_COMPILE_DEFS) ##====================================================================================================================== if(ROTGEN_FORCE_DYNAMIC) set ( SOURCES - src/map.cpp - src/matrix.cpp - src/block.cpp + src/map/impl.cpp + src/matrix/impl.cpp + src/block/impl.cpp + src/svd/impl.cpp src/info.cpp - src/svd.cpp - src/operators.cpp src/format.cpp ) else() diff --git a/include/rotgen/algebra.hpp b/include/rotgen/algebra.hpp new file mode 100644 index 0000000..ea74232 --- /dev/null +++ b/include/rotgen/algebra.hpp @@ -0,0 +1,16 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +#if defined(ROTGEN_FORCE_DYNAMIC) +#include +#else +#include +#endif \ No newline at end of file diff --git a/include/rotgen/solver.hpp b/include/rotgen/algebra/qr.hpp similarity index 100% rename from include/rotgen/solver.hpp rename to include/rotgen/algebra/qr.hpp diff --git a/include/rotgen/dynamic/svd.hpp b/include/rotgen/algebra/svd/dynamic.hpp similarity index 96% rename from include/rotgen/dynamic/svd.hpp rename to include/rotgen/algebra/svd/dynamic.hpp index e40bd4b..f2c1551 100644 --- a/include/rotgen/dynamic/svd.hpp +++ b/include/rotgen/algebra/svd/dynamic.hpp @@ -7,7 +7,7 @@ //================================================================================================== #pragma once -#include +#include namespace rotgen { diff --git a/include/rotgen/impl/svd.hpp b/include/rotgen/algebra/svd/dynamic/impl.hpp similarity index 90% rename from include/rotgen/impl/svd.hpp rename to include/rotgen/algebra/svd/dynamic/impl.hpp index ad95258..4e5d2af 100644 --- a/include/rotgen/impl/svd.hpp +++ b/include/rotgen/algebra/svd/dynamic/impl.hpp @@ -24,13 +24,13 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef SOURCENAME #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef SOURCENAME @@ -42,13 +42,13 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef SOURCENAME #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef SOURCENAME diff --git a/include/rotgen/impl/svd_model.hpp b/include/rotgen/algebra/svd/dynamic/model.hpp similarity index 100% rename from include/rotgen/impl/svd_model.hpp rename to include/rotgen/algebra/svd/dynamic/model.hpp diff --git a/include/rotgen/fixed/svd.hpp b/include/rotgen/algebra/svd/fixed.hpp similarity index 67% rename from include/rotgen/fixed/svd.hpp rename to include/rotgen/algebra/svd/fixed.hpp index ff9cb0d..86a2448 100644 --- a/include/rotgen/fixed/svd.hpp +++ b/include/rotgen/algebra/svd/fixed.hpp @@ -26,19 +26,19 @@ namespace rotgen auto singular_values() const { - if constexpr(!use_expression_templates) return as_concrete_t{svd_.singularValues()}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{svd_.singularValues()}; else return svd_.singularValues(); } auto U() const { - if constexpr(!use_expression_templates) return as_concrete_t{svd_.matrixU()}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{svd_.matrixU()}; else return svd_.matrixU(); } auto V() const { - if constexpr(!use_expression_templates) return as_concrete_t{svd_.matrixV()}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{svd_.matrixV()}; else return svd_.matrixV(); } @@ -46,7 +46,7 @@ namespace rotgen { auto d = svd_.singularValues().asDiagonal(); if constexpr(!use_expression_templates) - return as_concrete_t{d.toDenseMatrix ()}; + return detail::as_concrete_t{d.toDenseMatrix ()}; else return d; } @@ -55,21 +55,21 @@ namespace rotgen auto singular_values(int r) const { auto that = svd_.singularValues().head(r); - if constexpr(!use_expression_templates) return as_concrete_t{that}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{that}; else return svd_.singularValues(); } auto U(int r) const { auto that = svd_.matrixU().leftCols(r); - if constexpr(!use_expression_templates) return as_concrete_t{that}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{that}; else return that; } auto V(int r) const { auto that = svd_.matrixV().leftCols(r); - if constexpr(!use_expression_templates) return as_concrete_t{that}; + if constexpr(!use_expression_templates) return detail::as_concrete_t{that}; else return that; } @@ -77,7 +77,7 @@ namespace rotgen { auto d = svd_.singularValues().head(r).asDiagonal(); if constexpr(!use_expression_templates) - return as_concrete_t{d.toDenseMatrix ()}; + return detail::as_concrete_t{d.toDenseMatrix ()}; else return d; } diff --git a/include/rotgen/common/traits.hpp b/include/rotgen/common/traits.hpp deleted file mode 100644 index 8d8df6a..0000000 --- a/include/rotgen/common/traits.hpp +++ /dev/null @@ -1,28 +0,0 @@ -//================================================================================================== -/* - ROTGEN - Runtime Overlay for Eigen - Copyright : CODE RECKONS - SPDX-License-Identifier: BSL-1.0 -*/ -//================================================================================================== -#pragma once - -namespace rotgen -{ - template< typename EigenType - , template typename Wrapper - > - struct as_concrete - { - using type = Wrapper< typename EigenType::value_type - , EigenType::RowsAtCompileTime, EigenType::ColsAtCompileTime - , EigenType::Flags & 1 - , EigenType::MaxRowsAtCompileTime, EigenType::MaxColsAtCompileTime - >; - }; - - template typename Wrapper - > - using as_concrete_t = typename as_concrete,Wrapper>::type; -} \ No newline at end of file diff --git a/include/rotgen/config.hpp b/include/rotgen/config.hpp index 3b17439..7ba46f2 100644 --- a/include/rotgen/config.hpp +++ b/include/rotgen/config.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include namespace rotgen diff --git a/include/rotgen/container.hpp b/include/rotgen/container.hpp new file mode 100644 index 0000000..60ff74b --- /dev/null +++ b/include/rotgen/container.hpp @@ -0,0 +1,13 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include +#include +#include +#include \ No newline at end of file diff --git a/include/rotgen/container/block.hpp b/include/rotgen/container/block.hpp new file mode 100644 index 0000000..099d35c --- /dev/null +++ b/include/rotgen/container/block.hpp @@ -0,0 +1,16 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +#if defined(ROTGEN_FORCE_DYNAMIC) +#include +#else +#include +#endif \ No newline at end of file diff --git a/include/rotgen/dynamic/block.hpp b/include/rotgen/container/block/dynamic.hpp similarity index 98% rename from include/rotgen/dynamic/block.hpp rename to include/rotgen/container/block/dynamic.hpp index 74eb41d..2ca0049 100644 --- a/include/rotgen/dynamic/block.hpp +++ b/include/rotgen/container/block/dynamic.hpp @@ -8,8 +8,8 @@ #pragma once #include -#include -#include +#include +#include #include #include @@ -39,6 +39,8 @@ namespace rotgen static constexpr int RowsAtCompileTime = Rows; static constexpr int ColsAtCompileTime = Cols; + static constexpr int MaxRowsAtCompileTime = Rows; + static constexpr int MaxColsAtCompileTime = Cols; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr int Options = Ref::Options; static constexpr bool IsRowMajor = (storage_order & RowMajor) == RowMajor; diff --git a/include/rotgen/impl/block.hpp b/include/rotgen/container/block/dynamic/impl.hpp similarity index 91% rename from include/rotgen/impl/block.hpp rename to include/rotgen/container/block/dynamic/impl.hpp index 0682a9f..3e0a07e 100644 --- a/include/rotgen/impl/block.hpp +++ b/include/rotgen/container/block/dynamic/impl.hpp @@ -8,8 +8,8 @@ #pragma once #include -#include -#include +#include +#include #include #include #include @@ -26,7 +26,7 @@ namespace rotgen #define CONST const #define BASENAME block_const_impl #define BASEMAP map_const_impl - #include + #include #undef BASENAME #undef BASEMAP #undef CONST @@ -35,7 +35,7 @@ namespace rotgen #define CONST #define BASENAME block_impl #define BASEMAP map_impl - #include + #include #undef BASENAME #undef BASEMAP #undef CONST diff --git a/include/rotgen/impl/block_indirect.hpp b/include/rotgen/container/block/dynamic/indirect.hpp similarity index 87% rename from include/rotgen/impl/block_indirect.hpp rename to include/rotgen/container/block/dynamic/indirect.hpp index f612cc1..d0dffa7 100644 --- a/include/rotgen/impl/block_indirect.hpp +++ b/include/rotgen/container/block/dynamic/indirect.hpp @@ -5,7 +5,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -15,7 +15,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -31,7 +31,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -41,7 +41,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME diff --git a/include/rotgen/impl/block_model.hpp b/include/rotgen/container/block/dynamic/model.hpp similarity index 100% rename from include/rotgen/impl/block_model.hpp rename to include/rotgen/container/block/dynamic/model.hpp diff --git a/include/rotgen/fixed/block.hpp b/include/rotgen/container/block/fixed.hpp similarity index 98% rename from include/rotgen/fixed/block.hpp rename to include/rotgen/container/block/fixed.hpp index ded13ce..710ce31 100644 --- a/include/rotgen/fixed/block.hpp +++ b/include/rotgen/container/block/fixed.hpp @@ -7,6 +7,7 @@ //================================================================================================== #pragma once +#include #include #include @@ -64,11 +65,13 @@ namespace rotgen using concrete_dynamic_type = matrix; template - using as_concrete_type = as_concrete_t; + using as_concrete_type = detail::as_concrete_t; static constexpr int Options = Ref::Options; static constexpr int RowsAtCompileTime = Rows; static constexpr int ColsAtCompileTime = Cols; + static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; + static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool is_defined_static = Rows!=-1 && Cols!=-1; static constexpr bool has_static_storage = storage_status; diff --git a/include/rotgen/container/map.hpp b/include/rotgen/container/map.hpp new file mode 100644 index 0000000..52b3e32 --- /dev/null +++ b/include/rotgen/container/map.hpp @@ -0,0 +1,16 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +#if defined(ROTGEN_FORCE_DYNAMIC) +#include +#else +#include +#endif \ No newline at end of file diff --git a/include/rotgen/dynamic/map.hpp b/include/rotgen/container/map/dynamic.hpp similarity index 96% rename from include/rotgen/dynamic/map.hpp rename to include/rotgen/container/map/dynamic.hpp index 80230db..9c57c9d 100644 --- a/include/rotgen/dynamic/map.hpp +++ b/include/rotgen/container/map/dynamic.hpp @@ -8,7 +8,7 @@ #pragma once #include -#include +#include #include #include @@ -40,6 +40,8 @@ namespace rotgen static constexpr int RowsAtCompileTime = Ref::RowsAtCompileTime; static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; + static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; + static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; static constexpr bool IsCompileTimeSized = RowsAtCompileTime != -1 && ColsAtCompileTime != -1; @@ -336,20 +338,20 @@ namespace rotgen }; template - detail::composite_matrix_type operator+(map const& lhs, map const& rhs) + detail::composite_type operator+(map const& lhs, map const& rhs) { using map1_type = map; using map2_type = map; - using concrete_type = detail::composite_matrix_type; + using concrete_type = detail::composite_type; return concrete_type(map1_type(lhs).base().add(map2_type(rhs))); } template - detail::composite_matrix_type operator-(map const& lhs, map const& rhs) + detail::composite_type operator-(map const& lhs, map const& rhs) { using map1_type = map; using map2_type = map; - using concrete_type = detail::composite_matrix_type; + using concrete_type = detail::composite_type; return concrete_type(map1_type(lhs).base().sub(map2_type(rhs))); } diff --git a/include/rotgen/impl/map.hpp b/include/rotgen/container/map/dynamic/impl.hpp similarity index 88% rename from include/rotgen/impl/map.hpp rename to include/rotgen/container/map/dynamic/impl.hpp index 003198a..9b770c7 100644 --- a/include/rotgen/impl/map.hpp +++ b/include/rotgen/container/map/dynamic/impl.hpp @@ -8,8 +8,8 @@ #pragma once #include -#include -#include +#include +#include #include #include #include @@ -28,14 +28,14 @@ namespace rotgen #define USE_CONST #define CONST const #define BASENAME map_const_impl - #include + #include #undef BASENAME #undef CONST #undef USE_CONST #define CONST #define BASENAME map_impl - #include + #include #undef BASENAME #undef CONST @@ -57,4 +57,4 @@ namespace rotgen >::type; } -#include +#include diff --git a/include/rotgen/impl/map_indirect.hpp b/include/rotgen/container/map/dynamic/indirect.hpp similarity index 90% rename from include/rotgen/impl/map_indirect.hpp rename to include/rotgen/container/map/dynamic/indirect.hpp index 6fa0c1b..f01ac94 100644 --- a/include/rotgen/impl/map_indirect.hpp +++ b/include/rotgen/container/map/dynamic/indirect.hpp @@ -6,7 +6,7 @@ #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -18,7 +18,7 @@ #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -36,7 +36,7 @@ #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -48,7 +48,7 @@ #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME diff --git a/include/rotgen/impl/map_model.hpp b/include/rotgen/container/map/dynamic/model.hpp similarity index 100% rename from include/rotgen/impl/map_model.hpp rename to include/rotgen/container/map/dynamic/model.hpp diff --git a/include/rotgen/impl/map_operators.hpp b/include/rotgen/container/map/dynamic/operators.hpp similarity index 100% rename from include/rotgen/impl/map_operators.hpp rename to include/rotgen/container/map/dynamic/operators.hpp diff --git a/include/rotgen/fixed/map.hpp b/include/rotgen/container/map/fixed.hpp similarity index 95% rename from include/rotgen/fixed/map.hpp rename to include/rotgen/container/map/fixed.hpp index 717d5a5..564c8ea 100644 --- a/include/rotgen/fixed/map.hpp +++ b/include/rotgen/container/map/fixed.hpp @@ -39,16 +39,18 @@ namespace rotgen using value_type = typename std::remove_const_t::value_type; using concrete_type = typename std::remove_const_t::concrete_type; - static constexpr Index RowsAtCompileTime = Ref::RowsAtCompileTime; - static constexpr Index ColsAtCompileTime = Ref::ColsAtCompileTime; - static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; - static constexpr bool has_static_storage = Ref::has_static_storage; - static constexpr int storage_order = Ref::storage_order; - static constexpr bool is_immutable = std::is_const_v; - static constexpr bool is_defined_static = Ref::is_defined_static; + static constexpr int RowsAtCompileTime = Ref::RowsAtCompileTime; + static constexpr int ColsAtCompileTime = Ref::ColsAtCompileTime; + static constexpr int MaxRowsAtCompileTime = Ref::MaxRowsAtCompileTime; + static constexpr int MaxColsAtCompileTime = Ref::MaxColsAtCompileTime; + static constexpr bool IsVectorAtCompileTime = Ref::IsVectorAtCompileTime; + static constexpr bool has_static_storage = Ref::has_static_storage; + static constexpr int storage_order = Ref::storage_order; + static constexpr bool is_immutable = std::is_const_v; + static constexpr bool is_defined_static = Ref::is_defined_static; template - using as_concrete_type = as_concrete_t; + using as_concrete_type = detail::as_concrete_t; using ptr_type = std::conditional_t; using stride_type = Stride; diff --git a/include/rotgen/container/matrix.hpp b/include/rotgen/container/matrix.hpp new file mode 100644 index 0000000..14d78ae --- /dev/null +++ b/include/rotgen/container/matrix.hpp @@ -0,0 +1,16 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +#if defined(ROTGEN_FORCE_DYNAMIC) +#include +#else +#include +#endif \ No newline at end of file diff --git a/include/rotgen/dynamic/matrix.hpp b/include/rotgen/container/matrix/dynamic.hpp similarity index 93% rename from include/rotgen/dynamic/matrix.hpp rename to include/rotgen/container/matrix/dynamic.hpp index 46c785e..f70859b 100644 --- a/include/rotgen/dynamic/matrix.hpp +++ b/include/rotgen/container/matrix/dynamic.hpp @@ -7,7 +7,8 @@ //================================================================================================== #pragma once -#include +#include +#include #include #include @@ -26,16 +27,18 @@ namespace rotgen using concrete_type = matrix; using value_type = Scalar; - static constexpr auto storage_order = Opts & 1; - static constexpr Index RowsAtCompileTime = Rows; - static constexpr Index ColsAtCompileTime = Cols; - static constexpr bool IsCompileTimeSized = Rows != -1 && Cols != -1; - static constexpr bool IsVectorAtCompileTime = (RowsAtCompileTime == 1) || (ColsAtCompileTime == 1); - static constexpr int Options = Opts; - static constexpr bool IsRowMajor = (Opts & RowMajor) == RowMajor; - static constexpr bool is_defined_static = false; - static constexpr bool has_static_storage = false; - static constexpr bool is_immutable = false; + static constexpr auto storage_order = Opts & 1; + static constexpr int RowsAtCompileTime = Rows; + static constexpr int ColsAtCompileTime = Cols; + static constexpr int MaxRowsAtCompileTime = MaxRows; + static constexpr int MaxColsAtCompileTime = MaxCols; + static constexpr bool IsCompileTimeSized = Rows != -1 && Cols != -1; + static constexpr bool IsVectorAtCompileTime = (RowsAtCompileTime == 1) || (ColsAtCompileTime == 1); + static constexpr int Options = Opts; + static constexpr bool IsRowMajor = (Opts & RowMajor) == RowMajor; + static constexpr bool is_defined_static = false; + static constexpr bool has_static_storage = false; + static constexpr bool is_immutable = false; using transposed_type = matrix; diff --git a/include/rotgen/impl/matrix.hpp b/include/rotgen/container/matrix/dynamic/impl.hpp similarity index 88% rename from include/rotgen/impl/matrix.hpp rename to include/rotgen/container/matrix/dynamic/impl.hpp index dd1e5a8..51ee304 100644 --- a/include/rotgen/impl/matrix.hpp +++ b/include/rotgen/container/matrix/dynamic/impl.hpp @@ -8,7 +8,7 @@ #pragma once #include -#include +#include #include #include #include @@ -26,13 +26,13 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME @@ -44,13 +44,13 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include + #include #undef CLASSNAME #undef TRANSCLASSNAME diff --git a/include/rotgen/impl/matrix_model.hpp b/include/rotgen/container/matrix/dynamic/model.hpp similarity index 100% rename from include/rotgen/impl/matrix_model.hpp rename to include/rotgen/container/matrix/dynamic/model.hpp diff --git a/include/rotgen/fixed/matrix.hpp b/include/rotgen/container/matrix/fixed.hpp similarity index 95% rename from include/rotgen/fixed/matrix.hpp rename to include/rotgen/container/matrix/fixed.hpp index 71741c9..b01e079 100644 --- a/include/rotgen/fixed/matrix.hpp +++ b/include/rotgen/container/matrix/fixed.hpp @@ -7,6 +7,7 @@ //================================================================================================== #pragma once +#include #include #include @@ -38,15 +39,17 @@ namespace rotgen using concrete_type = matrix; using concrete_dynamic_type = matrix; - static constexpr int RowsAtCompileTime = Rows; - static constexpr int ColsAtCompileTime = Cols; - static constexpr bool IsCompileTimeSized = Rows != -1 && Cols != -1; - static constexpr bool IsVectorAtCompileTime = (RowsAtCompileTime == 1) || (ColsAtCompileTime == 1); - static constexpr int Options = parent::Options; - static constexpr bool IsRowMajor = parent::IsRowMajor; + static constexpr int RowsAtCompileTime = Rows; + static constexpr int ColsAtCompileTime = Cols; + static constexpr int MaxRowsAtCompileTime = MaxRows; + static constexpr int MaxColsAtCompileTime = MaxCols; + static constexpr bool IsCompileTimeSized = Rows != -1 && Cols != -1; + static constexpr bool IsVectorAtCompileTime = (RowsAtCompileTime == 1) || (ColsAtCompileTime == 1); + static constexpr int Options = parent::Options; + static constexpr bool IsRowMajor = parent::IsRowMajor; template - using as_concrete_type = as_concrete_t; + using as_concrete_type = detail::as_concrete_t; static constexpr bool is_immutable = false; static constexpr bool is_defined_static = Rows!=-1 && Cols!=-1; diff --git a/include/rotgen/common/ref.hpp b/include/rotgen/container/ref.hpp similarity index 100% rename from include/rotgen/common/ref.hpp rename to include/rotgen/container/ref.hpp diff --git a/include/rotgen/common/strides.hpp b/include/rotgen/container/strides.hpp similarity index 100% rename from include/rotgen/common/strides.hpp rename to include/rotgen/container/strides.hpp diff --git a/include/rotgen/common/export.hpp b/include/rotgen/detail/export.hpp similarity index 100% rename from include/rotgen/common/export.hpp rename to include/rotgen/detail/export.hpp diff --git a/include/rotgen/detail/helpers.hpp b/include/rotgen/detail/helpers.hpp index dd17f40..6b7e8a7 100644 --- a/include/rotgen/detail/helpers.hpp +++ b/include/rotgen/detail/helpers.hpp @@ -9,6 +9,23 @@ namespace rotgen::detail { + template< typename EigenType + , template typename Wrapper + > + struct as_concrete + { + using type = Wrapper< typename EigenType::value_type + , EigenType::RowsAtCompileTime, EigenType::ColsAtCompileTime + , EigenType::Flags & 1 + , EigenType::MaxRowsAtCompileTime, EigenType::MaxColsAtCompileTime + >; + }; + + template typename Wrapper + > + using as_concrete_t = typename as_concrete,Wrapper>::type; + template inline constexpr bool has_same_vector_size = []() { @@ -28,10 +45,14 @@ namespace rotgen::detail template inline constexpr auto select_static = (M==rotgen::Dynamic || N==rotgen::Dynamic) ? rotgen::Dynamic : M; - template - using composite_matrix_type = matrix< typename M1::value_type - , select_static - , select_static - , M1::storage_order - >; + template< typename M1, typename M2 + , template typename Wrapper + > + using composite_type = Wrapper< typename M1::value_type + , select_static + , select_static + , M1::storage_order + , select_static + , select_static + >; } \ No newline at end of file diff --git a/include/rotgen/impl/payload.hpp b/include/rotgen/detail/payload.hpp similarity index 98% rename from include/rotgen/impl/payload.hpp rename to include/rotgen/detail/payload.hpp index 72ec4b5..54a66a2 100644 --- a/include/rotgen/impl/payload.hpp +++ b/include/rotgen/detail/payload.hpp @@ -9,8 +9,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/include/rotgen/format.hpp b/include/rotgen/format.hpp new file mode 100644 index 0000000..ad9d29c --- /dev/null +++ b/include/rotgen/format.hpp @@ -0,0 +1,14 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#if defined(ROTGEN_FORCE_DYNAMIC) +#include +#else +#include +#endif \ No newline at end of file diff --git a/include/rotgen/dynamic/format.hpp b/include/rotgen/format/dynamic.hpp similarity index 100% rename from include/rotgen/dynamic/format.hpp rename to include/rotgen/format/dynamic.hpp diff --git a/include/rotgen/fixed/format.hpp b/include/rotgen/format/fixed.hpp similarity index 97% rename from include/rotgen/fixed/format.hpp rename to include/rotgen/format/fixed.hpp index 7c2ced5..fb890bc 100644 --- a/include/rotgen/fixed/format.hpp +++ b/include/rotgen/format/fixed.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include diff --git a/include/rotgen/functions.hpp b/include/rotgen/functions.hpp index 786bf0c..6434144 100644 --- a/include/rotgen/functions.hpp +++ b/include/rotgen/functions.hpp @@ -7,325 +7,7 @@ //================================================================================================== #pragma once -#include - -namespace rotgen -{ - //----------------------------------------------------------------------------------------------- - // Infos & Shape - //----------------------------------------------------------------------------------------------- - std::size_t rows(auto const& m) requires(requires{ m.rows(); }){ return m.rows(); } - std::size_t cols(auto const& m) requires(requires{ m.cols(); }){ return m.cols(); } - std::size_t size(auto const& m) requires(requires{ m.size(); }){ return m.size(); } - - void resize(auto& a, int s) requires requires{a.resize(s);} { a.resize(s); } - void resize(auto& a, int r, int c) requires requires{a.resize(r,c);} { a.resize(r,c); } - - void conservativeResize(auto& a, int s) requires requires{a.conservativeResize(s);} - { - a.conservativeResize(s); - } - - void conservativeResize(auto& a, int r, int c) requires requires{a.conservativeResize(r,c);} - { - a.conservativeResize(r, c); - } - - //----------------------------------------------------------------------------------------------- - // Global operations - //----------------------------------------------------------------------------------------------- - decltype(auto) normalized (auto const& m) requires(requires{ m.normalized(); }) { return m.normalized(); } - decltype(auto) transpose (auto const& m) requires(requires{ m.transpose(); }) { return m.transpose(); } - decltype(auto) conjugate (auto const& m) requires(requires{ m.conjugate(); }) { return m.conjugate(); } - decltype(auto) adjoint (auto const& m) requires(requires{ m.adjoint(); }) { return m.adjoint(); } - - void normalize(auto& a) requires(requires{ a.normalize(); }) { a.normalize(); } - void transposeInPlace(auto& a) requires(requires{ a.transposeInPlace(); }) { a.transposeInPlace(); } - void adjointInPlace(auto& a) requires(requires{ a.adjointInPlace(); }) { a.adjointInPlace(); } - - //----------------------------------------------------------------------------------------------- - // Component-wise functions - //----------------------------------------------------------------------------------------------- - auto abs (auto const& arg) requires(requires{arg.cwiseAbs();} ) { return arg.cwiseAbs(); } - auto abs2(auto const& arg) requires(requires{arg.cwiseAbs2();} ) { return arg.cwiseAbs2(); } - auto rec (auto const& arg) requires(requires{arg.cwiseInverse();}) { return arg.cwiseInverse(); } - auto sqrt(auto const& arg) requires(requires{arg.cwiseSqrt();} ) { return arg.cwiseSqrt(); } - - template - auto min(A const& a, B const& b) - { - if constexpr(!use_expression_templates) return min(generalize_t(a), generalize_t(b)); - else return base_of(a).cwiseMin(base_of(b)); - } - - 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); - } - - 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); - } - - 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)); - } - - 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); - } - - 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); - } - - 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)); - } - - template - auto mul(A const& a, std::convertible_to auto b) - { - return a * b; - } - - template - auto mul(std::convertible_to auto a, B const& b) - { - return a * b; - } - - template - 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(); - } - - template - auto div(A const& a, std::convertible_to auto b) - { - return a / b; - } - - //----------------------------------------------------------------------------------------------- - // Reductions - //----------------------------------------------------------------------------------------------- - auto trace(concepts::entity auto const& arg) { return arg.trace(); } - auto squaredNorm(concepts::entity auto const& arg) { return arg.squaredNorm(); } - auto norm(concepts::entity auto const& arg) { return arg.norm(); } - auto sum(auto const& arg) requires requires{ arg.sum(); } { return arg.sum(); } - auto prod(concepts::entity auto const& arg) { return arg.prod(); } - auto mean(concepts::entity auto const& arg) { return arg.mean(); } - - template - auto dot(A const& a, B const& b) - requires(detail::has_same_vector_size && 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)); - } - - auto maxCoeff(auto const& arg) requires( requires{ arg.maxCoeff(); } ) { return arg.maxCoeff(); } - auto minCoeff(auto const& arg) requires( requires{ arg.minCoeff(); } ) { return arg.minCoeff(); } - - template - auto maxCoeff(concepts::entity auto const& arg, IndexType* row, IndexType* col) - { - return arg.maxCoeff(row, col); - } - - template - auto minCoeff(concepts::entity auto const& arg, IndexType* row, IndexType* col) - { - return arg.minCoeff(row, col); - } - - template - auto lpNorm(T const& arg) requires( requires{arg.template lpNorm

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

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

(); + } + + //----------------------------------------------------------------------------------------------- + // Expression handling + //----------------------------------------------------------------------------------------------- + template + decltype(auto) noalias(T&& t) requires( requires{std::forward(t).noalias();} ) + { + return std::forward(t).noalias(); + } + + template + auto evaluate(T&& t) requires( requires{std::forward(t).evaluate();} ) + { + return std::forward(t).evaluate(); + } + + template + auto evaluate(T&& t) requires( requires{std::forward(t).eval();} ) + { + return std::forward(t).eval(); + } + + //----------------------------------------------------------------------------------------------- + // Generators + //----------------------------------------------------------------------------------------------- + template + auto setZero(T&& t) requires( requires{std::forward(t).setZero();} ) + { + return std::forward(t).setZero(); + } + + template + auto setZero() requires( requires{T::Zero();} ) + { + return T::Zero(); + } + + template + auto setZero(std::integral auto n) requires( requires{T::Zero(n);} ) + { + return T::Zero(n); + } + + template + auto setZero(std::integral auto r,std::integral auto c) requires( requires{T::Zero(r,c);} ) + { + return T::Zero(r,c); + } + + template + auto setOnes(T&& t) requires( requires{std::forward(t).setOnes();} ) + { + return std::forward(t).setOnes(); + } + + template + auto setOnes() requires( requires{T::Ones();} ) + { + return T::Ones(); + } + + template + auto setOnes(std::integral auto n) requires( requires{T::Ones(n);} ) + { + return T::Ones(n); + } + + template + auto setOnes(std::integral auto r,std::integral auto c) requires( requires{T::Ones(r,c);} ) + { + return T::Ones(r,c); + } + + template + auto setIdentity(T&& t) requires( requires{std::forward(t).setIdentity();} ) + { + return std::forward(t).setIdentity(); + } + + template + auto setIdentity() requires( requires{T::Identity();} ) + { + return T::Identity(); + } + + template + auto setIdentity(std::integral auto n) requires( requires{T::Identity(n);} ) + { + return T::Identity(n); + } + + template + auto setIdentity(std::integral auto r,std::integral auto c) requires( requires{T::Identity(r,c);} ) + { + return T::Identity(r,c); + } + + template + auto setRandom(T&& t) requires( requires{std::forward(t).setRandom();} ) + { + return std::forward(t).setRandom(); + } + + template + auto setRandom() requires( requires{T::Random();} ) + { + return T::Random(); + } + + template + auto setRandom(std::integral auto n) requires( requires{T::Random(n);} ) + { + return T::Random(n); + } + + template + auto setRandom(std::integral auto r,std::integral auto c) requires( requires{T::Random(r,c);} ) + { + return T::Random(r,c); + } + + template + auto setConstant(T&& t, auto v) requires( requires{std::forward(t).setConstant(v);} ) + { + return std::forward(t).setConstant(v); + } + + template + auto setConstant(auto v) requires( requires{T::Constant(v);} ) + { + return T::Constant(v); + } + + template + auto setConstant(std::integral auto n, auto v) requires( requires{T::Constant(n,v);} ) + { + 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);} ) + { + return T::Constant(r,c,v); + } + + //----------------------------------------------------------------------------------------------- + // 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 if constexpr(requires{typename A::rotgen_tag;}) return base_of(a).inverse(); + else return 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); + } +} \ No newline at end of file diff --git a/include/rotgen/operators.hpp b/include/rotgen/functions/operators.hpp similarity index 100% rename from include/rotgen/operators.hpp rename to include/rotgen/functions/operators.hpp diff --git a/include/rotgen/common/reshaper.hpp b/include/rotgen/functions/reshaper.hpp similarity index 100% rename from include/rotgen/common/reshaper.hpp rename to include/rotgen/functions/reshaper.hpp diff --git a/include/rotgen/rotgen.hpp b/include/rotgen/rotgen.hpp index bd42479..882b956 100644 --- a/include/rotgen/rotgen.hpp +++ b/include/rotgen/rotgen.hpp @@ -8,28 +8,8 @@ #pragma once #include -#include -#include -#include - -#if defined(ROTGEN_FORCE_DYNAMIC) -#include -#include -#include -#include -#include -#else -#include -#include -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include +#include +#include #include +#include +#include diff --git a/src/block_indirect.cpp b/src/block/generate.cpp similarity index 94% rename from src/block_indirect.cpp rename to src/block/generate.cpp index 0e08f39..5eb5314 100644 --- a/src/block_indirect.cpp +++ b/src/block/generate.cpp @@ -13,7 +13,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col) -#include "block_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -25,7 +25,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row) -#include "block_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -43,7 +43,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_col) -#include "block_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME @@ -55,7 +55,7 @@ #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define MAPNAME ROTGEN_MATRIX_NAME(BASEMAP,SIZE,_row) -#include "block_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME #undef SOURCENAME diff --git a/src/block.cpp b/src/block/impl.cpp similarity index 83% rename from src/block.cpp rename to src/block/impl.cpp index 8cae7d6..a450e16 100644 --- a/src/block.cpp +++ b/src/block/impl.cpp @@ -6,8 +6,8 @@ */ //================================================================================================== #include -#include -#include +#include +#include #include #include @@ -17,7 +17,7 @@ namespace rotgen #define CONST const #define BASENAME block_const_impl #define BASEMAP map_const_impl - #include "block_indirect.cpp" + #include "generate.cpp" #undef BASENAME #undef BASEMAP #undef USE_CONST @@ -26,7 +26,7 @@ namespace rotgen #define CONST #define BASENAME block_impl #define BASEMAP map_impl - #include "block_indirect.cpp" + #include "generate.cpp" #undef BASENAME #undef BASEMAP #undef CONST diff --git a/src/block_model.cpp b/src/block/model.cpp similarity index 100% rename from src/block_model.cpp rename to src/block/model.cpp diff --git a/src/format.cpp b/src/format.cpp index 474a13b..4d74c74 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -7,8 +7,8 @@ //================================================================================================== #include -#include -#include +#include +#include #include #include diff --git a/src/info.cpp b/src/info.cpp index 91361ca..8d1d04a 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -7,7 +7,6 @@ */ //================================================================================================== #include -#include namespace rotgen::detail { diff --git a/src/map_indirect.cpp b/src/map/generate.cpp similarity index 95% rename from src/map_indirect.cpp rename to src/map/generate.cpp index fed2ac7..0bfdfac 100644 --- a/src/map_indirect.cpp +++ b/src/map/generate.cpp @@ -14,7 +14,7 @@ #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) -#include "map_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -28,7 +28,7 @@ #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) -#include "map_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -48,7 +48,7 @@ #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) -#include "map_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME @@ -62,7 +62,7 @@ #define TRANSSOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define CLASSCONSTNAME ROTGEN_MATRIX_NAME(map_const_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) -#include "map_model.cpp" +#include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef TRANSSOURCENAME diff --git a/src/map.cpp b/src/map/impl.cpp similarity index 79% rename from src/map.cpp rename to src/map/impl.cpp index c7d5d41..6766b92 100644 --- a/src/map.cpp +++ b/src/map/impl.cpp @@ -6,8 +6,8 @@ */ //================================================================================================== #include -#include -#include +#include +#include #include #include @@ -16,14 +16,16 @@ namespace rotgen #define USE_CONST #define CONST const #define BASENAME map_const_impl - #include "map_indirect.cpp" + #include "generate.cpp" #undef BASENAME #undef USE_CONST #undef CONST #define CONST #define BASENAME map_impl - #include "map_indirect.cpp" + #include "generate.cpp" #undef BASENAME #undef CONST } + +#include "operators.cpp" diff --git a/src/map_model.cpp b/src/map/model.cpp similarity index 100% rename from src/map_model.cpp rename to src/map/model.cpp diff --git a/src/operators.cpp b/src/map/operators.cpp similarity index 86% rename from src/operators.cpp rename to src/map/operators.cpp index 9679c46..04ffb41 100644 --- a/src/operators.cpp +++ b/src/map/operators.cpp @@ -6,11 +6,11 @@ */ //================================================================================================== -#include -#include +#include +#include #include -#define ROTGEN_IMPL_OP(OP,FN,RET) \ +#define ROTGEN_IMPL_OP(OP,FN,RET) \ RET operator OP(map_const_impl32_col const& a, map_impl32_col const& b ) { return FN(a, b); } \ RET operator OP(map_const_impl32_col const& a, map_impl32_row const& b ) { return FN(a, b); } \ RET operator OP(map_const_impl32_col const& a, map_const_impl32_row const& b ) { return FN(a, b); } \ @@ -29,12 +29,9 @@ namespace rotgen { namespace { - auto add(auto const& a, auto const& b) { return a.storage()->data + b.storage()->data; } - auto sub(auto const& a, auto const& b) { return a.storage()->data - b.storage()->data; } bool equal(auto const& a, auto const& b) { return a.storage()->data == b.storage()->data; } bool not_equal(auto const& a, auto const& b) { return a.storage()->data != b.storage()->data; } } - ROTGEN_IMPL_OP(==, equal , bool); ROTGEN_IMPL_OP(!=, not_equal, bool); } \ No newline at end of file diff --git a/src/matrix.cpp b/src/matrix/impl.cpp similarity index 89% rename from src/matrix.cpp rename to src/matrix/impl.cpp index f8d7c05..f3702a9 100644 --- a/src/matrix.cpp +++ b/src/matrix/impl.cpp @@ -6,8 +6,8 @@ */ //================================================================================================== #include -#include -#include +#include +#include #include #include @@ -19,7 +19,7 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "matrix_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef STORAGE_ORDER @@ -27,7 +27,7 @@ namespace rotgen #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "matrix_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef STORAGE_ORDER @@ -41,7 +41,7 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "matrix_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef STORAGE_ORDER @@ -49,7 +49,7 @@ namespace rotgen #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "matrix_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME #undef STORAGE_ORDER diff --git a/src/matrix_model.cpp b/src/matrix/model.cpp similarity index 100% rename from src/matrix_model.cpp rename to src/matrix/model.cpp diff --git a/src/svd.cpp b/src/svd/impl.cpp similarity index 86% rename from src/svd.cpp rename to src/svd/impl.cpp index d85ff3e..b5d4b4f 100644 --- a/src/svd.cpp +++ b/src/svd/impl.cpp @@ -6,9 +6,9 @@ */ //================================================================================================== #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -21,7 +21,7 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "svd_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef SOURCENAME #undef STORAGE_ORDER @@ -29,7 +29,7 @@ namespace rotgen #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "svd_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef SOURCENAME #undef STORAGE_ORDER @@ -43,7 +43,7 @@ namespace rotgen #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "svd_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef SOURCENAME #undef STORAGE_ORDER @@ -51,7 +51,7 @@ namespace rotgen #define STORAGE_ORDER Eigen::RowMajor #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "svd_model.cpp" + #include "model.cpp" #undef CLASSNAME #undef SOURCENAME #undef STORAGE_ORDER diff --git a/src/svd_model.cpp b/src/svd/model.cpp similarity index 100% rename from src/svd_model.cpp rename to src/svd/model.cpp

(); - } - - //----------------------------------------------------------------------------------------------- - // Expression handling - //----------------------------------------------------------------------------------------------- - template - decltype(auto) noalias(T&& t) requires( requires{std::forward(t).noalias();} ) - { - return std::forward(t).noalias(); - } - - template - auto evaluate(T&& t) requires( requires{std::forward(t).evaluate();} ) - { - return std::forward(t).evaluate(); - } - - template - auto evaluate(T&& t) requires( requires{std::forward(t).eval();} ) - { - return std::forward(t).eval(); - } - - //----------------------------------------------------------------------------------------------- - // Generators - //----------------------------------------------------------------------------------------------- - template - auto setZero(T&& t) requires( requires{std::forward(t).setZero();} ) - { - return std::forward(t).setZero(); - } - - template - auto setZero() requires( requires{T::Zero();} ) - { - return T::Zero(); - } - - template - auto setZero(std::integral auto n) requires( requires{T::Zero(n);} ) - { - return T::Zero(n); - } - - template - auto setZero(std::integral auto r,std::integral auto c) requires( requires{T::Zero(r,c);} ) - { - return T::Zero(r,c); - } - - template - auto setOnes(T&& t) requires( requires{std::forward(t).setOnes();} ) - { - return std::forward(t).setOnes(); - } - - template - auto setOnes() requires( requires{T::Ones();} ) - { - return T::Ones(); - } - - template - auto setOnes(std::integral auto n) requires( requires{T::Ones(n);} ) - { - return T::Ones(n); - } - - template - auto setOnes(std::integral auto r,std::integral auto c) requires( requires{T::Ones(r,c);} ) - { - return T::Ones(r,c); - } - - template - auto setIdentity(T&& t) requires( requires{std::forward(t).setIdentity();} ) - { - return std::forward(t).setIdentity(); - } - - template - auto setIdentity() requires( requires{T::Identity();} ) - { - return T::Identity(); - } - - template - auto setIdentity(std::integral auto n) requires( requires{T::Identity(n);} ) - { - return T::Identity(n); - } - - template - auto setIdentity(std::integral auto r,std::integral auto c) requires( requires{T::Identity(r,c);} ) - { - return T::Identity(r,c); - } - - template - auto setRandom(T&& t) requires( requires{std::forward(t).setRandom();} ) - { - return std::forward(t).setRandom(); - } - - template - auto setRandom() requires( requires{T::Random();} ) - { - return T::Random(); - } - - template - auto setRandom(std::integral auto n) requires( requires{T::Random(n);} ) - { - return T::Random(n); - } - - template - auto setRandom(std::integral auto r,std::integral auto c) requires( requires{T::Random(r,c);} ) - { - return T::Random(r,c); - } - - template - auto setConstant(T&& t, auto v) requires( requires{std::forward(t).setConstant(v);} ) - { - return std::forward(t).setConstant(v); - } - - template - auto setConstant(auto v) requires( requires{T::Constant(v);} ) - { - return T::Constant(v); - } - - template - auto setConstant(std::integral auto n, auto v) requires( requires{T::Constant(n,v);} ) - { - 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);} ) - { - return T::Constant(r,c,v); - } - - //----------------------------------------------------------------------------------------------- - // 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 if constexpr(requires{typename A::rotgen_tag;}) return base_of(a).inverse(); - else return 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); - } -} \ No newline at end of file +#include +#include +#include +#include \ No newline at end of file diff --git a/include/rotgen/extract.hpp b/include/rotgen/functions/extract.hpp similarity index 100% rename from include/rotgen/extract.hpp rename to include/rotgen/functions/extract.hpp diff --git a/include/rotgen/functions/functions.hpp b/include/rotgen/functions/functions.hpp new file mode 100644 index 0000000..786bf0c --- /dev/null +++ b/include/rotgen/functions/functions.hpp @@ -0,0 +1,331 @@ +//================================================================================================== +/* + ROTGEN - Runtime Overlay for Eigen + Copyright : CODE RECKONS + SPDX-License-Identifier: BSL-1.0 +*/ +//================================================================================================== +#pragma once + +#include + +namespace rotgen +{ + //----------------------------------------------------------------------------------------------- + // Infos & Shape + //----------------------------------------------------------------------------------------------- + std::size_t rows(auto const& m) requires(requires{ m.rows(); }){ return m.rows(); } + std::size_t cols(auto const& m) requires(requires{ m.cols(); }){ return m.cols(); } + std::size_t size(auto const& m) requires(requires{ m.size(); }){ return m.size(); } + + void resize(auto& a, int s) requires requires{a.resize(s);} { a.resize(s); } + void resize(auto& a, int r, int c) requires requires{a.resize(r,c);} { a.resize(r,c); } + + void conservativeResize(auto& a, int s) requires requires{a.conservativeResize(s);} + { + a.conservativeResize(s); + } + + void conservativeResize(auto& a, int r, int c) requires requires{a.conservativeResize(r,c);} + { + a.conservativeResize(r, c); + } + + //----------------------------------------------------------------------------------------------- + // Global operations + //----------------------------------------------------------------------------------------------- + decltype(auto) normalized (auto const& m) requires(requires{ m.normalized(); }) { return m.normalized(); } + decltype(auto) transpose (auto const& m) requires(requires{ m.transpose(); }) { return m.transpose(); } + decltype(auto) conjugate (auto const& m) requires(requires{ m.conjugate(); }) { return m.conjugate(); } + decltype(auto) adjoint (auto const& m) requires(requires{ m.adjoint(); }) { return m.adjoint(); } + + void normalize(auto& a) requires(requires{ a.normalize(); }) { a.normalize(); } + void transposeInPlace(auto& a) requires(requires{ a.transposeInPlace(); }) { a.transposeInPlace(); } + void adjointInPlace(auto& a) requires(requires{ a.adjointInPlace(); }) { a.adjointInPlace(); } + + //----------------------------------------------------------------------------------------------- + // Component-wise functions + //----------------------------------------------------------------------------------------------- + auto abs (auto const& arg) requires(requires{arg.cwiseAbs();} ) { return arg.cwiseAbs(); } + auto abs2(auto const& arg) requires(requires{arg.cwiseAbs2();} ) { return arg.cwiseAbs2(); } + auto rec (auto const& arg) requires(requires{arg.cwiseInverse();}) { return arg.cwiseInverse(); } + auto sqrt(auto const& arg) requires(requires{arg.cwiseSqrt();} ) { return arg.cwiseSqrt(); } + + template + auto min(A const& a, B const& b) + { + if constexpr(!use_expression_templates) return min(generalize_t(a), generalize_t(b)); + else return base_of(a).cwiseMin(base_of(b)); + } + + 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); + } + + 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); + } + + 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)); + } + + 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); + } + + 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); + } + + 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)); + } + + template + auto mul(A const& a, std::convertible_to auto b) + { + return a * b; + } + + template + auto mul(std::convertible_to auto a, B const& b) + { + return a * b; + } + + template + 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(); + } + + template + auto div(A const& a, std::convertible_to auto b) + { + return a / b; + } + + //----------------------------------------------------------------------------------------------- + // Reductions + //----------------------------------------------------------------------------------------------- + auto trace(concepts::entity auto const& arg) { return arg.trace(); } + auto squaredNorm(concepts::entity auto const& arg) { return arg.squaredNorm(); } + auto norm(concepts::entity auto const& arg) { return arg.norm(); } + auto sum(auto const& arg) requires requires{ arg.sum(); } { return arg.sum(); } + auto prod(concepts::entity auto const& arg) { return arg.prod(); } + auto mean(concepts::entity auto const& arg) { return arg.mean(); } + + template + auto dot(A const& a, B const& b) + requires(detail::has_same_vector_size && 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)); + } + + auto maxCoeff(auto const& arg) requires( requires{ arg.maxCoeff(); } ) { return arg.maxCoeff(); } + auto minCoeff(auto const& arg) requires( requires{ arg.minCoeff(); } ) { return arg.minCoeff(); } + + template + auto maxCoeff(concepts::entity auto const& arg, IndexType* row, IndexType* col) + { + return arg.maxCoeff(row, col); + } + + template + auto minCoeff(concepts::entity auto const& arg, IndexType* row, IndexType* col) + { + return arg.minCoeff(row, col); + } + + template + auto lpNorm(T const& arg) requires( requires{arg.template lpNorm