diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..ecfe19d --- /dev/null +++ b/.clang-format @@ -0,0 +1,264 @@ +## ------------------------------------------------------------------------------------------------- +## SPY - C++ Informations Broker +## Copyright: SPY Project Contributors +## SPDX-License-Identifier: BSL-1.0 +## ------------------------------------------------------------------------------------------------- +BasedOnStyle: Microsoft +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseArrows: false + AlignCaseColons: false +AlignConsecutiveTableGenBreakingDAGArgColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenCondOperatorColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveTableGenDefinitionColons: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Always +AllowShortBlocksOnASingleLine: Always +AllowShortCaseExpressionOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: false +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: false + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakAfterReturnType: None +BreakArrays: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: Always +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakFunctionDefinitionParameters: false +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +BreakTemplateDeclarations: MultiLine +ColumnLimit: 80 +CommentPragmas: "" +CompactNamespaces: false +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: + Priority: 1 + CaseSensitive: true + SortPriority: 1 + - Regex: + Priority: 2 + CaseSensitive: true + SortPriority: 2 + - Regex: .* + Priority: 3 + CaseSensitive: true + SortPriority: 3 +IncludeIsMainRegex: "" +IncludeIsMainSourceRegex: "" +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: false +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLines: + AtEndOfFile: false + AtStartOfBlock: true + AtStartOfFile: true +LambdaBodyIndentation: Signature +LineEnding: LF +MacroBlockBegin: "" +MacroBlockEnd: "" +MainIncludeChar: AngleBracket +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: All +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Left +QualifierAlignment: Custom +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: ReturnStatement +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDeclarationName: false + AfterFunctionDefinitionName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + ExceptDoubleParentheses: false + InConditionalStatements: false + InCStyleCasts: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: c++20 +TabWidth: 2 +TableGenBreakInsideDAGArg: DontBreak +UseTab: Never +VerilogBreakBetweenInstancePorts: true +Language: Cpp +QualifierOrder: + - inline + - static + - type + - const \ No newline at end of file diff --git a/include/rotgen/algebra.hpp b/include/rotgen/algebra.hpp index ea74232..fe820be 100644 --- a/include/rotgen/algebra.hpp +++ b/include/rotgen/algebra.hpp @@ -13,4 +13,4 @@ #include #else #include -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/algebra/qr.hpp b/include/rotgen/algebra/qr.hpp index 0c9579f..dfe1eaf 100644 --- a/include/rotgen/algebra/qr.hpp +++ b/include/rotgen/algebra/qr.hpp @@ -10,11 +10,11 @@ namespace rotgen::solver { template - void qr(X& x, M const& m, RHS const& rhs ) + void qr(X& x, M const& m, RHS const& rhs) { - auto r_x = generalize_t(x); - auto r_m = generalize_t(m); + auto r_x = generalize_t(x); + auto r_m = generalize_t(m); auto r_rhs = generalize_t(rhs); r_x = r_m.base().qr_solve(r_rhs.base()); } -} \ No newline at end of file +} diff --git a/include/rotgen/algebra/svd/dynamic.hpp b/include/rotgen/algebra/svd/dynamic.hpp index f2c1551..12d98b5 100644 --- a/include/rotgen/algebra/svd/dynamic.hpp +++ b/include/rotgen/algebra/svd/dynamic.hpp @@ -11,26 +11,34 @@ namespace rotgen { - template - struct svd : find_svd + template struct svd : find_svd { - using parent = find_svd; + using parent = find_svd; - using m_type = matrix; - using d_type = matrix; + using m_type = matrix; + using d_type = matrix; - svd(M const& m, int options = ComputeThinU | ComputeThinV) : parent(m,options) {} + svd(M const& m, int options = ComputeThinU | ComputeThinV) + : parent(m, options) + { + } - int rank() const { return parent::rank(); } + int rank() const { return parent::rank(); } - m_type U() const { return parent::U(); } - m_type D() const { return parent::D(); } - m_type V() const { return parent::V(); } - d_type singular_values() const { return parent::singular_values(); } + m_type U() const { return parent::U(); } - m_type U(int r) const { return parent::U(r); } - m_type D(int r) const { return parent::D(r); } - m_type V(int r) const { return parent::V(r); } - m_type singular_values(int r) const { return parent::singular_values(r); } + m_type D() const { return parent::D(); } + + m_type V() const { return parent::V(); } + + d_type singular_values() const { return parent::singular_values(); } + + m_type U(int r) const { return parent::U(r); } + + m_type D(int r) const { return parent::D(r); } + + m_type V(int r) const { return parent::V(r); } + + m_type singular_values(int r) const { return parent::singular_values(r); } }; -} \ No newline at end of file +} diff --git a/include/rotgen/algebra/svd/dynamic/impl.hpp b/include/rotgen/algebra/svd/dynamic/impl.hpp index 4e5d2af..ffe049c 100644 --- a/include/rotgen/algebra/svd/dynamic/impl.hpp +++ b/include/rotgen/algebra/svd/dynamic/impl.hpp @@ -19,50 +19,64 @@ namespace rotgen class matrix_impl32_row; class matrix_impl32_col; - #define SIZE 64 - #define TYPE double +#define SIZE 64 +#define TYPE double - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include - #undef CLASSNAME - #undef SOURCENAME +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _col) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include +#undef CLASSNAME +#undef SOURCENAME - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include - #undef CLASSNAME - #undef SOURCENAME +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _row) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include +#undef CLASSNAME +#undef SOURCENAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float +#define SIZE 32 +#define TYPE float - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include - #undef CLASSNAME - #undef SOURCENAME +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _col) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include +#undef CLASSNAME +#undef SOURCENAME - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include - #undef CLASSNAME - #undef SOURCENAME +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _row) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include +#undef CLASSNAME +#undef SOURCENAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE + template struct find_svd_impl; - template struct find_svd_impl; + template<> struct find_svd_impl + { + using type = svd_impl32_col; + }; - template<> struct find_svd_impl { using type = svd_impl32_col; }; - template<> struct find_svd_impl { using type = svd_impl32_row; }; - template<> struct find_svd_impl { using type = svd_impl64_col; }; - template<> struct find_svd_impl { using type = svd_impl64_row; }; + template<> struct find_svd_impl + { + using type = svd_impl32_row; + }; - template - using find_svd = typename find_svd_impl::type; -} \ No newline at end of file + template<> struct find_svd_impl + { + using type = svd_impl64_col; + }; + + template<> struct find_svd_impl + { + using type = svd_impl64_row; + }; + + template + using find_svd = typename find_svd_impl::type; +} diff --git a/include/rotgen/algebra/svd/dynamic/model.hpp b/include/rotgen/algebra/svd/dynamic/model.hpp index 83f428f..41d6787 100644 --- a/include/rotgen/algebra/svd/dynamic/model.hpp +++ b/include/rotgen/algebra/svd/dynamic/model.hpp @@ -13,7 +13,7 @@ //================================================================================================== class ROTGEN_EXPORT CLASSNAME { - public: +public: CLASSNAME(SOURCENAME const& m, int options); CLASSNAME(CLASSNAME const& other); CLASSNAME(CLASSNAME&&) noexcept; @@ -23,22 +23,23 @@ class ROTGEN_EXPORT CLASSNAME ~CLASSNAME(); - int rank() const; - SOURCENAME U() const; - SOURCENAME D() const; - SOURCENAME singular_values() const; - SOURCENAME V() const; + int rank() const; + SOURCENAME U() const; + SOURCENAME D() const; + SOURCENAME singular_values() const; + SOURCENAME V() const; - SOURCENAME U(int) const; - SOURCENAME D(int) const; - SOURCENAME singular_values(int) const; - SOURCENAME V(int) const; + SOURCENAME U(int) const; + SOURCENAME D(int) const; + SOURCENAME singular_values(int) const; + SOURCENAME V(int) const; - private: +private: struct payload; std::unique_ptr storage_; - public: - std::unique_ptr& storage() { return storage_; } +public: + std::unique_ptr& storage() { return storage_; } + std::unique_ptr const& storage() const { return storage_; } -}; \ No newline at end of file +}; diff --git a/include/rotgen/algebra/svd/fixed.hpp b/include/rotgen/algebra/svd/fixed.hpp index 86a2448..82b9369 100644 --- a/include/rotgen/algebra/svd/fixed.hpp +++ b/include/rotgen/algebra/svd/fixed.hpp @@ -12,77 +12,84 @@ namespace rotgen { - template - struct svd + template struct svd { - using base = Eigen::JacobiSVD; - using u_type = typename base::MatrixUType; - using v_type = typename base::MatrixVType; - using d_type = typename base::SingularValuesType; + using base = Eigen::JacobiSVD; + using u_type = typename base::MatrixUType; + using v_type = typename base::MatrixVType; + using d_type = typename base::SingularValuesType; - svd(M const& m, int options = ComputeThinU | ComputeThinV) : svd_(m.base(),options) {} + svd(M const& m, int options = ComputeThinU | ComputeThinV) + : svd_(m.base(), options) + { + } - int rank() const { return svd_.rank(); } + int rank() const { return svd_.rank(); } auto singular_values() const { - if constexpr(!use_expression_templates) return detail::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 detail::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 detail::as_concrete_t{svd_.matrixV()}; + if constexpr (!use_expression_templates) + return detail::as_concrete_t{svd_.matrixV()}; else return svd_.matrixV(); } auto D() const { auto d = svd_.singularValues().asDiagonal(); - if constexpr(!use_expression_templates) - return detail::as_concrete_t{d.toDenseMatrix ()}; - else - return d; + if constexpr (!use_expression_templates) + return detail::as_concrete_t{ + d.toDenseMatrix()}; + else return d; } - auto singular_values(int r) const { auto that = svd_.singularValues().head(r); - if constexpr(!use_expression_templates) return detail::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 detail::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 detail::as_concrete_t{that}; + if constexpr (!use_expression_templates) + return detail::as_concrete_t{that}; else return that; } auto D(int r) const { auto d = svd_.singularValues().head(r).asDiagonal(); - if constexpr(!use_expression_templates) - return detail::as_concrete_t{d.toDenseMatrix ()}; - else - return d; + if constexpr (!use_expression_templates) + return detail::as_concrete_t{ + d.toDenseMatrix()}; + else return d; } - private: + private: base svd_; }; -} \ No newline at end of file +} diff --git a/include/rotgen/alias.hpp b/include/rotgen/alias.hpp index 33b2182..297f8d8 100644 --- a/include/rotgen/alias.hpp +++ b/include/rotgen/alias.hpp @@ -8,25 +8,25 @@ namespace rotgen { // matrix aliases (float and double, fixed and dynamic) - using matrix2f = rotgen::matrix; - using matrix3f = rotgen::matrix; - using matrix4f = rotgen::matrix; - using matrix2d = rotgen::matrix; - using matrix3d = rotgen::matrix; - using matrix4d = rotgen::matrix; - using matrixXf = rotgen::matrix; - using matrixXd = rotgen::matrix; - using matrixXi = rotgen::matrix; + using matrix2f = rotgen::matrix; + using matrix3f = rotgen::matrix; + using matrix4f = rotgen::matrix; + using matrix2d = rotgen::matrix; + using matrix3d = rotgen::matrix; + using matrix4d = rotgen::matrix; + using matrixXf = rotgen::matrix; + using matrixXd = rotgen::matrix; + using matrixXi = rotgen::matrix; // Column vector aliases - using vector2f = rotgen::matrix; - using vector3f = rotgen::matrix; - using vector4f = rotgen::matrix; - using vector2d = rotgen::matrix; - using vector3d = rotgen::matrix; - using vector4d = rotgen::matrix; - using vectorXf = rotgen::matrix; - using vectorXd = rotgen::matrix; + using vector2f = rotgen::matrix; + using vector3f = rotgen::matrix; + using vector4f = rotgen::matrix; + using vector2d = rotgen::matrix; + using vector3d = rotgen::matrix; + using vector4d = rotgen::matrix; + using vectorXf = rotgen::matrix; + using vectorXd = rotgen::matrix; // Row vector aliases using row_vector2f = rotgen::matrix; @@ -37,4 +37,4 @@ namespace rotgen using row_vector4d = rotgen::matrix; using row_vectorXf = rotgen::matrix; using row_vectorXd = rotgen::matrix; -} \ No newline at end of file +} diff --git a/include/rotgen/concepts.hpp b/include/rotgen/concepts.hpp index 5f6003c..30449db 100644 --- a/include/rotgen/concepts.hpp +++ b/include/rotgen/concepts.hpp @@ -13,26 +13,27 @@ namespace rotgen::concepts //! @brief Check if a type is a Rotgen reference. //================================================================================================ template - concept reference = requires { typename std::remove_cvref_t::rotgen_ref_tag; }; + concept reference = + requires { typename std::remove_cvref_t::rotgen_ref_tag; }; //================================================================================================ //! @brief Check if a type is a vector. //================================================================================================ template - concept vector = T::IsVectorAtCompileTime; + concept vector = T::IsVectorAtCompileTime; //================================================================================================ //! @brief Check if a type is a 3D vector. //================================================================================================ template - concept vectorND = vector && (T::RowsAtCompileTime == N || T::ColsAtCompileTime == N); + concept vectorND = + vector && (T::RowsAtCompileTime == N || T::ColsAtCompileTime == N); //================================================================================================ //! @brief Check if a type is a ROTGEN type. //================================================================================================ template - concept entity = requires(T const&) - { + concept entity = requires(T const&) { typename std::remove_cvref_t::rotgen_tag; typename std::remove_cvref_t::parent; }; @@ -41,15 +42,18 @@ namespace rotgen::concepts //! @brief Check if a type is an EIGEN type. //================================================================================================ template - concept eigen_compatible = requires(T const& a) - { + concept eigen_compatible = requires(T const& a) { typename std::remove_cvref_t::Scalar; - { std::remove_cvref_t::RowsAtCompileTime } -> std::convertible_to; - { std::remove_cvref_t::ColsAtCompileTime } -> std::convertible_to; - { std::remove_cvref_t::MaxRowsAtCompileTime } -> std::convertible_to; - { std::remove_cvref_t::MaxColsAtCompileTime } -> std::convertible_to; + { std::remove_cvref_t::RowsAtCompileTime } -> std::convertible_to; + { std::remove_cvref_t::ColsAtCompileTime } -> std::convertible_to; + { + std::remove_cvref_t::MaxRowsAtCompileTime + } -> std::convertible_to; + { + std::remove_cvref_t::MaxColsAtCompileTime + } -> std::convertible_to; { a.eval() }; }; -} \ No newline at end of file +} diff --git a/include/rotgen/config.hpp b/include/rotgen/config.hpp index 7ba46f2..19cb475 100644 --- a/include/rotgen/config.hpp +++ b/include/rotgen/config.hpp @@ -16,8 +16,7 @@ namespace rotgen { using Index = std::ptrdiff_t; - inline constexpr std::ptrdiff_t default_alignment = []() - { + inline constexpr std::ptrdiff_t default_alignment = []() { constexpr auto w = spy::simd_instruction_set.width; return w == -1 ? 0 : w / 8; }(); @@ -27,30 +26,31 @@ namespace rotgen inline constexpr int ComputeFullV = 0x10; inline constexpr int ComputeThinV = 0x20; - inline constexpr int Dynamic = -1; - inline constexpr int Infinity = -1; - inline constexpr int AutoAlign = 0; - inline constexpr int ColMajor = 0; - inline constexpr int RowMajor = 1; - inline constexpr int DontAlign = 2; + inline constexpr int Dynamic = -1; + inline constexpr int Infinity = -1; + inline constexpr int AutoAlign = 0; + inline constexpr int ColMajor = 0; + inline constexpr int RowMajor = 1; + inline constexpr int DontAlign = 2; - inline constexpr int Unaligned = 0; - inline constexpr int Aligned8 = 8; - inline constexpr int Aligned16 = 16; - inline constexpr int Aligned32 = 32; - inline constexpr int Aligned64 = 64; + inline constexpr int Unaligned = 0; + inline constexpr int Aligned8 = 8; + inline constexpr int Aligned16 = 16; + inline constexpr int Aligned32 = 32; + inline constexpr int Aligned64 = 64; inline constexpr int Aligned128 = 128; - inline constexpr int Aligned = default_alignment; + inline constexpr int Aligned = default_alignment; - inline constexpr int DontAlignCols = 1; - inline constexpr int StreamPrecision = -1; - inline constexpr int FullPrecision = -2; + inline constexpr int DontAlignCols = 1; + inline constexpr int StreamPrecision = -1; + inline constexpr int FullPrecision = -2; } namespace rotgen::detail { template - inline constexpr int force_order = AutoAlign | ((R==1 && C!=1) ? RowMajor : ColMajor); + inline constexpr int force_order = + AutoAlign | ((R == 1 && C != 1) ? RowMajor : ColMajor); } #if !defined(ROTGEN_MAX_SIZE) && defined(ROTGEN_ENABLE_EXPRESSION_TEMPLATES) @@ -58,15 +58,15 @@ namespace rotgen::detail #endif #if !defined(ROTGEN_FORCE_DYNAMIC) - #if !defined(ROTGEN_MAX_SIZE) - #define ROTGEN_FORCE_DYNAMIC - #endif +#if !defined(ROTGEN_MAX_SIZE) +#define ROTGEN_FORCE_DYNAMIC +#endif #endif #if defined(ROTGEN_FORCE_DYNAMIC) -#define ROTGEN_HAS_STATIC_LIMIT false +#define ROTGEN_HAS_STATIC_LIMIT false #else -#define ROTGEN_HAS_STATIC_LIMIT true +#define ROTGEN_HAS_STATIC_LIMIT true #endif namespace rotgen @@ -77,8 +77,8 @@ namespace rotgen inline constexpr bool use_expression_templates = false; #endif - inline constexpr bool has_static_limit = ROTGEN_HAS_STATIC_LIMIT; - inline constexpr bool is_forcing_dynamic_status = !has_static_limit; + inline constexpr bool has_static_limit = ROTGEN_HAS_STATIC_LIMIT; + inline constexpr bool is_forcing_dynamic_status = !has_static_limit; namespace detail { @@ -91,8 +91,7 @@ namespace rotgen { inline constexpr Index max_static_size = -1; - template - inline constexpr bool storage_status = false; + template inline constexpr bool storage_status = false; } #else namespace rotgen @@ -100,19 +99,18 @@ namespace rotgen inline constexpr Index max_static_size = ROTGEN_MAX_SIZE; template - inline constexpr bool storage_status = - []() - { + inline constexpr bool storage_status = []() { // Actual static size - vector 1xN - if(Rows == 1 && Cols == -1) return true; + if (Rows == 1 && Cols == -1) return true; // Actual static size - vector Nx1 - else if(Rows == -1 && Cols == 1) return true; + else if (Rows == -1 && Cols == 1) return true; // Actual static size - matrix - else if(Rows > 0 && Cols > 0) return (Rows*Cols) <= max_static_size; + else if (Rows > 0 && Cols > 0) return (Rows * Cols) <= max_static_size; // Dynamic size but static Max Size - else if(MaxRows > 0 && MaxCols > 0) return (MaxRows*MaxCols) <= max_static_size; + else if (MaxRows > 0 && MaxCols > 0) + return (MaxRows * MaxCols) <= max_static_size; // Everything dynamic already - else return false; + else return false; }(); } #endif @@ -122,16 +120,17 @@ namespace rotgen inline std::ostream& setup_summary(std::ostream& os) { detail::dynamic_info(os); - os << " * Default alignment: " << default_alignment << " bytes." << std::endl; - if(!is_forcing_dynamic_status) + os << " * Default alignment: " << default_alignment << " bytes." + << std::endl; + if (!is_forcing_dynamic_status) { - if constexpr(use_expression_templates) + if constexpr (use_expression_templates) os << " * Expression templates : Enabled." << std::endl; - else - os << " * Expression templates : Disabled." << std::endl; + else os << " * Expression templates : Disabled." << std::endl; - if constexpr(rotgen::max_static_size) - os << " * Static/Dynamic mode with maximum size: " << rotgen::max_static_size << std::endl; + if constexpr (rotgen::max_static_size) + os << " * Static/Dynamic mode with maximum size: " + << rotgen::max_static_size << std::endl; } return os; diff --git a/include/rotgen/container.hpp b/include/rotgen/container.hpp index 60ff74b..9f9adff 100644 --- a/include/rotgen/container.hpp +++ b/include/rotgen/container.hpp @@ -10,4 +10,4 @@ #include #include #include -#include \ No newline at end of file +#include diff --git a/include/rotgen/container/block.hpp b/include/rotgen/container/block.hpp index 099d35c..95572e5 100644 --- a/include/rotgen/container/block.hpp +++ b/include/rotgen/container/block.hpp @@ -13,4 +13,4 @@ #include #else #include -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/container/block/dynamic.hpp b/include/rotgen/container/block/dynamic.hpp index 13a3439..5289727 100644 --- a/include/rotgen/container/block/dynamic.hpp +++ b/include/rotgen/container/block/dynamic.hpp @@ -18,38 +18,43 @@ namespace rotgen template class ref; - template + template class block : public find_block { - public: - static_assert ( concepts::entity - , "[ROTGEN][CRITICAL] - Block of non-rotgen type instanciated" - ); + public: + static_assert(concepts::entity, + "[ROTGEN][CRITICAL] - Block of non-rotgen type instanciated"); - using parent = find_block; - using rotgen_tag = void; - using rotgen_block_tag = void; - using value_type = typename std::remove_const_t::value_type; + using parent = find_block; + using rotgen_tag = void; + using rotgen_block_tag = void; + using value_type = typename std::remove_const_t::value_type; - static constexpr int storage_order = Ref::storage_order; - static constexpr bool is_immutable = std::is_const_v; - using concrete_type = matrix; - using transposed_type = matrix; - using concrete_dynamic_type = matrix; + static constexpr int storage_order = Ref::storage_order; + static constexpr bool is_immutable = std::is_const_v; + using concrete_type = matrix; + using transposed_type = matrix; + using concrete_dynamic_type = + matrix; - 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; + 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; - static constexpr bool is_defined_static = false; - static constexpr bool has_static_storage = false; + static constexpr bool is_defined_static = false; + static constexpr bool has_static_storage = false; using parent::operator=; - block& operator=(concepts::entity auto const& other) requires(!is_immutable) + + block& operator=(concepts::entity auto const& other) + requires(!is_immutable) { assert(parent::rows() == other.rows() && parent::cols() == other.cols()); for (rotgen::Index r = 0; r < parent::rows(); ++r) @@ -59,117 +64,191 @@ namespace rotgen return *this; } - block(Ref const& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) - requires( !requires{typename Ref::rotgen_block_tag; } && is_immutable) - : parent(r.base(),i0,j0,ni,nj) - {} + block(Ref const& r, + std::size_t i0, + std::size_t j0, + std::size_t ni, + std::size_t nj) + requires(!requires { typename Ref::rotgen_block_tag; } && is_immutable) + : parent(r.base(), i0, j0, ni, nj) + { + } - block(Ref const& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) - requires( requires{typename Ref::rotgen_block_tag; } && is_immutable) - : parent(*r.storage(),i0,j0,ni,nj) - {} + block(Ref const& r, + std::size_t i0, + std::size_t j0, + std::size_t ni, + std::size_t nj) + requires(requires { typename Ref::rotgen_block_tag; } && is_immutable) + : parent(*r.storage(), i0, j0, ni, nj) + { + } block(Ref const& r, std::size_t i0, std::size_t j0) - requires(!requires{typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && is_immutable) - : parent(r.base(),i0,j0,Rows,Cols) - {} + requires(!requires { typename Ref::rotgen_block_tag; } && Rows != -1 && + Cols != -1 && is_immutable) + : parent(r.base(), i0, j0, Rows, Cols) + { + } block(Ref const& r, std::size_t i0, std::size_t j0) - requires(requires{typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && is_immutable) - : parent(*r.storage(),i0,j0,Rows,Cols) - {} + requires(requires { typename Ref::rotgen_block_tag; } && Rows != -1 && + Cols != -1 && is_immutable) + : parent(*r.storage(), i0, j0, Rows, Cols) + { + } - block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) - requires( !requires{typename Ref::rotgen_block_tag; } && !is_immutable) - : parent(r.base(),i0,j0,ni,nj) - {} + block( + Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + requires(!requires { typename Ref::rotgen_block_tag; } && !is_immutable) + : parent(r.base(), i0, j0, ni, nj) + { + } - block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) - requires( requires{typename Ref::rotgen_block_tag; } && !is_immutable) - : parent(*r.storage(),i0,j0,ni,nj) - {} + block( + Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + requires(requires { typename Ref::rotgen_block_tag; } && !is_immutable) + : parent(*r.storage(), i0, j0, ni, nj) + { + } block(Ref& r, std::size_t i0, std::size_t j0) - requires(!requires{typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && !is_immutable) - : parent(r.base(),i0,j0,Rows,Cols) - {} + requires(!requires { typename Ref::rotgen_block_tag; } && Rows != -1 && + Cols != -1 && !is_immutable) + : parent(r.base(), i0, j0, Rows, Cols) + { + } block(Ref& r, std::size_t i0, std::size_t j0) - requires(requires{typename Ref::rotgen_block_tag; } && Rows != -1 && Cols != -1 && !is_immutable) - : parent(*r.storage(),i0,j0,Rows,Cols) - {} + requires(requires { typename Ref::rotgen_block_tag; } && Rows != -1 && + Cols != -1 && !is_immutable) + : parent(*r.storage(), i0, j0, Rows, Cols) + { + } block(parent const& base) : parent(base) {} bool is_contiguous_linear() const { - if(parent::innerStride() != 1) return false; - if constexpr(storage_order) return parent::outerStride() == parent::cols(); - else return parent::outerStride() == parent::rows(); + if (parent::innerStride() != 1) return false; + if constexpr (storage_order) + return parent::outerStride() == parent::cols(); + else return parent::outerStride() == parent::rows(); } - value_type& operator()(Index i, Index j) requires(!is_immutable) { return parent::operator()(i,j); } + value_type& operator()(Index i, Index j) + requires(!is_immutable) + { + return parent::operator()(i, j); + } - value_type& operator()(Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator()(Index i) + requires(!is_immutable && IsVectorAtCompileTime) { assert(is_contiguous_linear()); return parent::operator()(i); } - value_type& operator[](Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return (*this)(i); } - value_type operator()(Index i, Index j) const { return parent::operator()(i,j); } + value_type operator()(Index i, Index j) const + { + return parent::operator()(i, j); + } - value_type operator()(Index i) const requires(IsVectorAtCompileTime) + value_type operator()(Index i) const + requires(IsVectorAtCompileTime) { assert(is_contiguous_linear()); return parent::operator()(i); } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) { return (*this)(i); } - auto evaluate() const { return *this; } - decltype(auto) noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + auto evaluate() const { return *this; } - concrete_type normalized() const requires(IsVectorAtCompileTime) + decltype(auto) noalias() const { return *this; } + + decltype(auto) noalias() { return *this; } + + concrete_type normalized() const + requires(IsVectorAtCompileTime) { return concrete_type(base().normalized()); } - transposed_type transpose() const { return transposed_type(base().transpose());} - concrete_type conjugate() const { return concrete_type(base().conjugate());} - transposed_type adjoint() const { return transposed_type(base().adjoint());} - concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } - concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); } - concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); } - concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); } + transposed_type transpose() const + { + return transposed_type(base().transpose()); + } - void normalize() requires(!is_immutable && IsVectorAtCompileTime) + concrete_type conjugate() const + { + return concrete_type(base().conjugate()); + } + + transposed_type adjoint() const + { + return transposed_type(base().adjoint()); + } + + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + + concrete_type cwiseAbs2() const + { + return concrete_type(base().cwiseAbs2()); + } + + concrete_type cwiseInverse() const + { + return concrete_type(base().cwiseInverse()); + } + + concrete_type cwiseSqrt() const + { + return concrete_type(base().cwiseSqrt()); + } + + void normalize() + requires(!is_immutable && IsVectorAtCompileTime) { parent::normalize(); } - void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } - void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } + + void transposeInPlace() + requires(!is_immutable) + { + parent::transposeInPlace(); + } + + void adjointInPlace() + requires(!is_immutable) + { + parent::adjointInPlace(); + } friend bool operator==(block const& lhs, block const& rhs) { return static_cast(lhs) == static_cast(rhs); } - block& operator+=(block const& rhs) requires(!is_immutable) + block& operator+=(block const& rhs) + requires(!is_immutable) { base() += static_cast(rhs); return *this; } - block& operator-=(block const& rhs) requires(!is_immutable) + block& operator-=(block const& rhs) + requires(!is_immutable) { base() -= static_cast(rhs); return *this; @@ -180,31 +259,35 @@ namespace rotgen return concrete_type(static_cast(*this).operator-()); } - block& operator*=(block const& rhs) requires(!is_immutable) + block& operator*=(block const& rhs) + requires(!is_immutable) { base() *= static_cast(rhs); return *this; } - block& operator*=(value_type rhs) requires(!is_immutable) + block& operator*=(value_type rhs) + requires(!is_immutable) { base() *= rhs; return *this; } - block& operator/=(value_type rhs) requires(!is_immutable) + block& operator/=(value_type rhs) + requires(!is_immutable) { base() /= rhs; return *this; } auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -214,7 +297,7 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::maxCoeff(&r, &c); *row = r; *col = c; @@ -222,109 +305,134 @@ namespace rotgen } static concrete_type Zero() - requires (Rows != -1 && Cols != -1) + requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } static concrete_type Zero(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Zero(rows, cols); } static concrete_type Ones() - requires (Rows != -1 && Cols != -1) + requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } static concrete_type Ones(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Ones(rows, cols); } static concrete_type Constant(value_type value) - requires (Rows != -1 && Cols != -1) + requires(Rows != -1 && Cols != -1) { return parent::Constant(Rows, Cols, static_cast(value)); } static concrete_type Constant(int rows, int cols, value_type value) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Constant(rows, cols, static_cast(value)); } static concrete_type Random() - requires (Rows != -1 && Cols != -1) + requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } static concrete_type Random(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Random(rows, cols); } static concrete_type Identity() - requires (Rows != -1 && Cols != -1) + requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } static concrete_type Identity(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Identity(rows, cols); } - block& setOnes() requires(!is_immutable) + block& setOnes() + requires(!is_immutable) { parent::assign(parent::Ones(parent::rows(), parent::cols())); return *this; } - block& setZero() requires(!is_immutable) + block& setZero() + requires(!is_immutable) { parent::assign(parent::Zero(parent::rows(), parent::cols())); return *this; } - block& setConstant(value_type value) requires(!is_immutable) + block& setConstant(value_type value) + requires(!is_immutable) { parent::assign(parent::Constant(parent::rows(), parent::cols(), value)); return *this; } - block& setRandom() requires(!is_immutable) + block& setRandom() + requires(!is_immutable) { parent::assign(parent::Random(parent::rows(), parent::cols())); return *this; } - block& setIdentity() requires(!is_immutable) + block& setIdentity() + requires(!is_immutable) { parent::assign(parent::Identity(parent::rows(), parent::cols())); return *this; } - template - value_type lpNorm() const + template value_type lpNorm() const { assert(P == 1 || P == 2 || P == Infinity); return parent::lpNorm(P); } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this); } + parent& base() { return static_cast(*this); } + + parent const& base() const { return static_cast(*this); } }; template @@ -368,4 +476,4 @@ namespace rotgen using concrete_type = typename block::concrete_type; return concrete_type(lhs.base().div(rhs)); } -} \ No newline at end of file +} diff --git a/include/rotgen/container/block/dynamic/impl.hpp b/include/rotgen/container/block/dynamic/impl.hpp index 3e0a07e..2212338 100644 --- a/include/rotgen/container/block/dynamic/impl.hpp +++ b/include/rotgen/container/block/dynamic/impl.hpp @@ -21,39 +21,69 @@ namespace rotgen class matrix_impl32_row; class matrix_impl32_col; +#define USE_CONST +#define CONST const +#define BASENAME block_const_impl +#define BASEMAP map_const_impl +#include +#undef BASENAME +#undef BASEMAP +#undef CONST +#undef USE_CONST - #define USE_CONST - #define CONST const - #define BASENAME block_const_impl - #define BASEMAP map_const_impl - #include - #undef BASENAME - #undef BASEMAP - #undef CONST - #undef USE_CONST +#define CONST +#define BASENAME block_impl +#define BASEMAP map_impl +#include +#undef BASENAME +#undef BASEMAP +#undef CONST - #define CONST - #define BASENAME block_impl - #define BASEMAP map_impl - #include - #undef BASENAME - #undef BASEMAP - #undef CONST + template struct find_block_impl; - template struct find_block_impl; + template<> struct find_block_impl + { + using type = block_const_impl32_col; + }; - template<> struct find_block_impl { using type = block_const_impl32_col; }; - template<> struct find_block_impl { using type = block_const_impl32_row; }; - template<> struct find_block_impl { using type = block_const_impl64_col; }; - template<> struct find_block_impl { using type = block_const_impl64_row; }; - template<> struct find_block_impl { using type = block_impl32_col; }; - template<> struct find_block_impl { using type = block_impl32_row; }; - template<> struct find_block_impl { using type = block_impl64_col; }; - template<> struct find_block_impl { using type = block_impl64_row; }; + template<> struct find_block_impl + { + using type = block_const_impl32_row; + }; + + template<> struct find_block_impl + { + using type = block_const_impl64_col; + }; + + template<> struct find_block_impl + { + using type = block_const_impl64_row; + }; + + template<> struct find_block_impl + { + using type = block_impl32_col; + }; + + template<> struct find_block_impl + { + using type = block_impl32_row; + }; + + template<> struct find_block_impl + { + using type = block_impl64_col; + }; + + template<> struct find_block_impl + { + using type = block_impl64_row; + }; template - using find_block = typename find_block_impl < typename std::remove_const_t::value_type - , Ref::storage_order - , std::is_const_v - >::type; + using find_block = + typename find_block_impl::value_type, + Ref::storage_order, + std::is_const_v>::type; } diff --git a/include/rotgen/container/block/dynamic/indirect.hpp b/include/rotgen/container/block/dynamic/indirect.hpp index d0dffa7..fc99030 100644 --- a/include/rotgen/container/block/dynamic/indirect.hpp +++ b/include/rotgen/container/block/dynamic/indirect.hpp @@ -1,51 +1,51 @@ - #define SIZE 64 - #define TYPE double +#define SIZE 64 +#define TYPE double - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #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 - #undef CLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef MAPNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 +#undef CLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef MAPNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #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 - #undef CLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef MAPNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 +#undef CLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef MAPNAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float +#define SIZE 32 +#define TYPE float - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #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 - #undef CLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef MAPNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 +#undef CLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef MAPNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #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 - #undef CLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef MAPNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 +#undef CLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef MAPNAME - #undef SIZE - #undef TYPE \ No newline at end of file +#undef SIZE +#undef TYPE diff --git a/include/rotgen/container/block/dynamic/model.hpp b/include/rotgen/container/block/dynamic/model.hpp index d236c76..8e6727e 100644 --- a/include/rotgen/container/block/dynamic/model.hpp +++ b/include/rotgen/container/block/dynamic/model.hpp @@ -13,28 +13,28 @@ //================================================================================================== class ROTGEN_EXPORT CLASSNAME { - private: +private: struct payload; std::unique_ptr storage_; - public: - CLASSNAME(SOURCENAME CONST& r , Index i0, Index j0, Index ni, Index nj); - CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj); +public: + CLASSNAME(SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj); + CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(payload const& r, Index i0, Index j0, Index ni, Index nj); CLASSNAME(CLASSNAME const& other); CLASSNAME(CLASSNAME&&) noexcept; - #if !defined(USE_CONST) +#if !defined(USE_CONST) CLASSNAME& operator=(CLASSNAME const& other); CLASSNAME& operator=(CLASSNAME&&) noexcept; - #endif +#endif ~CLASSNAME(); - #if !defined(USE_CONST) +#if !defined(USE_CONST) void assign(SOURCENAME const&); - #endif +#endif Index rows() const; Index cols() const; @@ -46,44 +46,44 @@ class ROTGEN_EXPORT CLASSNAME 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 cwiseAbs() const; + SOURCENAME cwiseAbs2() const; SOURCENAME cwiseInverse() const; - SOURCENAME cwiseSqrt() const; + SOURCENAME cwiseSqrt() const; - #if !defined(USE_CONST) +#if !defined(USE_CONST) void normalize(); void transposeInPlace(); void adjointInPlace(); - #endif +#endif - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() 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); +#if !defined(USE_CONST) + TYPE& operator()(Index i, Index j); + TYPE& operator()(Index index); CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs); - CLASSNAME& operator*=(TYPE d); - CLASSNAME& operator/=(TYPE d); - #endif + CLASSNAME& operator*=(TYPE d); + CLASSNAME& operator/=(TYPE d); +#endif TYPE operator()(Index i, Index j) const; TYPE operator()(Index index) const; @@ -95,26 +95,43 @@ class ROTGEN_EXPORT CLASSNAME SOURCENAME mul(TYPE s) const; SOURCENAME div(TYPE s) const; - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,CLASSNAME const&); - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, format const&); - friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + CLASSNAME const&); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + format const&); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, + CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, + CLASSNAME const& rhs); - #if !defined(USE_CONST) - TYPE* data(); - #endif +#if !defined(USE_CONST) + TYPE* data(); +#endif const TYPE* data() const; - 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 Constant(Index r, Index c, TYPE v) { return SOURCENAME::Constant(r,c,v); } - static SOURCENAME Random(Index r, Index c) { return SOURCENAME::Random(r,c); } - static SOURCENAME Identity(Index r, Index c) { return SOURCENAME::Identity(r,c); } + static SOURCENAME Zero(Index r, Index c) { return SOURCENAME::Zero(r, c); } - public: - #if !defined(USE_CONST) - std::unique_ptr& storage() { return storage_; } - #endif + static SOURCENAME Ones(Index r, Index c) { return SOURCENAME::Ones(r, c); } + + static SOURCENAME Constant(Index r, Index c, TYPE v) + { + return SOURCENAME::Constant(r, c, v); + } + + static SOURCENAME Random(Index r, Index c) + { + return SOURCENAME::Random(r, c); + } + + static SOURCENAME Identity(Index r, Index c) + { + return SOURCENAME::Identity(r, c); + } + +public: +#if !defined(USE_CONST) + std::unique_ptr& storage() { return storage_; } +#endif std::unique_ptr const& storage() const { return storage_; } -}; \ No newline at end of file +}; diff --git a/include/rotgen/container/block/fixed.hpp b/include/rotgen/container/block/fixed.hpp index 710ce31..70599c5 100644 --- a/include/rotgen/container/block/fixed.hpp +++ b/include/rotgen/container/block/fixed.hpp @@ -21,99 +21,136 @@ namespace rotgen template struct compute_block_type { - using ref_t = std::conditional_t; + using ref_t = std::conditional_t; - using type = std::conditional_t < storage_status - , Eigen::Block - , Eigen::Block - >; + using type = std::conditional_t< + storage_status, + Eigen::Block, + Eigen::Block>; }; - template - struct compute_block_type,Rows,Cols,Inner,IsConst> - : compute_block_type::parent,Rows,Cols,Inner,IsConst> + template + struct compute_block_type, Rows, Cols, Inner, IsConst> + : compute_block_type::parent, + Rows, + Cols, + Inner, + IsConst> { }; template - using block_type = typename compute_block_type::type; + using block_type = + typename compute_block_type::type; } - template< typename Ref - , int Rows = Dynamic, int Cols = Dynamic - , bool Inner = false , int ForceStorageOrder = -1 - > - class block : private detail::block_type, Rows, Cols, Inner,std::is_const_v > + template + class block : private detail::block_type, + Rows, + Cols, + Inner, + std::is_const_v> { - static_assert ( concepts::entity - , "[ROTGEN][CRITICAL] - Block of non-rotgen type instanciated" - ); + static_assert(concepts::entity, + "[ROTGEN][CRITICAL] - Block of non-rotgen type instanciated"); - public: - using rotgen_tag = void; - using rotgen_block_tag = void; - using parent = detail::block_type, Rows, Cols, Inner,std::is_const_v>; - using value_type = typename parent::value_type; - using Index = typename parent::Index; + public: + using rotgen_tag = void; + using rotgen_block_tag = void; + using parent = detail::block_type, + Rows, + Cols, + Inner, + std::is_const_v>; + using value_type = typename parent::value_type; + using Index = typename parent::Index; - static constexpr int storage_order = (ForceStorageOrder == -1) ? Ref::storage_order : ForceStorageOrder; - static constexpr bool is_immutable = std::is_const_v; + static constexpr int storage_order = + (ForceStorageOrder == -1) ? Ref::storage_order : ForceStorageOrder; + static constexpr bool is_immutable = std::is_const_v; - static constexpr bool IsRowMajor = parent::IsRowMajor; + static constexpr bool IsRowMajor = parent::IsRowMajor; - using concrete_type = matrix; - using concrete_dynamic_type = matrix; + using concrete_type = matrix; + using concrete_dynamic_type = + matrix; template 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; + 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; - public: - block(const block& other) = default; - block(block&& other) = default; - block& operator=(const block&) = default; - block& operator=(block&&) = default; + public: + block(block const& other) = default; + block(block&& other) = default; + block& operator=(block const&) = default; + block& operator=(block&&) = default; - block(Ref const& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + block(Ref const& r, + std::size_t i0, + std::size_t j0, + std::size_t ni, + std::size_t nj) requires(is_immutable) - : parent(r.base(),i0,j0,ni,nj) - {} + : parent(r.base(), i0, j0, ni, nj) + { + } block(Ref const& r, std::size_t i0, std::size_t j0) requires(Rows != -1 && Cols != -1 && is_immutable) - : parent(r.base(),i0,j0,Rows,Cols) - {} + : parent(r.base(), i0, j0, Rows, Cols) + { + } - block(Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) + block( + Ref& r, std::size_t i0, std::size_t j0, std::size_t ni, std::size_t nj) requires(!is_immutable) - : parent(r.base(),i0,j0,ni,nj) - {} + : parent(r.base(), i0, j0, ni, nj) + { + } block(Ref& r, std::size_t i0, std::size_t j0) requires(Rows != -1 && Cols != -1 && !is_immutable) - : parent(r.base(),i0,j0,Rows,Cols) - {} + : parent(r.base(), i0, j0, Rows, Cols) + { + } template - block(block const& other) : parent(other.base()) - {} + block(block const& other) : parent(other.base()) + { + } template - block(const Eigen::MatrixBase& other) : parent(other) {} + block(Eigen::MatrixBase const& other) : parent(other) + { + } template - block(const Eigen::EigenBase& other) : parent(other) {} + block(Eigen::EigenBase const& other) : parent(other) + { + } - block(concepts::entity auto const& other) : parent(other.base()) - {} + block(concepts::entity auto const& other) : parent(other.base()) {} block& operator=(concepts::entity auto const& other) { @@ -122,21 +159,22 @@ namespace rotgen } template - block& operator=(const Eigen::MatrixBase& other) + block& operator=(Eigen::MatrixBase const& other) { parent::operator=(other); return *this; } template - block& operator=(const Eigen::EigenBase& other) + block& operator=(Eigen::EigenBase const& other) { parent::operator=(other); return *this; } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this); } + parent& base() { return static_cast(*this); } + + parent const& base() const { return static_cast(*this); } auto evaluate() const { @@ -146,239 +184,308 @@ namespace rotgen decltype(auto) noalias() const { - if constexpr(use_expression_templates) return base().noalias(); - else return *this; + if constexpr (use_expression_templates) return base().noalias(); + else return *this; } decltype(auto) noalias() { - 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 requires(IsVectorAtCompileTime) + auto normalized() const + requires(IsVectorAtCompileTime) { - if constexpr(use_expression_templates) return base().normalized(); - else return as_concrete_type(base().normalized()); + if constexpr (use_expression_templates) return base().normalized(); + else + return as_concrete_type( + base().normalized()); } auto transpose() const { - if constexpr(use_expression_templates) return base().transpose(); - else return as_concrete_type(base().transpose()); + if constexpr (use_expression_templates) return base().transpose(); + else + return as_concrete_type( + base().transpose()); } auto adjoint() const { - if constexpr(use_expression_templates) return base().adjoint(); - else return as_concrete_type(base().adjoint()); + if constexpr (use_expression_templates) return base().adjoint(); + else + return as_concrete_type(base().adjoint()); } auto conjugate() const { - if constexpr(use_expression_templates) return base().conjugate(); - else return as_concrete_type(base().conjugate()); + if constexpr (use_expression_templates) return base().conjugate(); + else + return as_concrete_type( + base().conjugate()); } - void normalize() requires(!is_immutable && IsVectorAtCompileTime) + void normalize() + requires(!is_immutable && IsVectorAtCompileTime) { parent::normalize(); } - void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } - void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } + void transposeInPlace() + requires(!is_immutable) + { + parent::transposeInPlace(); + } + + void adjointInPlace() + requires(!is_immutable) + { + parent::adjointInPlace(); + } auto cwiseAbs() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()}; - else return base().cwiseAbs(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseAbs()}; + else return base().cwiseAbs(); } auto cwiseAbs2() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; - else return base().cwiseAbs2(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); } auto cwiseInverse() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()}; - else return base().cwiseInverse(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseInverse()}; + else return base().cwiseInverse(); } auto cwiseSqrt() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; - else return base().cwiseSqrt(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); } - static concrete_type Constant(value_type value) requires (Rows != -1 && Cols != -1) + 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) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Constant(rows, cols, static_cast(value)); } - static concrete_type Identity() requires (Rows != -1 && Cols != -1) + static concrete_type Identity() + requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } static concrete_type Identity(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Identity(rows, cols); } - static concrete_type Zero() requires (Rows != -1 && Cols != -1) + static concrete_type Zero() + requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } static concrete_type Zero(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Zero(rows, cols); } - static concrete_type Ones() requires (Rows != -1 && Cols != -1) + static concrete_type Ones() + requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } static concrete_type Ones(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Ones(rows, cols); } - static concrete_type Random() requires (Rows != -1 && Cols != -1) + static concrete_type Random() + requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } static concrete_type Random(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Random(rows, cols); } - block& setOnes() requires(!is_immutable) + block& setOnes() + requires(!is_immutable) { *this = parent::Ones(rows(), cols()); return *this; } - block& setOnes(int r, int c) requires(!is_immutable) + block& setOnes(int r, int c) + requires(!is_immutable) { *this = parent::Ones(r, c); return *this; } - block& setZero() requires(!is_immutable) + block& setZero() + requires(!is_immutable) { *this = parent::Zero(rows(), cols()); return *this; } - block& setZero(int r, int c) requires(!is_immutable) + block& setZero(int r, int c) + requires(!is_immutable) { - *this = parent::Zero(r,c); + *this = parent::Zero(r, c); return *this; } - block& setConstant(value_type value) requires(!is_immutable) + block& setConstant(value_type value) + requires(!is_immutable) { *this = parent::Constant(rows(), cols(), value); return *this; } - block& setConstant(int r, int c, value_type value) requires(!is_immutable) + block& setConstant(int r, int c, value_type value) + requires(!is_immutable) { - *this = parent::Constant(r,c, value); + *this = parent::Constant(r, c, value); return *this; } - block& setRandom() requires(!is_immutable) + block& setRandom() + requires(!is_immutable) { - *this = parent::Random(rows(),cols()); + *this = parent::Random(rows(), cols()); return *this; } - block& setRandom(int r, int c) requires(!is_immutable) + block& setRandom(int r, int c) + requires(!is_immutable) { - *this = parent::Random(r,c); + *this = parent::Random(r, c); return *this; } - block& setIdentity() requires(!is_immutable) + block& setIdentity() + requires(!is_immutable) { - *this = parent::Identity(rows(),cols()); + *this = parent::Identity(rows(), cols()); return *this; } - block& setIdentity(int r, int c) requires(!is_immutable) + block& setIdentity(int r, int c) + requires(!is_immutable) { - *this = parent::Identity(r,c); + *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

(); } - value_type& operator()(Index i, Index j) requires(!is_immutable) + value_type& operator()(Index i, Index j) + requires(!is_immutable) { - return base()(i,j); + return base()(i, j); } - value_type& operator()(Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator()(Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return base().data()[i]; } - value_type& operator[](Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return (*this)(i); } - value_type operator()(Index i, Index j) const { return base()(i,j); } - value_type operator()(Index i) const requires(IsVectorAtCompileTime) { return base().data()[i]; } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) { return (*this)(i); } + value_type operator()(Index i, Index j) const { return base()(i, j); } + + value_type operator()(Index i) const + requires(IsVectorAtCompileTime) + { + return base().data()[i]; + } + + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) + { + return (*this)(i); + } - using parent::innerStride; - using parent::outerStride; - using parent::rows; using parent::cols; - using parent::size; - using parent::prod; - using parent::mean; - using parent::trace; - using parent::squaredNorm; - using parent::norm; - using parent::sum; using parent::data; - + using parent::innerStride; + using parent::mean; + using parent::norm; + using parent::outerStride; + using parent::prod; + using parent::rows; + using parent::size; + using parent::squaredNorm; + using parent::sum; + using parent::trace; auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -388,7 +495,7 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::maxCoeff(&r, &c); *row = r; *col = c; @@ -396,15 +503,18 @@ namespace rotgen } Index startRow() const { return base().startRow(); } + Index startCol() const { return base().startCol(); } - block& operator+=(block const& rhs) requires(!is_immutable) + block& operator+=(block const& rhs) + requires(!is_immutable) { static_cast(*this) += static_cast(rhs); return *this; } - block& operator-=(block const& rhs) requires(!is_immutable) + block& operator-=(block const& rhs) + requires(!is_immutable) { static_cast(*this) -= static_cast(rhs); return *this; @@ -415,22 +525,25 @@ namespace rotgen return concrete_type(static_cast(*this).operator-()); } - block& operator*=(block const& rhs) requires(!is_immutable) + block& operator*=(block const& rhs) + requires(!is_immutable) { static_cast(*this) *= static_cast(rhs); return *this; } - block& operator*=(value_type rhs) requires(!is_immutable) + block& operator*=(value_type rhs) + requires(!is_immutable) { static_cast(*this) *= rhs; return *this; } - block& operator/=(value_type rhs) requires(!is_immutable) + block& operator/=(value_type rhs) + requires(!is_immutable) { static_cast(*this) /= rhs; return *this; } }; -} \ No newline at end of file +} diff --git a/include/rotgen/container/map.hpp b/include/rotgen/container/map.hpp index 52b3e32..676dd14 100644 --- a/include/rotgen/container/map.hpp +++ b/include/rotgen/container/map.hpp @@ -13,4 +13,4 @@ #include #else #include -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/container/map/dynamic.hpp b/include/rotgen/container/map/dynamic.hpp index e18de45..dcec9c4 100644 --- a/include/rotgen/container/map/dynamic.hpp +++ b/include/rotgen/container/map/dynamic.hpp @@ -14,88 +14,106 @@ namespace rotgen { - template + template class map : public find_map { - public: + public: + static_assert(concepts::entity, + "[ROTGEN][CRITICAL] - Map of non-rotgen type instanciated"); - static_assert ( concepts::entity - , "[ROTGEN][CRITICAL] - Map of non-rotgen type instanciated" - ); + using parent = find_map; + using rotgen_tag = void; + using value_type = typename std::remove_const_t::value_type; + using concrete_type = typename std::remove_const_t::concrete_type; - using parent = find_map; - using rotgen_tag = void; - using value_type = typename std::remove_const_t::value_type; - using concrete_type = typename std::remove_const_t::concrete_type; - - static constexpr bool IsRowMajor = Ref::IsRowMajor; - static constexpr int storage_order = Ref::storage_order; - static constexpr bool has_static_storage = false; + static constexpr bool IsRowMajor = Ref::IsRowMajor; + static constexpr int storage_order = Ref::storage_order; + static constexpr bool has_static_storage = false; static constexpr bool is_immutable = std::is_const_v; static constexpr bool is_defined_static = false; - using ptr_type = std::conditional_t; + using ptr_type = + std::conditional_t; using stride_type = Stride; - 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 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; + static constexpr bool IsCompileTimeSized = + RowsAtCompileTime != -1 && ColsAtCompileTime != -1; - using transposed_type = matrix; + using transposed_type = + matrix; - map(ptr_type ptr, Index r, Index c, stride_type s) : parent(ptr, r, c, strides(s,r,c)) + map(ptr_type ptr, Index r, Index c, stride_type s) + : parent(ptr, r, c, strides(s, r, c)) { - if constexpr(RowsAtCompileTime != -1) - assert(r == RowsAtCompileTime && "Mismatched between dynamic and static row size"); + if constexpr (RowsAtCompileTime != -1) + assert(r == RowsAtCompileTime && + "Mismatched between dynamic and static row size"); - if constexpr(ColsAtCompileTime != -1) - assert(c == ColsAtCompileTime && "Mismatched between dynamic and static column size"); + if constexpr (ColsAtCompileTime != -1) + assert(c == ColsAtCompileTime && + "Mismatched between dynamic and static column size"); } 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); - }() - ) - {} + : parent(ptr, r, c, [&]() { + if constexpr (!std::same_as) + return strides(Stride{}, r, c); + else return strides(r, c); + }()) + { + } - map(ptr_type ptr, stride_type s) requires(IsCompileTimeSized) - : parent(ptr,RowsAtCompileTime,ColsAtCompileTime, strides(s)) - {} + map(ptr_type ptr, stride_type s) + requires(IsCompileTimeSized) + : parent( + ptr, RowsAtCompileTime, ColsAtCompileTime, strides(s)) + { + } - map(ptr_type ptr, Index size) requires(RowsAtCompileTime==1 || ColsAtCompileTime==1) - : map( ptr, RowsAtCompileTime==1?1:size, ColsAtCompileTime==1?1:size) - {} + map(ptr_type ptr, Index size) + requires(RowsAtCompileTime == 1 || ColsAtCompileTime == 1) + : map(ptr, + RowsAtCompileTime == 1 ? 1 : size, + ColsAtCompileTime == 1 ? 1 : size) + { + } - map(ptr_type ptr) requires(IsCompileTimeSized) - : map( ptr, RowsAtCompileTime, ColsAtCompileTime ) - {} + map(ptr_type ptr) + requires(IsCompileTimeSized) + : map(ptr, RowsAtCompileTime, ColsAtCompileTime) + { + } template - map(map const& other) : map ( other.data(), other.rows(), other.cols() - , stride{other.outerStride(),other.innerStride()} - ) - {} + map(map const& other) + : map(other.data(), + other.rows(), + other.cols(), + stride{other.outerStride(), other.innerStride()}) + { + } map(parent const& base) : parent(base) {} - map(map const& other) : parent(other) - {} + map(map const& other) : parent(other) {} - map& operator=(map const& other) requires(!is_immutable) + map& operator=(map const& other) + requires(!is_immutable) { - base() = static_cast(other); + base() = static_cast(other); return *this; } - map& operator=(concepts::entity auto const& other) requires(!is_immutable) + map& operator=(concepts::entity auto const& other) + requires(!is_immutable) { assert(parent::rows() == other.rows() && parent::cols() == other.cols()); for (rotgen::Index r = 0; r < parent::rows(); ++r) @@ -105,94 +123,170 @@ namespace rotgen return *this; } - value_type& operator()(Index i, Index j) requires(!is_immutable) { return parent::operator()(i,j); } - value_type& operator()(Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator()(Index i, Index j) + requires(!is_immutable) { - assert( parent::innerStride() == 1 - && parent::outerStride() ==(storage_order == RowMajor ? parent::cols() : parent::rows()) - ); + return parent::operator()(i, j); + } + + value_type& operator()(Index i) + requires(!is_immutable && IsVectorAtCompileTime) + { + assert(parent::innerStride() == 1 && + parent::outerStride() == + (storage_order == RowMajor ? parent::cols() : parent::rows())); return parent::operator()(i); } - value_type& operator[](Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return (*this)(i); } - value_type operator()(Index i, Index j) const { return parent::operator()(i,j); } - value_type operator()(Index i) const requires(IsVectorAtCompileTime) + value_type operator()(Index i, Index j) const { - assert( parent::innerStride() == 1 - && parent::outerStride() ==(storage_order == RowMajor ? parent::cols() : parent::rows()) - ); + return parent::operator()(i, j); + } + + value_type operator()(Index i) const + requires(IsVectorAtCompileTime) + { + assert(parent::innerStride() == 1 && + parent::outerStride() == + (storage_order == RowMajor ? parent::cols() : parent::rows())); return parent::operator()(i); } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) { return (*this)(i); } - auto evaluate() const { return *this; } - decltype(auto) noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + auto evaluate() const { return *this; } - concrete_type normalized() const requires(IsVectorAtCompileTime) + decltype(auto) noalias() const { return *this; } + + decltype(auto) noalias() { return *this; } + + concrete_type normalized() const + requires(IsVectorAtCompileTime) { return concrete_type(base().normalized()); } - transposed_type transpose() const { return transposed_type(base().transpose()); } - concrete_type conjugate() const { return concrete_type(base().conjugate()); } - transposed_type adjoint() const { return transposed_type(base().adjoint()); } + transposed_type transpose() const + { + return transposed_type(base().transpose()); + } - concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } - concrete_type cwiseAbs2() const { return concrete_type(base().cwiseAbs2()); } - concrete_type cwiseInverse() const { return concrete_type(base().cwiseInverse()); } - concrete_type cwiseSqrt() const { return concrete_type(base().cwiseSqrt()); } - concrete_type cwiseMin(map const& rhs) const { return concrete_type(base().cwiseMin(rhs.base())); } - concrete_type cwiseMax(map const& rhs) const { return concrete_type(base().cwiseMax(rhs.base())); } - concrete_type cwiseQuotient(map const& rhs) const { return concrete_type(base().cwiseQuotient(rhs.base())); } - concrete_type cwiseProduct(map const& rhs) const { return concrete_type(base().cwiseProduct(rhs.base())); } - concrete_type cwiseMin(value_type s) const { return concrete_type(base().cwiseMin(s)); } - concrete_type cwiseMax(value_type s) const { return concrete_type(base().cwiseMax(s)); } + concrete_type conjugate() const + { + return concrete_type(base().conjugate()); + } + + transposed_type adjoint() const + { + return transposed_type(base().adjoint()); + } + + concrete_type cwiseAbs() const { return concrete_type(base().cwiseAbs()); } + + concrete_type cwiseAbs2() const + { + return concrete_type(base().cwiseAbs2()); + } + + concrete_type cwiseInverse() const + { + return concrete_type(base().cwiseInverse()); + } + + concrete_type cwiseSqrt() const + { + return concrete_type(base().cwiseSqrt()); + } + + concrete_type cwiseMin(map const& rhs) const + { + return concrete_type(base().cwiseMin(rhs.base())); + } + + concrete_type cwiseMax(map const& rhs) const + { + return concrete_type(base().cwiseMax(rhs.base())); + } + + concrete_type cwiseQuotient(map const& rhs) const + { + return concrete_type(base().cwiseQuotient(rhs.base())); + } + + concrete_type cwiseProduct(map const& rhs) const + { + return concrete_type(base().cwiseProduct(rhs.base())); + } + + concrete_type cwiseMin(value_type s) const + { + return concrete_type(base().cwiseMin(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 cross(map const& other) const + concrete_type cross(map const& other) const { concrete_type that; - if constexpr(RowsAtCompileTime==-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); - that(2,0) = (*this)(0,0) * other(1,0) - (*this)(1,0) * other(0,0); + 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); + that(2, 0) = (*this)(0, 0) * other(1, 0) - (*this)(1, 0) * other(0, 0); } else { - that(0,0) = (*this)(0,1) * other(0,2) - (*this)(0,2) * other(0,1); - that(0,1) = (*this)(0,2) * other(0,0) - (*this)(0,0) * other(0,2); - that(0,2) = (*this)(0,0) * other(0,1) - (*this)(0,1) * other(0,0); + that(0, 0) = (*this)(0, 1) * other(0, 2) - (*this)(0, 2) * other(0, 1); + that(0, 1) = (*this)(0, 2) * other(0, 0) - (*this)(0, 0) * other(0, 2); + that(0, 2) = (*this)(0, 0) * other(0, 1) - (*this)(0, 1) * other(0, 0); } return that; } - void normalize() requires(!is_immutable && IsVectorAtCompileTime) + void normalize() + requires(!is_immutable && IsVectorAtCompileTime) { parent::normalize(); } - void transposeInPlace() requires(!is_immutable) { parent::transposeInPlace(); } - void adjointInPlace() requires(!is_immutable) { parent::adjointInPlace(); } + + void transposeInPlace() + requires(!is_immutable) + { + parent::transposeInPlace(); + } + + void adjointInPlace() + requires(!is_immutable) + { + parent::adjointInPlace(); + } template - map& operator+=(map const& rhs) requires(!is_immutable) + map& operator+=(map const& rhs) + requires(!is_immutable) { base() += rhs.base(); return *this; } template - map& operator-=(map const& rhs) requires(!is_immutable) + map& operator-=(map const& rhs) + requires(!is_immutable) { base() -= rhs.base(); return *this; @@ -204,31 +298,35 @@ namespace rotgen } template - map& operator*=(map const& rhs) requires(!is_immutable) + map& operator*=(map const& rhs) + requires(!is_immutable) { base() *= rhs.base(); return *this; } - map& operator*=(value_type rhs) requires(!is_immutable) + map& operator*=(value_type rhs) + requires(!is_immutable) { base() *= rhs; return *this; } - map& operator/=(value_type rhs) requires(!is_immutable) + map& operator/=(value_type rhs) + requires(!is_immutable) { base() /= rhs; return *this; } auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -238,24 +336,23 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index 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(); } - 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 Constant(value_type value) requires( requires {Ref::Constant(value);} ) + static auto Constant(value_type value) + requires(requires { Ref::Constant(value); }) { return Ref::Constant(value); } @@ -265,17 +362,16 @@ namespace rotgen return Ref::Constant(rows, cols, value); } - static auto Random() requires( requires {Ref::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() requires( requires {Ref::Identity();} ) + static auto Identity() + requires(requires { Ref::Identity(); }) { return Ref::Identity(); } @@ -285,51 +381,56 @@ namespace rotgen return Ref::Identity(rows, cols); } - map& setZero() requires(!is_immutable) + map& setZero() + requires(!is_immutable) { parent::setZero(); return *this; } - map& setOnes() requires(!is_immutable) + map& setOnes() + requires(!is_immutable) { parent::setOnes(); return *this; } - map& setIdentity() requires(!is_immutable) + map& setIdentity() + requires(!is_immutable) { parent::setIdentity(); return *this; } - map& setRandom() requires(!is_immutable) + map& setRandom() + requires(!is_immutable) { parent::setRandom(); return *this; } - map& setConstant(value_type s) requires(!is_immutable) + map& setConstant(value_type s) + requires(!is_immutable) { 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()); } - template - value_type lpNorm() const + template value_type lpNorm() const { assert(P == 1 || P == 2 || P == Infinity); return parent::lpNorm(P); } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this); } + parent& base() { return static_cast(*this); } + + parent const& base() const { return static_cast(*this); } concrete_type qr_solve(map const& rhs) const { @@ -338,69 +439,73 @@ namespace rotgen }; template - detail::composite_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_type; + 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))); } template - detail::composite_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_type; + 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))); } template - matrix - 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< typename R1::value_type - , R1::RowsAtCompileTime,R2::ColsAtCompileTime - , R1::storage_order - >; + using map1_type = map; + using map2_type = map; + using concrete_type = matrix; return concrete_type(map1_type(lhs).base().mul(map2_type(rhs).base())); } template - typename map::concrete_type - operator*(map const& lhs, std::convertible_to auto s) + typename map::concrete_type operator*( + map const& lhs, std::convertible_to auto s) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base().mul(s)); } template - typename map::concrete_type - operator*(std::convertible_to auto s, map const& rhs) + typename map::concrete_type operator*( + std::convertible_to auto s, map const& rhs) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(rhs.base().mul(s)); } template - typename map::concrete_type - operator/(map const& lhs, std::convertible_to auto s) + typename map::concrete_type operator/( + map const& lhs, std::convertible_to auto s) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base().div(s)); } template - bool operator==(map const& lhs, map const& rhs) + bool operator==(map const& lhs, map const& rhs) { return lhs.base() == rhs.base(); } + template - bool operator!=(map const& lhs, map const& rhs) + bool operator!=(map const& lhs, map const& rhs) { return lhs.base() != rhs.base(); } -} \ No newline at end of file +} diff --git a/include/rotgen/container/map/dynamic/impl.hpp b/include/rotgen/container/map/dynamic/impl.hpp index 9b770c7..bdfe8fe 100644 --- a/include/rotgen/container/map/dynamic/impl.hpp +++ b/include/rotgen/container/map/dynamic/impl.hpp @@ -25,36 +25,67 @@ namespace rotgen class map_impl32_col; class map_const_impl32_col; - #define USE_CONST - #define CONST const - #define BASENAME map_const_impl - #include - #undef BASENAME - #undef CONST - #undef USE_CONST +#define USE_CONST +#define CONST const +#define BASENAME map_const_impl +#include +#undef BASENAME +#undef CONST +#undef USE_CONST - #define CONST - #define BASENAME map_impl - #include - #undef BASENAME - #undef CONST +#define CONST +#define BASENAME map_impl +#include +#undef BASENAME +#undef CONST - template struct find_map_impl; + template struct find_map_impl; - template<> struct find_map_impl { using type = map_const_impl32_col; }; - template<> struct find_map_impl { using type = map_const_impl32_row; }; - template<> struct find_map_impl { using type = map_const_impl64_col; }; - template<> struct find_map_impl { using type = map_const_impl64_row; }; - template<> struct find_map_impl { using type = map_impl32_col; }; - template<> struct find_map_impl { using type = map_impl32_row; }; - template<> struct find_map_impl { using type = map_impl64_col; }; - template<> struct find_map_impl { using type = map_impl64_row; }; + template<> struct find_map_impl + { + using type = map_const_impl32_col; + }; + + template<> struct find_map_impl + { + using type = map_const_impl32_row; + }; + + template<> struct find_map_impl + { + using type = map_const_impl64_col; + }; + + template<> struct find_map_impl + { + using type = map_const_impl64_row; + }; + + template<> struct find_map_impl + { + using type = map_impl32_col; + }; + + template<> struct find_map_impl + { + using type = map_impl32_row; + }; + + template<> struct find_map_impl + { + using type = map_impl64_col; + }; + + template<> struct find_map_impl + { + using type = map_impl64_row; + }; template - using find_map = typename find_map_impl < typename std::remove_const_t::value_type - , Ref::storage_order - , std::is_const_v - >::type; + using find_map = + typename find_map_impl::value_type, + Ref::storage_order, + std::is_const_v>::type; } #include diff --git a/include/rotgen/container/map/dynamic/indirect.hpp b/include/rotgen/container/map/dynamic/indirect.hpp index f01ac94..90e0c50 100644 --- a/include/rotgen/container/map/dynamic/indirect.hpp +++ b/include/rotgen/container/map/dynamic/indirect.hpp @@ -1,59 +1,59 @@ - #define SIZE 64 - #define TYPE double +#define SIZE 64 +#define TYPE double - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #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 - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef CLASSCONSTNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef CLASSCONSTNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #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 - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef CLASSCONSTNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef CLASSCONSTNAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float +#define SIZE 32 +#define TYPE float - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #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 - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef CLASSCONSTNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef CLASSCONSTNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) - #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 - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef TRANSSOURCENAME - #undef SOURCENAME - #undef CLASSCONSTNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef TRANSSOURCENAME +#undef SOURCENAME +#undef CLASSCONSTNAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE diff --git a/include/rotgen/container/map/dynamic/model.hpp b/include/rotgen/container/map/dynamic/model.hpp index cd5adfd..d7b90d9 100644 --- a/include/rotgen/container/map/dynamic/model.hpp +++ b/include/rotgen/container/map/dynamic/model.hpp @@ -13,17 +13,17 @@ //================================================================================================== class ROTGEN_EXPORT CLASSNAME { - public: +public: CLASSNAME(TYPE CONST* ptr, Index r, Index c); CLASSNAME(TYPE CONST* ptr, Index r, Index c, stride s); CLASSNAME(CLASSNAME const& other); CLASSNAME(CLASSNAME&&) noexcept; - #if !defined(USE_CONST) +#if !defined(USE_CONST) CLASSNAME& operator=(CLASSNAME const& other); CLASSNAME& operator=(CLASSNAME&& other); - #endif +#endif ~CLASSNAME(); @@ -34,65 +34,64 @@ class ROTGEN_EXPORT CLASSNAME 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 cwiseAbs() const; + SOURCENAME cwiseAbs2() const; SOURCENAME cwiseInverse() const; - SOURCENAME cwiseSqrt() 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) +#if !defined(USE_CONST) void normalize(); void transposeInPlace(); void adjointInPlace(); - #endif +#endif - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() 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 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; + SOURCENAME qr_solve(CLASSNAME const& rhs) const; - #if !defined(USE_CONST) - TYPE& operator()(Index i, Index j); - TYPE& operator()(Index i); - #endif +#if !defined(USE_CONST) + TYPE& operator()(Index i, Index j); + TYPE& operator()(Index i); +#endif TYPE operator()(Index i, Index j) const; TYPE operator()(Index i) const; - - #if !defined(USE_CONST) +#if !defined(USE_CONST) CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator+=(CLASSCONSTNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSCONSTNAME const& rhs); CLASSNAME& operator*=(CLASSNAME const& rhs); CLASSNAME& operator*=(CLASSCONSTNAME const& rhs); - CLASSNAME& operator*=(TYPE d); - CLASSNAME& operator/=(TYPE d); - #endif + CLASSNAME& operator*=(TYPE d); + CLASSNAME& operator/=(TYPE d); +#endif SOURCENAME operator-() const; SOURCENAME add(CLASSNAME const& rhs) const; @@ -106,27 +105,32 @@ class ROTGEN_EXPORT CLASSNAME SOURCENAME inverse() const; - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, CLASSNAME const&); - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, format const&); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + CLASSNAME const&); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + format const&); const TYPE* data() const; - #if !defined(USE_CONST) +#if !defined(USE_CONST) TYPE* data(); void setZero(); void setOnes(); void setRandom(); void setIdentity(); void setConstant(TYPE); - #endif +#endif - friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, + CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, + CLASSNAME const& rhs); - private: +private: struct payload; std::unique_ptr storage_; - public: - std::unique_ptr& storage() { return storage_; } +public: + std::unique_ptr& storage() { return storage_; } + std::unique_ptr const& storage() const { return storage_; } -}; \ No newline at end of file +}; diff --git a/include/rotgen/container/map/dynamic/operators.hpp b/include/rotgen/container/map/dynamic/operators.hpp index 2e825c7..b35a2fb 100644 --- a/include/rotgen/container/map/dynamic/operators.hpp +++ b/include/rotgen/container/map/dynamic/operators.hpp @@ -7,24 +7,28 @@ //================================================================================================== #pragma once -#define ROTGEN_DEF_RELOP_PAIR(OP, T1, T2) \ -ROTGEN_EXPORT bool operator OP (T1 const&, T2 const&); \ -inline bool operator OP (T2 const& a, T1 const& b) { return b OP a; } \ -/**/ +#define ROTGEN_DEF_RELOP_PAIR(OP, T1, T2) \ + ROTGEN_EXPORT bool operator OP(T1 const&, T2 const&); \ + inline bool operator OP(T2 const& a, T1 const& b) \ + { \ + return b OP a; \ + } \ + /**/ + +#define ROTGEN_DEF_RELOP(OP) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_impl32_col) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_impl32_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_const_impl32_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_row, map_impl32_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_row, map_impl32_col) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_impl32_col, map_impl32_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_impl64_col) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_impl64_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_const_impl64_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_row, map_impl64_row) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_row, map_impl64_col) \ + ROTGEN_DEF_RELOP_PAIR(OP, map_impl64_col, map_impl64_row) -#define ROTGEN_DEF_RELOP(OP) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_impl32_col) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_impl32_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_col, map_const_impl32_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_row, map_impl32_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl32_row, map_impl32_col) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_impl32_col, map_impl32_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_impl64_col) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_impl64_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_col, map_const_impl64_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_row, map_impl64_row) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_const_impl64_row, map_impl64_col) \ -ROTGEN_DEF_RELOP_PAIR(OP, map_impl64_col, map_impl64_row) \ /**/ namespace rotgen @@ -34,4 +38,4 @@ namespace rotgen } #undef ROTGEN_DEF_RELOP_PAIR -#undef ROTGEN_DEF_RELOP \ No newline at end of file +#undef ROTGEN_DEF_RELOP diff --git a/include/rotgen/container/map/fixed.hpp b/include/rotgen/container/map/fixed.hpp index 564c8ea..d0882ea 100644 --- a/include/rotgen/container/map/fixed.hpp +++ b/include/rotgen/container/map/fixed.hpp @@ -14,77 +14,90 @@ namespace rotgen { namespace detail { - template - struct compute_map_type + template struct compute_map_type { - using base = Eigen::Matrix< typename Ref::value_type - , Ref::RowsAtCompileTime, Ref::ColsAtCompileTime - , Ref::storage_order - >; + using base = Eigen::Matrix; using ref_t = std::conditional_t; - using type = Eigen::Map>; + using type = Eigen::Map>; }; template - using map_type = typename compute_map_type::type; + using map_type = typename compute_map_type::type; } template - class map : private detail::map_type, Options, std::is_const_v> + class map : private detail::map_type, + Options, + std::is_const_v> { - public: - using rotgen_tag = void; - using parent = detail::map_type, Options, std::is_const_v>; - using value_type = typename std::remove_const_t::value_type; + public: + using rotgen_tag = void; + using parent = + detail::map_type, Options, std::is_const_v>; + using value_type = typename std::remove_const_t::value_type; using concrete_type = typename std::remove_const_t::concrete_type; - 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 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; + 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 = detail::as_concrete_t; - using ptr_type = std::conditional_t; + using ptr_type = + std::conditional_t; using stride_type = Stride; - map(const map&) = default; - map(map&&) = default; - map& operator=(const map&) = default; - map& operator=(map&&) = default; + map(map const&) = default; + map(map&&) = default; + map& operator=(map const&) = default; + map& operator=(map&&) = default; + + map(ptr_type ptr, Index r, Index c, stride_type s) + : parent(ptr, r, c, strides(s, r, c)) + { + } - map(ptr_type ptr, Index r, Index c, stride_type s) : parent(ptr, r, c, strides(s,r,c)) {} 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); - }() - ) - {} + : parent(ptr, r, c, [&]() { + if constexpr (!std::same_as) + return strides(Stride{}, r, c); + else return strides(r, c); + }()) + { + } - map(ptr_type ptr, stride_type s) requires(RowsAtCompileTime!=-1 && ColsAtCompileTime!=-1) - : parent(ptr, strides(s,RowsAtCompileTime,ColsAtCompileTime)) - {} + map(ptr_type ptr, stride_type s) + requires(RowsAtCompileTime != -1 && ColsAtCompileTime != -1) + : parent(ptr, + strides(s, RowsAtCompileTime, ColsAtCompileTime)) + { + } - map(ptr_type ptr, Index sz) requires(RowsAtCompileTime==1 || ColsAtCompileTime==1) - : map(ptr, RowsAtCompileTime==1?1:sz, ColsAtCompileTime==1?1:sz) - {} + map(ptr_type ptr, Index sz) + requires(RowsAtCompileTime == 1 || ColsAtCompileTime == 1) + : map( + ptr, RowsAtCompileTime == 1 ? 1 : sz, ColsAtCompileTime == 1 ? 1 : sz) + { + } - map(ptr_type ptr) requires(RowsAtCompileTime!=-1 && ColsAtCompileTime!=-1) - : map( ptr, RowsAtCompileTime, ColsAtCompileTime ) - {} + map(ptr_type ptr) + requires(RowsAtCompileTime != -1 && ColsAtCompileTime != -1) + : map(ptr, RowsAtCompileTime, ColsAtCompileTime) + { + } - map(concepts::entity auto const& other) : parent(other.base()) - {} + map(concepts::entity auto const& other) : parent(other.base()) {} map& operator=(concepts::entity auto const& other) { @@ -92,62 +105,79 @@ namespace rotgen return *this; } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this); } + parent& base() { return static_cast(*this); } + + parent const& base() const { return static_cast(*this); } auto evaluate() const { - auto res = static_cast(*this).eval(); + 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; + if constexpr (use_expression_templates) return base().noalias(); + else return *this; } decltype(auto) noalias() { - if constexpr(use_expression_templates) return base().noalias(); - else return *this; + if constexpr (use_expression_templates) return base().noalias(); + else return *this; } - value_type& operator()(Index i, Index j) requires(!is_immutable) + value_type& operator()(Index i, Index j) + requires(!is_immutable) { - return base()(i,j); + return base()(i, j); } - value_type& operator()(Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator()(Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return base().data()[i]; } - value_type& operator[](Index i) requires(!is_immutable && IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(!is_immutable && IsVectorAtCompileTime) { return (*this)(i); } - value_type operator()(Index i, Index j) const { return base()(i,j); } - value_type operator()(Index i) const requires(IsVectorAtCompileTime) { return base().data()[i]; } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) { return (*this)(i); } + value_type operator()(Index i, Index j) const { return base()(i, j); } + + value_type operator()(Index i) const + requires(IsVectorAtCompileTime) + { + return base().data()[i]; + } + + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) + { + return (*this)(i); + } template - map& operator+=(map const& rhs) requires(!is_immutable) + map& operator+=(map const& rhs) + requires(!is_immutable) { base() += rhs.base(); return *this; } template - map& operator-=(map const& rhs) requires(!is_immutable) + map& operator-=(map const& rhs) + requires(!is_immutable) { base() -= rhs.base(); return *this; } template - map& operator*=(map const& rhs) requires(!is_immutable) + map& operator*=(map const& rhs) + requires(!is_immutable) { base() *= rhs.base(); return *this; @@ -167,129 +197,180 @@ namespace rotgen auto cwiseMin(map const& rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseMin(rhs.base())}; - else return base().cwiseMin(rhs.base()); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseMin(rhs.base())}; + else return base().cwiseMin(rhs.base()); } auto cwiseMin(value_type rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseMin(rhs)}; - else return base().cwiseMin(rhs); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseMin(rhs)}; + else return base().cwiseMin(rhs); } auto cwiseMax(map const& rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseMax(rhs.base())}; - else return base().cwiseMax(rhs.base()); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseMax(rhs.base())}; + else return base().cwiseMax(rhs.base()); } auto cwiseMax(value_type rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseMax(rhs)}; - else return base().cwiseMax(rhs); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseMax(rhs)}; + else return base().cwiseMax(rhs); } auto cwiseProduct(map const& rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseProduct(rhs.base())}; - else return base().cwiseProduct(rhs.base()); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseProduct(rhs.base())}; + else return base().cwiseProduct(rhs.base()); } auto cwiseQuotient(map const& rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseQuotient(rhs.base())}; - else return base().cwiseQuotient(rhs.base()); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseQuotient(rhs.base())}; + else return base().cwiseQuotient(rhs.base()); } auto cwiseAbs() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs()}; - else return base().cwiseAbs(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseAbs()}; + else return base().cwiseAbs(); } auto cwiseAbs2() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseAbs2()}; - else return base().cwiseAbs2(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); } auto cwiseInverse() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseInverse()}; - else return base().cwiseInverse(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseInverse()}; + else return base().cwiseInverse(); } auto cwiseSqrt() const { - if constexpr(!use_expression_templates) return concrete_type{parent::cwiseSqrt()}; - else return base().cwiseSqrt(); + if constexpr (!use_expression_templates) + return concrete_type{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); } auto cross(map const& rhs) const { - if constexpr(!use_expression_templates) return concrete_type{parent::cross(rhs.base())}; - else return base().cross(rhs.base()); + if constexpr (!use_expression_templates) + return concrete_type{parent::cross(rhs.base())}; + else return base().cross(rhs.base()); } auto inverse() const { - if constexpr(use_expression_templates) return base().inverse(); - else return as_concrete_type(base().inverse()); + if constexpr (use_expression_templates) return base().inverse(); + else + return as_concrete_type(base().inverse()); } - auto normalized() const requires(IsVectorAtCompileTime) + auto normalized() const + requires(IsVectorAtCompileTime) { - if constexpr(use_expression_templates) return base().normalized(); - else return as_concrete_type(base().normalized()); + if constexpr (use_expression_templates) return base().normalized(); + else + return as_concrete_type( + base().normalized()); } auto transpose() const { - if constexpr(use_expression_templates) return base().transpose(); - else return as_concrete_type(base().transpose()); + if constexpr (use_expression_templates) return base().transpose(); + else + return as_concrete_type( + base().transpose()); } auto adjoint() const { - if constexpr(use_expression_templates) return base().adjoint(); - else return as_concrete_type(base().adjoint()); + if constexpr (use_expression_templates) return base().adjoint(); + else + return as_concrete_type(base().adjoint()); } auto conjugate() const { - if constexpr(use_expression_templates) return base().conjugate(); - else return as_concrete_type(base().conjugate()); + if constexpr (use_expression_templates) return base().conjugate(); + else + return as_concrete_type( + base().conjugate()); } - void normalize() requires(IsVectorAtCompileTime) + void normalize() + requires(IsVectorAtCompileTime) { base().normalize(); } - void transposeInPlace() { base().transposeInPlace(); } - void adjointInPlace() { base().adjointInPlace(); } + void transposeInPlace() { base().transposeInPlace(); } + + void adjointInPlace() { base().adjointInPlace(); } auto qr_solve(auto const& rhs) const { return concrete_type(base().colPivHouseholderQr().solve(rhs.base())); }; - 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() + requires(requires { Ref::Zero(); }) + { + return Ref::Zero(); + } - static auto Ones() requires( requires {Ref::Ones();} ) { return Ref::Ones(); } - static auto Ones(int rows, int cols) { return Ref::Ones(rows,cols); } + static auto Zero(int rows, int cols) { return Ref::Zero(rows, cols); } - static auto Constant(value_type value) requires( requires {Ref::Constant(value);} ) - { return Ref::Constant(value); } + static auto Ones() + requires(requires { Ref::Ones(); }) + { + return Ref::Ones(); + } - static auto Constant(int rows, int cols, value_type value) { return Ref::Constant(rows, cols, value); } + static auto Ones(int rows, int cols) { return Ref::Ones(rows, cols); } - static auto Random() requires( requires {Ref::Random();} ) { return Ref::Random(); } - static auto Random(int rows, int cols) { return Ref::Random(rows, cols); } + static auto Constant(value_type value) + requires(requires { Ref::Constant(value); }) + { + return Ref::Constant(value); + } - static auto Identity() requires( requires {Ref::Identity();} ) { return Ref::Identity(); } - static auto Identity(int rows, int cols) { return Ref::Identity(rows, cols); } + static auto Constant(int rows, int cols, value_type value) + { + return Ref::Constant(rows, cols, value); + } + + static auto Random() + requires(requires { Ref::Random(); }) + { + return Ref::Random(); + } + + static auto Random(int rows, int cols) { return Ref::Random(rows, cols); } + + static auto Identity() + requires(requires { Ref::Identity(); }) + { + return Ref::Identity(); + } + + static auto Identity(int rows, int cols) + { + return Ref::Identity(rows, cols); + } map& setOnes() { @@ -321,27 +402,27 @@ namespace rotgen return *this; } - using parent::innerStride; - using parent::outerStride; - using parent::rows; using parent::cols; - using parent::size; using parent::data; - using parent::sum; + using parent::innerStride; using parent::mean; - using parent::prod; - using parent::trace; using parent::norm; + using parent::outerStride; + using parent::prod; + using parent::rows; + using parent::size; using parent::squaredNorm; - + using parent::sum; + using parent::trace; auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -351,7 +432,7 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::maxCoeff(&r, &c); *row = r; *col = c; @@ -359,7 +440,7 @@ namespace rotgen } template - value_type dot(map const& rhs) const + value_type dot(map const& rhs) const { return base().dot(rhs.base()); } @@ -372,103 +453,104 @@ namespace rotgen }; template - bool operator==(map const& lhs, map const& rhs) + bool operator==(map const& lhs, map const& rhs) { return lhs.base() == rhs.base(); } template - bool operator!=(map const& lhs, map const& rhs) + bool operator!=(map const& lhs, map const& rhs) { return lhs.base() != rhs.base(); } #if defined(ROTGEN_ENABLE_EXPRESSION_TEMPLATES) template - auto operator+(map const& lhs, map const& rhs) + auto operator+(map const& lhs, map const& rhs) { return lhs.base() + rhs.base(); } template - auto operator-(map const& lhs, map const& rhs) + auto operator-(map const& lhs, map const& rhs) { return lhs.base() - rhs.base(); } template - auto operator*(map const& lhs, map const& rhs) + auto operator*(map const& lhs, map const& rhs) { return lhs.base() * rhs.base(); } template - auto operator*( map const& lhs, std::convertible_to auto s) + auto operator*(map const& lhs, + std::convertible_to auto s) { return lhs.base() * s; } template - auto operator*(std::convertible_to auto s, map const& rhs) + auto operator*(std::convertible_to auto s, + map const& rhs) { return s * rhs.base(); } template - auto operator/(map const& lhs, std::convertible_to auto s) + auto operator/(map const& lhs, + std::convertible_to auto s) { return lhs.base() / s; } #else template - typename map::concrete_type operator+(map const& lhs, map const& rhs) + typename map::concrete_type operator+(map const& lhs, + map const& rhs) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() + rhs.base()); } template - typename map::concrete_type operator-(map const& lhs, map const& rhs) + typename map::concrete_type operator-(map const& lhs, + map const& rhs) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() - rhs.base()); } template - matrix - operator*(map const& lhs, map const& rhs) + matrix + operator*(map const& lhs, map const& rhs) { - using concrete_type = matrix< typename R1::value_type - , R1::RowsAtCompileTime,R2::ColsAtCompileTime - >; + using concrete_type = matrix; return concrete_type(lhs.base() * rhs.base()); } template - typename map::concrete_type operator*( map const& lhs - , std::convertible_to auto s - ) + typename map::concrete_type operator*( + map const& lhs, std::convertible_to auto s) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() * s); } template - typename map::concrete_type operator*( std::convertible_to auto s - , map const& rhs - ) + typename map::concrete_type operator*( + std::convertible_to auto s, map const& rhs) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(rhs.base() * s); } template - typename map::concrete_type operator/( map const& lhs - , std::convertible_to auto s - ) + typename map::concrete_type operator/( + map const& lhs, std::convertible_to auto s) { - using concrete_type = typename map::concrete_type; + using concrete_type = typename map::concrete_type; return concrete_type(lhs.base() / s); } #endif diff --git a/include/rotgen/container/matrix.hpp b/include/rotgen/container/matrix.hpp index 14d78ae..9f24148 100644 --- a/include/rotgen/container/matrix.hpp +++ b/include/rotgen/container/matrix.hpp @@ -13,4 +13,4 @@ #include #else #include -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/container/matrix/dynamic.hpp b/include/rotgen/container/matrix/dynamic.hpp index ec5f811..6f888aa 100644 --- a/include/rotgen/container/matrix/dynamic.hpp +++ b/include/rotgen/container/matrix/dynamic.hpp @@ -14,134 +14,171 @@ namespace rotgen { - template< typename Scalar - , int Rows = Dynamic , int Cols = Dynamic - , int Opts = detail::force_order - , int MaxRows = Rows , int MaxCols = Cols - > - class matrix : public find_matrix + template, + int MaxRows = Rows, + int MaxCols = Cols> + class matrix : public find_matrix { - public: - using parent = find_matrix; - using rotgen_tag = void; - using concrete_type = matrix; - using value_type = Scalar; + public: + using parent = find_matrix; + using rotgen_tag = void; + using concrete_type = matrix; + using value_type = Scalar; - 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; + 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; + using transposed_type = matrix; - matrix() : parent(Rows==-1?0:Rows,Cols==-1?0:Cols) {} + matrix() : parent(Rows == -1 ? 0 : Rows, Cols == -1 ? 0 : Cols) {} - matrix(Index r, Index c) requires(!IsCompileTimeSized) - : parent(r, c) + matrix(Index r, Index c) + requires(!IsCompileTimeSized) + : parent(r, c) { - if constexpr(Rows != -1) assert(r == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(c == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(r == Rows && "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(c == Cols && + "Mismatched between dynamic and static column size"); } - matrix(Index n) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) - : parent(Rows != -1 ? 1 : n, Cols != -1 ? 1 : n) - {} + matrix(Index n) + requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) + : parent(Rows != -1 ? 1 : n, Cols != -1 ? 1 : n) + { + } - matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent(1,1,{v}) {} + matrix(Scalar v) + requires(Rows == 1 && Cols == 1) + : parent(1, 1, {v}) + { + } matrix(Scalar v0, Scalar v1, auto... vs) - requires((Rows == (2+sizeof...(vs)) && Cols == 1) || (Rows == 1 && Cols == (2+sizeof...(vs)))) - : parent(Rows,Cols,{v0,v1,static_cast(vs)...}) - {} + requires((Rows == (2 + sizeof...(vs)) && Cols == 1) || + (Rows == 1 && Cols == (2 + sizeof...(vs)))) + : parent(Rows, Cols, {v0, v1, static_cast(vs)...}) + { + } matrix(parent const& base) : parent(base) {} - matrix(std::initializer_list> init) : parent(init) + matrix(std::initializer_list> init) + : parent(init) { - if constexpr(Rows != -1) assert(init.size() == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) + if constexpr (Rows != -1) + assert(init.size() == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) { [[maybe_unused]] std::size_t c = 0; - if(init.size()) c = init.begin()->size(); - assert(c == Cols && "Mismatched between dynamic and static column size"); + if (init.size()) c = init.begin()->size(); + assert(c == Cols && + "Mismatched between dynamic and static column size"); } } matrix(std::initializer_list init) - requires(IsVectorAtCompileTime) : parent(Rows, Cols, init) - {} - - matrix(concepts::entity auto const& e) : parent(e.rows(),e.cols()) + requires(IsVectorAtCompileTime) + : parent(Rows, Cols, init) { - 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"); + } + + matrix(concepts::entity auto const& e) : parent(e.rows(), e.cols()) + { + 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); + for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c); } matrix& operator=(concepts::entity auto const& e) { - 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"); + 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); + for (rotgen::Index c = 0; c < e.cols(); ++c) (*this)(r, c) = e(r, c); return *this; } - value_type& operator[](Index i) requires(IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(IsVectorAtCompileTime) { return (*this)(i); } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) { return (*this)(i); } - auto evaluate() const { return *this; } - decltype(auto) noalias() const { return *this; } - decltype(auto) noalias() { return *this; } + auto evaluate() const { return *this; } + + decltype(auto) noalias() const { return *this; } + + decltype(auto) noalias() { return *this; } void resize(int r, int 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"); + 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 resize(int s) requires(IsVectorAtCompileTime) + void resize(int s) + requires(IsVectorAtCompileTime) { - if constexpr(Rows == 1) parent::resize(1,s); - else parent::resize(s,1); + if constexpr (Rows == 1) parent::resize(1, s); + else parent::resize(s, 1); } void conservativeResize(int r, int 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"); + 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) requires(IsVectorAtCompileTime) + 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 requires(IsVectorAtCompileTime) + matrix normalized() const + requires(IsVectorAtCompileTime) { return matrix(base().normalized()); } @@ -151,28 +188,30 @@ namespace rotgen return transposed_type(base().transpose()); } - matrix conjugate() const - { - return matrix(base().conjugate()); - } + matrix conjugate() const { return matrix(base().conjugate()); } transposed_type adjoint() const { return transposed_type(base().adjoint()); } - void normalize() requires(IsVectorAtCompileTime) + void normalize() + requires(IsVectorAtCompileTime) { parent::normalize(); } void transposeInPlace() { parent::transposeInPlace(); } - void adjointInPlace() { parent::adjointInPlace(); } - matrix cwiseAbs() const { return matrix(base().cwiseAbs()); } - matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); } + void adjointInPlace() { parent::adjointInPlace(); } + + matrix cwiseAbs() const { return matrix(base().cwiseAbs()); } + + matrix cwiseAbs2() const { return matrix(base().cwiseAbs2()); } + matrix cwiseInverse() const { return matrix(base().cwiseInverse()); } - matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); } + + matrix cwiseSqrt() const { return matrix(base().cwiseSqrt()); } friend bool operator==(matrix const& lhs, matrix const& rhs) { @@ -191,10 +230,7 @@ namespace rotgen return *this; } - matrix operator-() const - { - return matrix(base().operator-()); - } + matrix operator-() const { return matrix(base().operator-()); } matrix& operator*=(matrix const& rhs) { @@ -215,12 +251,13 @@ namespace rotgen } auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -230,70 +267,95 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::maxCoeff(&r, &c); *row = r; *col = c; return result; } - static matrix Ones() requires (Rows != -1 && Cols != -1) + static matrix Ones() + requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } static matrix Ones(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Ones(rows, cols); } - static matrix Zero() requires (Rows != -1 && Cols != -1) + static matrix Zero() + requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } static matrix Zero(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Zero(rows, cols); } - static matrix Constant(Scalar value) requires (Rows != -1 && Cols != -1) + static matrix Constant(Scalar value) + requires(Rows != -1 && Cols != -1) { return parent::Constant(Rows, Cols, static_cast(value)); } static matrix Constant(int rows, int cols, Scalar value) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Constant(rows, cols, static_cast(value)); } - static matrix Random() requires (Rows != -1 && Cols != -1) + static matrix Random() + requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } static matrix Random(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Random(rows, cols); } - static matrix Identity() requires (Rows != -1 && Cols != -1) + static matrix Identity() + requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } static matrix Identity(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Identity(rows, cols); } @@ -323,7 +385,8 @@ namespace rotgen matrix& setConstant(Scalar value) { - *this = parent::Constant(parent::rows(), parent::cols(), static_cast(value)); + *this = parent::Constant(parent::rows(), parent::cols(), + static_cast(value)); return *this; } @@ -357,55 +420,65 @@ namespace rotgen return *this; } - template - Scalar lpNorm() const + template Scalar lpNorm() const { static_assert(P == 1 || P == 2 || P == Infinity); return parent::lp_norm(P); } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this);; } + parent& base() { return static_cast(*this); } + + parent const& base() const + { + return static_cast(*this); + ; + } }; template - matrix operator+(matrix const& lhs, matrix const& rhs) + matrix operator+(matrix const& lhs, + matrix const& rhs) { - matrix that(lhs); + matrix that(lhs); return that += rhs; } template - matrix operator-(matrix const& lhs, matrix const& rhs) + matrix operator-(matrix const& lhs, + matrix const& rhs) { - matrix that(lhs); + matrix that(lhs); return that -= rhs; } template - matrix operator*(matrix const& lhs, matrix const& rhs) + matrix operator*(matrix const& lhs, + matrix const& rhs) { - matrix that(lhs); + matrix that(lhs); return that *= rhs; } template - matrix operator*(matrix const& lhs, double rhs) + matrix operator*(matrix const& lhs, + double rhs) { - matrix that(lhs); + matrix that(lhs); return that *= rhs; } template - matrix operator*(double lhs, matrix const& rhs) + matrix operator*(double lhs, + matrix const& rhs) { return rhs * lhs; } template - matrix operator/(matrix const& lhs, double rhs) + matrix operator/(matrix const& lhs, + double rhs) { - matrix that(lhs); + matrix that(lhs); return that /= rhs; } -} \ No newline at end of file +} diff --git a/include/rotgen/container/matrix/dynamic/impl.hpp b/include/rotgen/container/matrix/dynamic/impl.hpp index 51ee304..1c47f31 100644 --- a/include/rotgen/container/matrix/dynamic/impl.hpp +++ b/include/rotgen/container/matrix/dynamic/impl.hpp @@ -21,49 +21,64 @@ namespace rotgen class matrix_impl32_row; class matrix_impl32_col; - #define SIZE 64 - #define TYPE double +#define SIZE 64 +#define TYPE double - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include - #undef CLASSNAME - #undef TRANSCLASSNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include +#undef CLASSNAME +#undef TRANSCLASSNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include - #undef CLASSNAME - #undef TRANSCLASSNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include +#undef CLASSNAME +#undef TRANSCLASSNAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float +#define SIZE 32 +#define TYPE float - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include - #undef CLASSNAME - #undef TRANSCLASSNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include +#undef CLASSNAME +#undef TRANSCLASSNAME - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include - #undef CLASSNAME - #undef TRANSCLASSNAME +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include +#undef CLASSNAME +#undef TRANSCLASSNAME - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - template struct find_matrix_impl; + template struct find_matrix_impl; - template<> struct find_matrix_impl { using type = matrix_impl32_col; }; - template<> struct find_matrix_impl { using type = matrix_impl32_row; }; - template<> struct find_matrix_impl { using type = matrix_impl64_col; }; - template<> struct find_matrix_impl { using type = matrix_impl64_row; }; + template<> struct find_matrix_impl + { + using type = matrix_impl32_col; + }; - template - using find_matrix = typename find_matrix_impl::type; + template<> struct find_matrix_impl + { + using type = matrix_impl32_row; + }; + + template<> struct find_matrix_impl + { + using type = matrix_impl64_col; + }; + + template<> struct find_matrix_impl + { + using type = matrix_impl64_row; + }; + + template + using find_matrix = typename find_matrix_impl::type; } diff --git a/include/rotgen/container/matrix/dynamic/model.hpp b/include/rotgen/container/matrix/dynamic/model.hpp index 95f6ca9..9d43c1d 100644 --- a/include/rotgen/container/matrix/dynamic/model.hpp +++ b/include/rotgen/container/matrix/dynamic/model.hpp @@ -13,10 +13,12 @@ //================================================================================================== class ROTGEN_EXPORT CLASSNAME { - public: +public: CLASSNAME(); CLASSNAME(std::size_t rows, std::size_t cols); - CLASSNAME(std::size_t rows, std::size_t cols,std::initializer_list init); + CLASSNAME(std::size_t rows, + std::size_t cols, + std::initializer_list init); CLASSNAME(std::initializer_list> init); @@ -35,53 +37,57 @@ class ROTGEN_EXPORT CLASSNAME void resize(std::size_t new_rows, std::size_t new_cols); void conservativeResize(std::size_t new_rows, std::size_t 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 cwiseAbs() const; + CLASSNAME cwiseAbs2() const; CLASSNAME cwiseInverse() const; - CLASSNAME cwiseSqrt() const; + CLASSNAME cwiseSqrt() const; void normalize(); void transposeInPlace(); void adjointInPlace(); - TYPE sum() const; - TYPE prod() const; - TYPE mean() const; - TYPE trace() 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 squaredNorm() const; + TYPE norm() const; TYPE lp_norm(int p) const; - TYPE& operator()(std::size_t i, std::size_t j); + TYPE& operator()(std::size_t i, std::size_t j); TYPE const& operator()(std::size_t i, std::size_t j) const; - TYPE& operator()(std::size_t index); + TYPE& operator()(std::size_t index); TYPE const& operator()(std::size_t index) const; CLASSNAME& operator+=(CLASSNAME const& rhs); CLASSNAME& operator-=(CLASSNAME const& rhs); CLASSNAME operator-() const; CLASSNAME& operator*=(CLASSNAME const& rhs); - CLASSNAME& operator*=(TYPE d); - CLASSNAME& operator/=(TYPE d); + CLASSNAME& operator*=(TYPE d); + CLASSNAME& operator/=(TYPE d); - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&,CLASSNAME const&); - friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, format const&); - friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs); - friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + CLASSNAME const&); + friend ROTGEN_EXPORT std::ostream& operator<<(std::ostream&, + format const&); + friend ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, + CLASSNAME const& rhs); + friend ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, + CLASSNAME const& rhs); const TYPE* data() const; - TYPE* data(); + TYPE* data(); static CLASSNAME Zero(std::size_t rows, std::size_t cols); static CLASSNAME Ones(std::size_t rows, std::size_t cols); @@ -89,11 +95,12 @@ class ROTGEN_EXPORT CLASSNAME static CLASSNAME Random(std::size_t rows, std::size_t cols); static CLASSNAME Identity(std::size_t rows, std::size_t cols); - private: +private: struct payload; std::unique_ptr storage_; - public: - std::unique_ptr& storage() { return storage_; } +public: + std::unique_ptr& storage() { return storage_; } + std::unique_ptr const& storage() const { return storage_; } -}; \ No newline at end of file +}; diff --git a/include/rotgen/container/matrix/fixed.hpp b/include/rotgen/container/matrix/fixed.hpp index b01e079..0bc2752 100644 --- a/include/rotgen/container/matrix/fixed.hpp +++ b/include/rotgen/container/matrix/fixed.hpp @@ -15,114 +15,139 @@ namespace rotgen { namespace detail { - template - using storage_type = std::conditional_t < storage_status - , Eigen::Matrix - , Eigen::Matrix - >; + template + using storage_type = std::conditional_t< + storage_status, + Eigen::Matrix, + Eigen::Matrix>; } - template< typename Scalar - , int Rows = Dynamic , int Cols = Dynamic - , int Opts = detail::force_order - , int MaxRows = Rows, int MaxCols = Cols - > - class matrix : private detail::storage_type + template, + int MaxRows = Rows, + int MaxCols = Cols> + class matrix + : private detail::storage_type { - public: - using rotgen_tag = void; - using parent = detail::storage_type; - using value_type = Scalar; - using Index = typename parent::Index; + public: + using rotgen_tag = void; + using parent = + detail::storage_type; + using value_type = Scalar; + using Index = typename parent::Index; static constexpr auto storage_order = Opts & 1; using concrete_type = matrix; using concrete_dynamic_type = matrix; - 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; + 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 = detail::as_concrete_t; - static constexpr bool is_immutable = false; - static constexpr bool is_defined_static = Rows!=-1 && Cols!=-1; - static constexpr bool has_static_storage = storage_status; + static constexpr bool is_immutable = false; + static constexpr bool is_defined_static = Rows != -1 && Cols != -1; + static constexpr bool has_static_storage = + storage_status; - public: - - matrix() requires(has_static_storage) {} - matrix() requires(!has_static_storage) : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0){} - matrix(Index r, Index c) requires(!IsCompileTimeSized) : parent(r, c) {} - - matrix(const matrix& other) = default; - matrix(matrix&& other) = default; - matrix& operator=(const matrix&) = default; - matrix& operator=(matrix&&) = default; - - matrix(std::initializer_list> init) : parent(init) - {} - - matrix(Index n) requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) - : parent(n) - {} - - matrix(Scalar v) requires(Rows == 1 && Cols == 1) : parent - ( [&]() - { - if constexpr(has_static_storage) return parent(v); - else return parent{1,1}; - }() - ) + public: + matrix() + requires(has_static_storage) { - if constexpr(!has_static_storage) (*this)(0) = v; + } + + matrix() + requires(!has_static_storage) + : parent(Rows > 0 ? Rows : 0, Cols > 0 ? Cols : 0) + { + } + + matrix(Index r, Index c) + requires(!IsCompileTimeSized) + : parent(r, c) + { + } + + matrix(matrix const& other) = default; + matrix(matrix&& other) = default; + matrix& operator=(matrix const&) = default; + matrix& operator=(matrix&&) = default; + + matrix(std::initializer_list> init) + : parent(init) + { + } + + matrix(Index n) + requires(IsVectorAtCompileTime && (Rows != 1 || Cols != 1)) + : parent(n) + { + } + + 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) (*this)(0) = v; } explicit matrix(std::initializer_list init) requires(IsVectorAtCompileTime) - : parent( [&]() - { - if constexpr(has_static_storage) return parent{}; - else return parent{Rows,Cols}; - }() - ) + : parent([&]() { + 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) - requires((Rows == (2+sizeof...(vs)) && Cols == 1) || (Rows == 1 && Cols == (2+sizeof...(vs)))) - : matrix({v0,v1,static_cast(vs)...}) - {} + requires((Rows == (2 + sizeof...(vs)) && Cols == 1) || + (Rows == 1 && Cols == (2 + sizeof...(vs)))) + : matrix({v0, v1, static_cast(vs)...}) + { + } - matrix(concepts::entity auto const& other) : parent(other.base()) - {} + matrix(concepts::entity auto const& other) : parent(other.base()) {} template - matrix(const Eigen::MatrixBase& other) : parent(other) - {} + matrix(Eigen::MatrixBase const& other) : parent(other) + { + } template - matrix(const Eigen::EigenBase& other) : parent(other) - {} + matrix(Eigen::EigenBase const& other) : parent(other) + { + } template - matrix& operator=(const Eigen::MatrixBase& other) + matrix& operator=(Eigen::MatrixBase const& other) { parent::operator=(other); return *this; } template - matrix& operator=(const Eigen::EigenBase& other) + matrix& operator=(Eigen::EigenBase const& other) { parent::operator=(other); return *this; @@ -134,8 +159,9 @@ namespace rotgen return *this; } - parent& base() { return static_cast(*this); } - parent const& base() const { return static_cast(*this); } + parent& base() { return static_cast(*this); } + + parent const& base() const { return static_cast(*this); } auto evaluate() const { @@ -145,19 +171,20 @@ namespace rotgen decltype(auto) noalias() const { - if constexpr(use_expression_templates) return base().noalias(); - else return *this; + if constexpr (use_expression_templates) return base().noalias(); + else return *this; } decltype(auto) noalias() { - 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 requires(IsVectorAtCompileTime) + 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(); @@ -167,7 +194,7 @@ namespace rotgen auto transpose() const { - if constexpr(use_expression_templates) return base().transpose(); + if constexpr (use_expression_templates) return base().transpose(); else { auto res = base().transpose(); @@ -187,163 +214,205 @@ namespace rotgen return as_concrete_type(res); } - void normalize() requires(IsVectorAtCompileTime) + void normalize() + requires(IsVectorAtCompileTime) { parent::normalize(); } void transposeInPlace() { parent::transposeInPlace(); } - void adjointInPlace() { parent::adjointInPlace(); } + + void adjointInPlace() { parent::adjointInPlace(); } auto cwiseAbs() const { - if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs()}; - else return base().cwiseAbs(); + if constexpr (!use_expression_templates) + return matrix{parent::cwiseAbs()}; + else return base().cwiseAbs(); } auto cwiseAbs2() const { - if constexpr(!use_expression_templates) return matrix{parent::cwiseAbs2()}; - else return base().cwiseAbs2(); + if constexpr (!use_expression_templates) + return matrix{parent::cwiseAbs2()}; + else return base().cwiseAbs2(); } auto cwiseInverse() const { - if constexpr(!use_expression_templates) return matrix{parent::cwiseInverse()}; - else return base().cwiseInverse(); + if constexpr (!use_expression_templates) + return matrix{parent::cwiseInverse()}; + else return base().cwiseInverse(); } auto cwiseSqrt() const { - if constexpr(!use_expression_templates) return matrix{parent::cwiseSqrt()}; - else return base().cwiseSqrt(); + if constexpr (!use_expression_templates) + return matrix{parent::cwiseSqrt()}; + else return base().cwiseSqrt(); } - void resize(int s) requires(IsVectorAtCompileTime) + void resize(int s) + requires(IsVectorAtCompileTime) { - 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"); + 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 r, int 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"); + 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 s) requires(IsVectorAtCompileTime) + void conservativeResize(int s) + requires(IsVectorAtCompileTime) { - 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"); + 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 r, int 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"); + 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) requires (Rows != -1 && Cols != -1) + static matrix Constant(Scalar value) + requires(Rows != -1 && Cols != -1) { return parent::Constant(Rows, Cols, static_cast(value)); } static matrix Constant(int rows, int cols, Scalar value) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Constant(rows, cols, static_cast(value)); } - static matrix Identity() requires (Rows != -1 && Cols != -1) + static matrix Identity() + requires(Rows != -1 && Cols != -1) { return parent::Identity(Rows, Cols); } static matrix Identity(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Identity(rows, cols); } - static matrix Ones() requires (Rows != -1 && Cols != -1) + static matrix Ones() + requires(Rows != -1 && Cols != -1) { return parent::Ones(Rows, Cols); } static matrix Ones(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Ones(rows, cols); } - static matrix Zero() requires (Rows != -1 && Cols != -1) + static matrix Zero() + requires(Rows != -1 && Cols != -1) { return parent::Zero(Rows, Cols); } static matrix Zero(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + assert(cols == Cols && + "Mismatched between dynamic and static column size"); return parent::Zero(rows, cols); } - static matrix Random() requires (Rows != -1 && Cols != -1) + static matrix Random() + requires(Rows != -1 && Cols != -1) { return parent::Random(Rows, Cols); } static matrix Random(int rows, int cols) { - if constexpr(Rows != -1) assert(rows == Rows && "Mismatched between dynamic and static row size"); - if constexpr(Cols != -1) assert(cols == Cols && "Mismatched between dynamic and static column size"); + if constexpr (Rows != -1) + assert(rows == Rows && + "Mismatched between dynamic and static row size"); + if constexpr (Cols != -1) + 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

(); } - value_type& operator[](Index i) requires(IsVectorAtCompileTime) + value_type& operator[](Index i) + requires(IsVectorAtCompileTime) { return (*this)(i); } - value_type operator[](Index i) const requires(IsVectorAtCompileTime) + value_type operator[](Index i) const + requires(IsVectorAtCompileTime) { return (*this)(i); } using parent::operator(); - using parent::rows; using parent::cols; - using parent::size; - using parent::prod; - using parent::mean; - using parent::trace; - using parent::squaredNorm; - using parent::norm; - using parent::sum; using parent::data; - + using parent::mean; + using parent::norm; + using parent::prod; + using parent::rows; + using parent::size; + using parent::squaredNorm; + using parent::sum; + using parent::trace; auto minCoeff() const { return parent::minCoeff(); } + auto maxCoeff() const { return parent::maxCoeff(); } template auto minCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::minCoeff(&r, &c); *row = r; *col = c; @@ -353,7 +422,7 @@ namespace rotgen template auto maxCoeff(IndexType* row, IndexType* col) const { - Index r,c; + Index r, c; auto result = parent::maxCoeff(&r, &c); *row = r; *col = c; @@ -362,7 +431,7 @@ namespace rotgen matrix& setOnes() { - *this = parent::Ones(rows(),cols()); + *this = parent::Ones(rows(), cols()); return *this; } @@ -374,7 +443,7 @@ namespace rotgen matrix& setZero() { - *this = parent::Zero(rows(),cols()); + *this = parent::Zero(rows(), cols()); return *this; } @@ -386,7 +455,7 @@ namespace rotgen matrix& setConstant(Scalar value) { - *this = parent::Constant(rows(),cols(), static_cast(value)); + *this = parent::Constant(rows(), cols(), static_cast(value)); return *this; } @@ -398,7 +467,7 @@ namespace rotgen matrix& setRandom() { - *this = parent::Random(rows(),cols()); + *this = parent::Random(rows(), cols()); return *this; } @@ -410,7 +479,7 @@ namespace rotgen matrix& setIdentity() { - *this = parent::Identity(rows(),cols()); + *this = parent::Identity(rows(), cols()); return *this; } @@ -432,10 +501,7 @@ namespace rotgen return *this; } - matrix operator-() const - { - return matrix(base()(*this).operator-()); - } + matrix operator-() const { return matrix(base()(*this).operator-()); } matrix& operator*=(matrix const& rhs) { @@ -455,4 +521,4 @@ namespace rotgen return *this; } }; -} \ No newline at end of file +} diff --git a/include/rotgen/container/ref.hpp b/include/rotgen/container/ref.hpp index 5c4b409..16c7fe7 100644 --- a/include/rotgen/container/ref.hpp +++ b/include/rotgen/container/ref.hpp @@ -7,8 +7,8 @@ //================================================================================================== #pragma once -#include #include +#include #if !defined(ROTGEN_FORCE_DYNAMIC) #include @@ -20,88 +20,113 @@ namespace rotgen template class ref : private map { - public: - using parent = map; - using value_type = typename T::value_type; - using rotgen_tag = void; - using rotgen_ref_tag = void; + public: + using parent = map; + using value_type = typename T::value_type; + using rotgen_tag = void; + using rotgen_ref_tag = void; - static constexpr int storage_order = T::storage_order; - static constexpr int RowsAtCompileTime = T::RowsAtCompileTime; - static constexpr int ColsAtCompileTime = T::ColsAtCompileTime; + static constexpr int storage_order = T::storage_order; + static constexpr int RowsAtCompileTime = T::RowsAtCompileTime; + static constexpr int ColsAtCompileTime = T::ColsAtCompileTime; static constexpr bool IsVectorAtCompileTime = T::IsVectorAtCompileTime; - static constexpr bool is_immutable = T::is_immutable; + static constexpr bool is_immutable = T::is_immutable; using parent::evaluate; using parent::noalias; using parent::operator(); using parent::operator[]; - using parent::rows; using parent::cols; - using parent::size; - using parent::data; - using parent::sum; - using parent::prod; - using parent::mean; - using parent::trace; - using parent::transpose; using parent::cwiseAbs; using parent::cwiseAbs2; using parent::cwiseInverse; using parent::cwiseSqrt; + using parent::data; + using parent::lpNorm; using parent::maxCoeff; + using parent::mean; using parent::minCoeff; using parent::norm; using parent::normalize; + using parent::prod; + using parent::rows; + using parent::size; using parent::squaredNorm; - using parent::lpNorm; + using parent::sum; + using parent::trace; + using parent::transpose; using parent::operator+=; using parent::operator-=; using parent::operator*=; using parent::operator/=; - using parent::Zero; using parent::Constant; - using parent::Random; using parent::Identity; - using parent::setZero; - using parent::setConstant; - using parent::setRandom; - using parent::setIdentity; - using parent::outerStride; using parent::innerStride; + using parent::outerStride; + using parent::Random; + using parent::setConstant; + using parent::setIdentity; + using parent::setRandom; + using parent::setZero; + using parent::Zero; using parent::operator=; using stride_type = typename parent::stride_type; parent const& base() const { return static_cast(*this); } - parent& base() { return static_cast(*this); } + + parent& base() { return static_cast(*this); } template S, int R, int C, int O, int MR, int MC> ref(matrix& m) : parent(m.data(), m.rows(), m.cols(), strides(m)) - {} + { + } template - requires(std::same_as && (Ref::storage_order & 1) == storage_order) - ref(block&& b) : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + requires(std::same_as && + (Ref::storage_order & 1) == storage_order) + ref(block&& b) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } template - requires(std::same_as && (Ref::storage_order & 1) == storage_order) - ref(block& b) : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + requires(std::same_as && + (Ref::storage_order & 1) == storage_order) + ref(block& b) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } template - requires(std::same_as && (Ref::storage_order & 1) == storage_order) - ref(map& b) : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + requires(std::same_as && + (Ref::storage_order & 1) == storage_order) + ref(map& b) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } template - ref ( ref& b ) - requires(std::same_as && (TT::storage_order & 1) == storage_order) - : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + ref(ref& b) + requires(std::same_as && + (TT::storage_order & 1) == storage_order) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } ref(parent& m) : parent(m.data(), m.rows(), m.cols()) {} @@ -112,59 +137,59 @@ namespace rotgen friend std::ostream& operator<<(std::ostream& os, format const& r) { - return os << format{r.matrix_.base(),r.format_}; + return os << format{r.matrix_.base(), r.format_}; } }; // Specialization for const matrix type template - class ref : private map + class ref : private map { - public: - using parent = map; - using value_type = typename T::value_type; - using rotgen_tag = void; - using rotgen_ref_tag = void; + public: + using parent = map; + using value_type = typename T::value_type; + using rotgen_tag = void; + using rotgen_ref_tag = void; - static constexpr int storage_order = T::storage_order; - static constexpr int RowsAtCompileTime = T::RowsAtCompileTime; - static constexpr int ColsAtCompileTime = T::ColsAtCompileTime; + static constexpr int storage_order = T::storage_order; + static constexpr int RowsAtCompileTime = T::RowsAtCompileTime; + static constexpr int ColsAtCompileTime = T::ColsAtCompileTime; static constexpr bool IsVectorAtCompileTime = T::IsVectorAtCompileTime; - static constexpr bool is_immutable = T::is_immutable; + static constexpr bool is_immutable = T::is_immutable; using parent::evaluate; using parent::noalias; using parent::operator(); using parent::operator[]; - using parent::rows; using parent::cols; - using parent::size; - using parent::data; - using parent::sum; - using parent::prod; - using parent::mean; - using parent::trace; - using parent::transpose; using parent::cwiseAbs; using parent::cwiseAbs2; using parent::cwiseInverse; using parent::cwiseSqrt; + using parent::data; + using parent::lpNorm; using parent::maxCoeff; + using parent::mean; using parent::minCoeff; using parent::norm; using parent::normalize; + using parent::prod; + using parent::rows; + using parent::size; using parent::squaredNorm; - using parent::lpNorm; + using parent::sum; + using parent::trace; + using parent::transpose; using parent::operator+=; using parent::operator-=; using parent::operator*=; using parent::operator/=; - using parent::Zero; using parent::Constant; - using parent::Random; using parent::Identity; - using parent::outerStride; using parent::innerStride; + using parent::outerStride; + using parent::Random; + using parent::Zero; using parent::operator=; @@ -176,25 +201,41 @@ namespace rotgen template S, int R, int C, int O, int MR, int MC> ref(matrix const& m) : parent(m.data(), m.rows(), m.cols(), strides(m)) - {} + { + } template - ref ( block const& b ) - requires(std::same_as && (Ref::storage_order & 1) == storage_order) - : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + ref(block const& b) + requires(std::same_as && + (Ref::storage_order & 1) == storage_order) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } template - ref ( map const& b ) - requires(std::same_as && (Ref::storage_order & 1) == storage_order) - : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + ref(map const& b) + requires(std::same_as && + (Ref::storage_order & 1) == storage_order) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } template - ref ( ref const& b ) - requires(std::same_as && (TT::storage_order & 1) == storage_order) - : parent(b.data(), b.rows(), b.cols(), stride_type{b.outerStride(),b.innerStride()}) - {} + ref(ref const& b) + requires(std::same_as && + (TT::storage_order & 1) == storage_order) + : parent(b.data(), + b.rows(), + b.cols(), + stride_type{b.outerStride(), b.innerStride()}) + { + } ref(parent const& m) : parent(m.data(), m.rows(), m.cols()) {} @@ -205,7 +246,7 @@ namespace rotgen friend std::ostream& operator<<(std::ostream& os, format const& r) { - return os << format{r.matrix_.base(),r.format_}; + return os << format{r.matrix_.base(), r.format_}; } }; @@ -213,166 +254,186 @@ namespace rotgen ref(matrix&) -> ref>; template - ref(block& b) -> ref; + ref(block& b) -> ref; template ref(matrix const&) -> ref const>; template - ref(block const& b) -> ref; + ref(block const& b) -> ref; template - bool operator==(ref lhs, ref rhs) + bool operator==(ref lhs, ref rhs) { return lhs.base() == rhs.base(); } template - bool operator!=(ref lhs, ref rhs) + bool operator!=(ref lhs, ref rhs) { return lhs.base() != rhs.base(); } template - auto operator+(ref lhs, ref rhs) -> decltype(lhs.base() + rhs.base()) + auto operator+(ref lhs, ref rhs) + -> decltype(lhs.base() + rhs.base()) { return lhs.base() + rhs.base(); } template - auto operator+=(ref lhs, ref rhs) -> decltype(lhs.base() += rhs.base()) + auto operator+=(ref lhs, ref rhs) + -> decltype(lhs.base() += rhs.base()) { return lhs.base() += rhs.base(); } template - auto operator-(ref lhs, ref rhs) + auto operator-(ref lhs, ref rhs) { return lhs.base() - rhs.base(); } template - auto operator-=(ref lhs, ref rhs) -> decltype(lhs.base() -= rhs.base()) + auto operator-=(ref lhs, ref rhs) + -> decltype(lhs.base() -= rhs.base()) { return lhs.base() -= rhs.base(); } template - auto operator*(ref lhs, ref rhs) + auto operator*(ref lhs, ref rhs) { return lhs.base() * rhs.base(); } template - auto operator*=(ref lhs, ref rhs) -> decltype(lhs.base() *= rhs.base()) + auto operator*=(ref lhs, ref rhs) + -> decltype(lhs.base() *= rhs.base()) { return lhs.base() *= rhs.base(); } template - auto operator*(ref lhs, std::convertible_to auto s) + auto operator*(ref lhs, + std::convertible_to auto s) { return lhs.base() * s; } template - auto operator*(std::convertible_to auto s, ref rhs) + auto operator*(std::convertible_to auto s, + ref rhs) { return s * rhs.base(); } template - auto operator/(ref lhs, std::convertible_to auto s) + auto operator/(ref lhs, + std::convertible_to auto s) { return lhs.base() / s; } template - auto dot(ref lhs, ref rhs) + auto dot(ref lhs, ref rhs) { return lhs.base().dot(rhs.base()); } template - auto min(ref lhs, ref rhs) -> decltype(lhs.base().cwiseMin(rhs.base())) + auto min(ref lhs, ref rhs) + -> decltype(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)) + auto min(ref lhs, std::convertible_to auto s) + -> decltype(lhs.base().cwiseMin(s)) { return lhs.base().cwiseMin(s); } template - auto min(std::convertible_to auto s,ref rhs) -> decltype(rhs.base().cwiseMin(s)) + auto min(std::convertible_to auto s, ref rhs) + -> decltype(rhs.base().cwiseMin(s)) { return rhs.base().cwiseMin(s); } template - auto max(ref lhs, ref rhs) -> decltype(lhs.base().cwiseMax(rhs.base())) + auto max(ref lhs, ref rhs) + -> decltype(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)) + auto max(ref lhs, std::convertible_to auto s) + -> decltype(lhs.base().cwiseMax(s)) { return lhs.base().cwiseMax(s); } template - auto max(std::convertible_to auto s,ref rhs) -> decltype(rhs.base().cwiseMax(s)) + auto max(std::convertible_to auto s, ref rhs) + -> decltype(rhs.base().cwiseMax(s)) { return rhs.base().cwiseMax(s); } template - auto mul(ref lhs, ref rhs) -> decltype(lhs.base().cwiseProduct(rhs.base())) + auto mul(ref lhs, ref rhs) + -> decltype(lhs.base().cwiseProduct(rhs.base())) { return lhs.base().cwiseProduct(rhs.base()); } template - auto mul(ref lhs, std::convertible_to auto s) -> decltype(lhs * 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 rhs) -> decltype(s * rhs) + auto mul(std::convertible_to auto s, ref rhs) + -> decltype(s * rhs) { return s * rhs; } template - auto div(ref lhs, ref rhs) -> decltype(lhs.base().cwiseQuotient(rhs.base())) + auto div(ref lhs, ref rhs) + -> decltype(lhs.base().cwiseQuotient(rhs.base())) { return lhs.base().cwiseQuotient(rhs.base()); } template - auto div(ref lhs, std::convertible_to auto s) -> decltype(lhs / s) + auto div(ref lhs, std::convertible_to auto s) + -> decltype(lhs / s) { return lhs / s; } template - auto inverse(ref lhs) -> decltype(lhs.base().inverse()) + auto inverse(ref lhs) -> decltype(lhs.base().inverse()) { return lhs.base().inverse(); } template - auto cross(ref lhs, ref rhs) -> decltype(lhs.base().cross(rhs.base())) + auto cross(ref lhs, ref rhs) + -> decltype(lhs.base().cross(rhs.base())) { return lhs.base().cross(rhs.base()); } //------------------------------------------------------------------------------------------- - // Convert entity/eigen types to a proper ref so we can write less function overloads + // Convert entity/eigen types to a proper ref so we can write less function + // overloads template struct generalize; template @@ -382,42 +443,41 @@ namespace rotgen using type = std::remove_cvref_t; }; - template - using generalize_t = typename generalize::type; + template using generalize_t = typename generalize::type; template struct generalize { static constexpr bool is_const = std::is_const_v; - using base = matrix; - using type = std::conditional_t, ref>; + using base = matrix; + using type = std::conditional_t, ref>; }; - template - struct generalize> + template struct generalize> { - using type = ref; + using type = ref; }; - template - struct generalize const> + template struct generalize const> { - using type = ref; + using type = ref; }; - template - typename T::parent& base_of(T& a) + template typename T::parent& base_of(T& a) { return a.base(); } - template - typename T::parent const& base_of(T const& a) + template typename T::parent const& base_of(T const& a) { return a.base(); } template - T base_of(T a) requires(std::is_arithmetic_v) + T base_of(T a) + requires(std::is_arithmetic_v) { return a; } @@ -427,18 +487,19 @@ namespace rotgen { static constexpr bool is_const = std::is_const_v; using concrete_type = decltype(std::declval().eval()); - using base = matrix; - using type = std::conditional_t, ref>; + using base = matrix; + using type = std::conditional_t, ref>; }; - template - auto const& base_of(T const& a) + template auto const& base_of(T const& a) { return a; } - template - auto& base_of(T& a) + template auto& base_of(T& a) { return a; } diff --git a/include/rotgen/container/strides.hpp b/include/rotgen/container/strides.hpp index 5d2779f..f861794 100644 --- a/include/rotgen/container/strides.hpp +++ b/include/rotgen/container/strides.hpp @@ -16,65 +16,66 @@ namespace rotgen { #if !defined(ROTGEN_FORCE_DYNAMIC) - using stride = Eigen::Stride<-1,-1>; + using stride = Eigen::Stride<-1, -1>; #else struct stride { static constexpr bool is_dynamic = true; stride() : outer_(-1), inner_(1) {} - stride(Index s, Index i) : outer_(s), inner_(i) {} + + stride(Index s, Index i) : outer_(s), inner_(i) {} Index inner() const { return inner_; } + Index outer() const { return outer_; } - private: + private: Index outer_; Index inner_; }; #endif - template - struct inner_stride : stride + template struct inner_stride : stride { static constexpr bool is_dynamic = Value == Dynamic; - inner_stride() : stride(-1,Value) {} + + inner_stride() : stride(-1, Value) {} + inner_stride(Index v) : stride(0, v) {} }; - template - struct outer_stride : stride + template struct outer_stride : stride { static constexpr bool is_dynamic = Value == Dynamic; - outer_stride() : stride(Value,0) {} - outer_stride(Index v) : stride(v,0) {} + + outer_stride() : stride(Value, 0) {} + + outer_stride(Index v) : stride(v, 0) {} }; inner_stride(Index) -> inner_stride; outer_stride(Index) -> outer_stride; - template - stride strides(Index r, Index c) + template stride strides(Index r, Index c) { - if constexpr (Order == RowMajor) return {c,1}; - else return {r,1}; + if constexpr (Order == RowMajor) return {c, 1}; + else return {r, 1}; } - template - stride strides(stride const& original,Index, Index) + template stride strides(stride const& original, Index, Index) { return original; } template - stride strides(outer_stride const& original,Index r, Index c) + stride strides(outer_stride const& original, Index r, Index c) { - if constexpr(N==0) return stride{ Order==ColMajor ? r : c, 1}; - else return {original.outer(),1}; + if constexpr (N == 0) return stride{Order == ColMajor ? r : c, 1}; + else return {original.outer(), 1}; } - template - auto strides(const E& e) + template auto strides(E const& e) { return strides(e.rows(), e.cols()); } diff --git a/include/rotgen/detail/export.hpp b/include/rotgen/detail/export.hpp index 9dce182..b847361 100644 --- a/include/rotgen/detail/export.hpp +++ b/include/rotgen/detail/export.hpp @@ -8,33 +8,32 @@ #pragma once #ifdef ROTGEN_STATIC_DEFINE -# define ROTGEN_EXPORT -# define ROTGEN_NO_EXPORT +#define ROTGEN_EXPORT +#define ROTGEN_NO_EXPORT #else -# ifndef ROTGEN_EXPORT -# ifdef rotgen_EXPORTS - /* We are building this library */ -# define ROTGEN_EXPORT __attribute__((visibility("default"))) -# else - /* We are using this library */ -# define ROTGEN_EXPORT __attribute__((visibility("default"))) -# endif -# endif +#ifndef ROTGEN_EXPORT +#ifdef rotgen_EXPORTS +/* We are building this library */ +#define ROTGEN_EXPORT __attribute__((visibility("default"))) +#else +/* We are using this library */ +#define ROTGEN_EXPORT __attribute__((visibility("default"))) +#endif +#endif -# ifndef ROTGEN_NO_EXPORT -# define ROTGEN_NO_EXPORT __attribute__((visibility("hidden"))) -# endif +#ifndef ROTGEN_NO_EXPORT +#define ROTGEN_NO_EXPORT __attribute__((visibility("hidden"))) +#endif #endif #ifndef ROTGEN_DEPRECATED -# define ROTGEN_DEPRECATED __attribute__ ((__deprecated__)) +#define ROTGEN_DEPRECATED __attribute__((__deprecated__)) #endif #ifndef ROTGEN_DEPRECATED_EXPORT -# define ROTGEN_DEPRECATED_EXPORT ROTGEN_EXPORT ROTGEN_DEPRECATED +#define ROTGEN_DEPRECATED_EXPORT ROTGEN_EXPORT ROTGEN_DEPRECATED #endif #ifndef ROTGEN_DEPRECATED_NO_EXPORT -# define ROTGEN_DEPRECATED_NO_EXPORT ROTGEN_NO_EXPORT ROTGEN_DEPRECATED +#define ROTGEN_DEPRECATED_NO_EXPORT ROTGEN_NO_EXPORT ROTGEN_DEPRECATED #endif - diff --git a/include/rotgen/detail/generators.hpp b/include/rotgen/detail/generators.hpp index 049a249..5639e3f 100644 --- a/include/rotgen/detail/generators.hpp +++ b/include/rotgen/detail/generators.hpp @@ -7,6 +7,7 @@ //================================================================================================== #pragma once -#define ROTGEN_CAT(a, ...) ROTGEN_PRIMITIVE_CAT(a, __VA_ARGS__) -#define ROTGEN_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ -#define ROTGEN_MATRIX_NAME(BASE,ID,SUFFIX) ROTGEN_CAT(BASE,ROTGEN_CAT(ID,SUFFIX)) +#define ROTGEN_CAT(a, ...) ROTGEN_PRIMITIVE_CAT(a, __VA_ARGS__) +#define ROTGEN_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ +#define ROTGEN_MATRIX_NAME(BASE, ID, SUFFIX) \ + ROTGEN_CAT(BASE, ROTGEN_CAT(ID, SUFFIX)) diff --git a/include/rotgen/detail/helpers.hpp b/include/rotgen/detail/helpers.hpp index 6b7e8a7..2055f84 100644 --- a/include/rotgen/detail/helpers.hpp +++ b/include/rotgen/detail/helpers.hpp @@ -9,50 +9,55 @@ namespace rotgen::detail { - template< typename EigenType - , template typename Wrapper - > + template typename Wrapper> struct as_concrete { - using type = Wrapper< typename EigenType::value_type - , EigenType::RowsAtCompileTime, EigenType::ColsAtCompileTime - , EigenType::Flags & 1 - , EigenType::MaxRowsAtCompileTime, EigenType::MaxColsAtCompileTime - >; + using type = Wrapper; }; - template typename Wrapper - > - using as_concrete_t = typename as_concrete,Wrapper>::type; + template typename Wrapper> + using as_concrete_t = + typename as_concrete, Wrapper>::type; template - inline constexpr bool has_same_vector_size = []() - { + inline constexpr bool has_same_vector_size = []() { // No vector = noo size - if(!(M::IsVectorAtCompileTime && N::IsVectorAtCompileTime)) return false; + if (!(M::IsVectorAtCompileTime && N::IsVectorAtCompileTime)) return false; // Row vectors -> same Cols - if(M::RowsAtCompileTime == 1 && N::RowsAtCompileTime == 1) return M::ColsAtCompileTime == N::ColsAtCompileTime; + if (M::RowsAtCompileTime == 1 && N::RowsAtCompileTime == 1) + return M::ColsAtCompileTime == N::ColsAtCompileTime; // Col vectors -> same Rows - if(M::ColsAtCompileTime == 1 && N::ColsAtCompileTime == 1) return M::RowsAtCompileTime == N::RowsAtCompileTime; + if (M::ColsAtCompileTime == 1 && N::ColsAtCompileTime == 1) + return M::RowsAtCompileTime == N::RowsAtCompileTime; // Mixing 1xN with Mx1 return false; }(); template - using propagate_const = std::conditional_t, std::add_const_t, T>; + using propagate_const = + std::conditional_t, + std::add_const_t, + T>; template - inline constexpr auto select_static = (M==rotgen::Dynamic || N==rotgen::Dynamic) ? rotgen::Dynamic : M; + inline constexpr auto select_static = + (M == rotgen::Dynamic || N == rotgen::Dynamic) ? rotgen::Dynamic : M; - 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 + template typename Wrapper> + using composite_type = + Wrapper, + select_static, + M1::storage_order, + select_static, + select_static>; +} diff --git a/include/rotgen/detail/payload.hpp b/include/rotgen/detail/payload.hpp index 54a66a2..7d80f17 100644 --- a/include/rotgen/detail/payload.hpp +++ b/include/rotgen/detail/payload.hpp @@ -21,180 +21,264 @@ namespace rotgen //================================================================================================== struct matrix_impl64_col::payload { - using data_type = Eigen::Matrix; + using data_type = + Eigen::Matrix; data_type data; - payload(std::size_t r=0, std::size_t c=0) : data(r, c) {} - payload(std::initializer_list> init) : data(init) {} + + payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + + payload(std::initializer_list> init) + : data(init) + { + } + payload(data_type&& matrix) : data(std::move(matrix)) {} void assign(Eigen::Block ref) { data = ref; } + void assign(data_type const& mat) { data = mat; } + void assign(data_type&& mat) { data = std::move(mat); } }; struct matrix_impl64_row::payload { - using data_type = Eigen::Matrix; + using data_type = + Eigen::Matrix; data_type data; - payload(std::size_t r=0, std::size_t c=0) : data(r, c) {} - payload(std::initializer_list> init) : data(init) {} + + payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + + payload(std::initializer_list> init) + : data(init) + { + } + payload(data_type&& matrix) : data(std::move(matrix)) {} void assign(Eigen::Block ref) { data = ref; } + void assign(data_type const& mat) { data = mat; } + void assign(data_type&& mat) { data = std::move(mat); } }; struct matrix_impl32_col::payload { - using data_type = Eigen::Matrix; + using data_type = + Eigen::Matrix; data_type data; - payload(std::size_t r=0, std::size_t c=0) : data(r, c) {} - payload(std::initializer_list> init) : data(init) {} + + payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + + payload(std::initializer_list> init) + : data(init) + { + } + payload(data_type&& matrix) : data(std::move(matrix)) {} void assign(Eigen::Block ref) { data = ref; } + void assign(data_type const& mat) { data = mat; } + void assign(data_type&& mat) { data = std::move(mat); } }; struct matrix_impl32_row::payload { - using data_type = Eigen::Matrix; + using data_type = + Eigen::Matrix; data_type data; - payload(std::size_t r=0, std::size_t c=0) : data(r, c) {} - payload(std::initializer_list> init) : data(init) {} + + payload(std::size_t r = 0, std::size_t c = 0) : data(r, c) {} + + payload(std::initializer_list> init) + : data(init) + { + } + payload(data_type&& matrix) : data(std::move(matrix)) {} void assign(Eigen::Block ref) { data = ref; } + void assign(data_type const& mat) { data = mat; } + void assign(data_type&& mat) { data = std::move(mat); } }; //================================================================================================== - // Internal payload - Required for cross-referencing from mixed order on map operators + // Internal payload - Required for cross-referencing from mixed order on map + // operators //================================================================================================== struct map_const_impl32_col::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = + Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (float const* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (float const* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(float const* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(float const* ptr, Index r, Index c, stride_type s) + : data(ptr, r, c, s) + { + } }; struct map_const_impl32_row::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = + Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (float const* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (float const* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(float const* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(float const* ptr, Index r, Index c, stride_type s) + : data(ptr, r, c, s) + { + } }; struct map_impl32_col::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (float* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (float* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(float* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(float* ptr, Index r, Index c, stride_type s) : data(ptr, r, c, s) {} }; struct map_impl32_row::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (float* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (float* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} - }; + payload(data_type const& o) : data(o) {} + payload(float* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(float* ptr, Index r, Index c, stride_type s) : data(ptr, r, c, s) {} + }; struct map_const_impl64_col::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = + Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (double const* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (double const* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(double const* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(double const* ptr, Index r, Index c, stride_type s) + : data(ptr, r, c, s) + { + } }; struct map_const_impl64_row::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = + Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (double const* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (double const* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(double const* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(double const* ptr, Index r, Index c, stride_type s) + : data(ptr, r, c, s) + { + } }; struct map_impl64_col::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (double* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (double* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(double* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(double* ptr, Index r, Index c, stride_type s) : data(ptr, r, c, s) + { + } }; struct map_impl64_row::payload { - using stride_type = Eigen::Stride; - using base_type = Eigen::Matrix; - using data_type = Eigen::Map; + using stride_type = Eigen::Stride; + using base_type = + Eigen::Matrix; + using data_type = Eigen::Map; data_type data; - payload (data_type const& o) : data(o) {} - payload (double* ptr, Index r, Index c) : data(ptr,r,c) {} - payload (double* ptr, Index r, Index c, stride_type s) : data(ptr,r,c,s) {} + payload(data_type const& o) : data(o) {} + + payload(double* ptr, Index r, Index c) : data(ptr, r, c) {} + + payload(double* ptr, Index r, Index c, stride_type s) : data(ptr, r, c, s) + { + } }; // - struct ioformat::payload + struct ioformat::payload { Eigen::IOFormat instance; - payload ( int p, int f - , std::string const& cs, std::string const& rsp - , std::string const& rp, std::string const& rs - , std::string const& mp, std::string const& ms - , char fill - ) - : instance(p,f,cs,rsp,rp,rs,mp,ms,fill) - {} + payload(int p, + int f, + std::string const& cs, + std::string const& rsp, + std::string const& rp, + std::string const& rs, + std::string const& mp, + std::string const& ms, + char fill) + : instance(p, f, cs, rsp, rp, rs, mp, ms, fill) + { + } }; } diff --git a/include/rotgen/detail/spy.hpp b/include/rotgen/detail/spy.hpp index 67a8617..f63c160 100644 --- a/include/rotgen/detail/spy.hpp +++ b/include/rotgen/detail/spy.hpp @@ -7,6 +7,7 @@ //====================================================================================================================== #ifndef SPY_SPY_HPP_INCLUDED #define SPY_SPY_HPP_INCLUDED + //====================================================================================================================== //! @namespace spy //! @brief Main SPY namespace @@ -23,6 +24,7 @@ namespace spy namespace supports { } + //==================================================================================================================== //! @namespace literal //! @brief SPY User-defined literal namespace @@ -31,7 +33,9 @@ namespace spy { } } + #include + namespace spy::_ { template @@ -40,6 +44,7 @@ namespace spy::_ { os.flush() }; { os.put(c) }; }; + template constexpr int find(int i0) { int sz = sizeof...(c); @@ -47,6 +52,7 @@ namespace spy::_ while (i0 < sz && arr[i0] != '\'') ++i0; return i0; } + template constexpr int parse(int i0, int i1) { char arr[] = {c...}; @@ -54,66 +60,87 @@ namespace spy::_ while (i0 < i1 && arr[i0] != '\'') value = value * 10 + (arr[i0++] - 48); return value; } - template class Wrapper, char... c> constexpr auto literal_wrap() + + template class Wrapper, char... c> + constexpr auto literal_wrap() { constexpr int b0 = 0, e0 = find(0); constexpr int b1 = e0 + 1, e1 = find(b1); constexpr int b2 = e1 + 1, e2 = sizeof...(c); - return Wrapper(b0, e0), parse(b1, e1), parse(b2, e2)>{}; + return Wrapper(b0, e0), parse(b1, e1), + parse(b2, e2)>{}; } + template struct version_id { static constexpr int major = M; static constexpr int minor = N; static constexpr int patch = P; }; + template - constexpr bool operator==(version_id, version_id) noexcept + constexpr bool operator==(version_id, + version_id) noexcept { return (M1 == M2) && (N1 == N2) && (P1 == P2); } + template - constexpr std::strong_ordering operator<=>(version_id, version_id) noexcept + constexpr std::strong_ordering operator<=>(version_id, + version_id) noexcept { if constexpr (constexpr auto cmp0 = M1 <=> M2; cmp0 != 0) return cmp0; else if constexpr (constexpr auto cmp1 = N1 <=> N2; cmp1 != 0) return cmp1; else return P1 <=> P2; } - template constexpr inline version_id version = {}; + + template + constexpr inline version_id version = {}; using unspecified_version_t = version_id<-1, 0, 0>; constexpr inline unspecified_version_t unspecified_version = {}; - template<_::stream OS, int M, int N, int P> auto& operator<<(OS& os, version_id const&) + + template<_::stream OS, int M, int N, int P> + auto& operator<<(OS& os, version_id const&) { return os << "v" << M << "." << N << "." << P; } + template<_::stream OS> auto& operator<<(OS& os, unspecified_version_t const&) { return os << "(unspecified)"; } } + namespace spy::supports { template struct sycl_t { explicit constexpr operator bool() const noexcept { return M > 0 && N > 0; } + template<_::stream OS> friend auto& operator<<(OS& os, sycl_t) { os << "SYCL v" << M << '.' << N; if (P > 0) os << '.' << P; return os; } - template constexpr inline bool operator==(sycl_t const&) const noexcept + + template + constexpr inline bool operator==(sycl_t const&) const noexcept { return M == M1 && N == N1 && P == P1; } }; + template struct cuda_t { explicit constexpr operator bool() const noexcept { return M > 0 && N > 0; } - template constexpr inline bool operator==(cuda_t const&) const noexcept + + template + constexpr inline bool operator==(cuda_t const&) const noexcept { return M == M1 && N == N1 && P == P1; } + template<_::stream OS> friend auto& operator<<(OS& os, cuda_t) { #if defined(__NVCC__) @@ -128,7 +155,8 @@ namespace spy::supports }; #if defined(SYCL_LANGUAGE_VERSION) && defined(__INTEL_LLVM_COMPILER) #define SPY_ACCELERATOR_SUPPORTS_SYCL - constexpr inline auto sycl = sycl_t{}; + constexpr inline auto sycl = + sycl_t{}; #elif defined(SPY_DOXYGEN_INVOKED) constexpr inline auto sycl = **implementation - defined * *; #else @@ -137,10 +165,13 @@ namespace spy::supports #if defined(__CUDACC__) #if defined(__CUDACC_VER_MAJOR__) #define SPY_ACCELERATOR_SUPPORTS_CUDA - constexpr inline auto cuda = cuda_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>{}; + constexpr inline auto cuda = + cuda_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>{}; #elif defined(CUDA_VERSION) #define SPY_ACCELERATOR_SUPPORTS_CUDA - constexpr inline auto cuda = cuda_t{}; + constexpr inline auto cuda = cuda_t{}; #endif #elif defined(SPY_DOXYGEN_INVOKED) constexpr inline auto cuda = **implementation - defined * *; @@ -148,6 +179,7 @@ namespace spy::supports constexpr inline auto cuda = cuda_t<-1, -1, -1>{}; #endif } + namespace spy::_ { enum class archs @@ -160,11 +192,18 @@ namespace spy::_ wasm_ = 40, riscv_ = 50 }; + template struct arch_info { static constexpr archs vendor = Arch; inline constexpr explicit operator bool() const noexcept; - template constexpr bool operator==(arch_info const&) const noexcept { return A2 == vendor; } + + template + constexpr bool operator==(arch_info const&) const noexcept + { + return A2 == vendor; + } + template<_::stream OS> friend auto& operator<<(OS& os, arch_info const&) { if (Arch == archs::x86_) return os << "X86"; @@ -177,22 +216,27 @@ namespace spy::_ } }; } + namespace spy { -#if defined(i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \ - defined(__i386) || defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || \ - defined(__INTEL__) +#if defined(i386) || defined(__i386__) || defined(__i486__) || \ + defined(__i586__) || defined(__i686__) || defined(__i386) || \ + defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL__) || \ + defined(__I86__) || defined(__INTEL__) using arch_type = _::arch_info<_::archs::x86_>; #define SPY_ARCH_IS_X86 -#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(__amd64) || defined(_M_X64) +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || \ + defined(__amd64) || defined(_M_X64) #define SPY_ARCH_IS_AMD64 using arch_type = _::arch_info<_::archs::amd64_>; -#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(_M_PPC) || \ - defined(_ARCH_PPC) || defined(__PPCGECKO__) || defined(__PPCBROADWAY__) || defined(_XENON) +#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || \ + defined(__ppc__) || defined(_M_PPC) || defined(_ARCH_PPC) || \ + defined(__PPCGECKO__) || defined(__PPCBROADWAY__) || defined(_XENON) using arch_type = _::arch_info<_::archs::ppc_>; #define SPY_ARCH_IS_PPC -#elif defined(__arm__) || defined(__arm64) || defined(__thumb__) || defined(__TARGET_ARCH_ARM) || \ - defined(__TARGET_ARCH_THUMB) || defined(_M_ARM) || defined(__ARM_ARCH_ISA_A64) +#elif defined(__arm__) || defined(__arm64) || defined(__thumb__) || \ + defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB) || \ + defined(_M_ARM) || defined(__ARM_ARCH_ISA_A64) using arch_type = _::arch_info<_::archs::arm_>; #define SPY_ARCH_IS_ARM #elif defined(__wasm__) @@ -207,13 +251,16 @@ namespace spy #endif constexpr inline arch_type architecture; } + namespace spy::_ { - template inline constexpr arch_info::operator bool() const noexcept + template + inline constexpr arch_info::operator bool() const noexcept { return spy::architecture == *this; } } + namespace spy { constexpr inline auto x86_ = _::arch_info<_::archs::x86_>{}; @@ -223,6 +270,7 @@ namespace spy constexpr inline auto wasm_ = _::arch_info<_::archs::wasm_>{}; constexpr inline auto riscv_ = _::arch_info<_::archs::riscv_>{}; } + #include #if defined __has_include #if __has_include() @@ -242,71 +290,102 @@ namespace spy::_ dpcpp_, nvcc_ }; + template struct compilers_info { static constexpr compilers vendor = Compiler; static constexpr version_id version = {}; inline constexpr explicit operator bool() const noexcept; - template constexpr bool operator==(compilers_info const&) const noexcept + + template + constexpr bool operator==( + compilers_info const&) const noexcept { return C2 == vendor; } + template - constexpr bool operator==(compilers_info const& c2) const noexcept + constexpr bool operator==( + compilers_info const& c2) const noexcept { return C2 == vendor && version == c2.version; } + template - constexpr std::partial_ordering operator<=>(compilers_info const& c2) const noexcept + constexpr std::partial_ordering operator<=>( + compilers_info const& c2) const noexcept { if constexpr (vendor == C2) return version <=> c2.version; else return std::partial_ordering::unordered; } }; - template<_::stream OS, compilers C, int M, int N, int P> auto& operator<<(OS& os, compilers_info const& c) + + template<_::stream OS, compilers C, int M, int N, int P> + auto& operator<<(OS& os, compilers_info const& c) { - if (C == compilers::nvcc_) return os << "NVIDIA CUDA Compiler " << c.version; - if (C == compilers::msvc_) return os << "Microsoft Visual Studio " << c.version; - if (C == compilers::intel_) return os << "Intel(R) C++ Compiler " << c.version; - if (C == compilers::dpcpp_) return os << "Intel(R) oneAPI DPC++/C++ Compiler " << c.version; + if (C == compilers::nvcc_) + return os << "NVIDIA CUDA Compiler " << c.version; + if (C == compilers::msvc_) + return os << "Microsoft Visual Studio " << c.version; + if (C == compilers::intel_) + return os << "Intel(R) C++ Compiler " << c.version; + if (C == compilers::dpcpp_) + return os << "Intel(R) oneAPI DPC++/C++ Compiler " << c.version; if (C == compilers::clang_) return os << "clang " << c.version; if (C == compilers::gcc_) return os << "g++ " << c.version; if (C == compilers::emscripten_) return os << "Emscripten " << c.version; return os << "Undefined " << c.version; } - template using msvc_t = compilers_info; - template using intel_t = compilers_info; - template using dpcpp_t = compilers_info; - template using nvcc_t = compilers_info; - template using clang_t = compilers_info; - template using gcc_t = compilers_info; - template using emscripten_t = compilers_info; + + template + using msvc_t = compilers_info; + template + using intel_t = compilers_info; + template + using dpcpp_t = compilers_info; + template + using nvcc_t = compilers_info; + template + using clang_t = compilers_info; + template + using gcc_t = compilers_info; + template + using emscripten_t = compilers_info; } + namespace spy { #if defined(__NVCC__) #define SPY_COMPILER_IS_NVCC - using compiler_type = _::nvcc_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>; + using compiler_type = + _::nvcc_t<__CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, 0>; #elif defined(_MSC_VER) #define SPY_COMPILER_IS_MSVC - using compiler_type = _::msvc_t<_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 100000>; + using compiler_type = + _::msvc_t<_MSC_VER / 100, _MSC_VER % 100, _MSC_FULL_VER % 100000>; #elif defined(__INTEL_LLVM_COMPILER) #define SPY_COMPILER_IS_INTEL_DPCPP #define SPY0 __INTEL_LLVM_COMPILER - using compiler_type = _::dpcpp_t; + using compiler_type = + _::dpcpp_t; #undef SPY0 -#elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) +#elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || \ + defined(__ECC) #define SPY_COMPILER_IS_INTEL #define SPY0 __INTEL_COMPILER - using compiler_type = _::intel_t<(SPY0 / 100) % 100, SPY0 % 100, __INTEL_COMPILER_UPDATE>; + using compiler_type = + _::intel_t<(SPY0 / 100) % 100, SPY0 % 100, __INTEL_COMPILER_UPDATE>; #undef SPY0 #elif defined(__EMSCRIPTEN__) #define SPY_COMPILER_IS_CLANG - using compiler_type = _::emscripten_t<__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__>; + using compiler_type = _::emscripten_t<__EMSCRIPTEN_major__, + __EMSCRIPTEN_minor__, + __EMSCRIPTEN_tiny__>; #undef SPY0 #elif defined(__clang__) #define SPY_COMPILER_IS_CLANG - using compiler_type = _::clang_t<__clang_major__, __clang_minor__, __clang_patchlevel__>; + using compiler_type = + _::clang_t<__clang_major__, __clang_minor__, __clang_patchlevel__>; #elif defined(__GNUC__) #define SPY_COMPILER_IS_GCC using compiler_type = _::gcc_t<__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__>; @@ -316,13 +395,16 @@ namespace spy #endif constexpr inline compiler_type compiler; } + namespace spy::_ { - template inline constexpr compilers_info::operator bool() const noexcept + template + inline constexpr compilers_info::operator bool() const noexcept { return spy::compiler == *this; } } + namespace spy { constexpr inline auto nvcc_ = _::nvcc_t<-1, 0, 0>{}; @@ -333,73 +415,95 @@ namespace spy constexpr inline auto gcc_ = _::gcc_t<-1, 0, 0>{}; constexpr inline auto emscripten_ = _::emscripten_t<-1, 0, 0>{}; } + namespace spy::literal { template constexpr auto operator""_nvcc() { return _::literal_wrap<_::nvcc_t, c...>(); } + template constexpr auto operator""_msvc() { return _::literal_wrap<_::msvc_t, c...>(); } + template constexpr auto operator""_intel() { return _::literal_wrap<_::intel_t, c...>(); } + template constexpr auto operator""_dpcpp() { return _::literal_wrap<_::dpcpp_t, c...>(); } + template constexpr auto operator""_clang() { return _::literal_wrap<_::clang_t, c...>(); } + template constexpr auto operator""_gcc() { return _::literal_wrap<_::gcc_t, c...>(); } + template constexpr auto operator""_em() { return _::literal_wrap<_::emscripten_t, c...>(); } } + namespace spy::_ { template struct data_model_info { inline constexpr explicit operator bool() const noexcept; + template - constexpr bool operator==(data_model_info const&) const noexcept + constexpr bool operator==( + data_model_info const&) const noexcept { - return (Short == Short2) && (Integer == Integer2) && (Long == Long2) && (Pointer == Pointer2); + return (Short == Short2) && (Integer == Integer2) && (Long == Long2) && + (Pointer == Pointer2); } }; + template<_::stream OS, int Short, int Integer, int Long, int Pointer> - auto& operator<<(OS& os, data_model_info const&) + auto& operator<<(OS& os, + data_model_info const&) { if constexpr (Pointer == 4 && Integer == 4) return os << "ILP32"; else if constexpr (Pointer == 4 && Integer == 2) return os << "LP32"; - else if constexpr (Pointer == 8 && Long == 8 && Integer == 8 && Short == 8) return os << "IntegerLP64"; - else if constexpr (Pointer == 8 && Short == 8 && Integer == 8 && Short == 2) return os << "ILP64"; - else if constexpr (Pointer == 8 && Long == 4 && Integer == 8 && Short == 2) return os << "LLP64"; - else if constexpr (Pointer == 8 && Long == 8 && Integer == 4 && Short == 2) return os << "LP64"; + else if constexpr (Pointer == 8 && Long == 8 && Integer == 8 && Short == 8) + return os << "IntegerLP64"; + else if constexpr (Pointer == 8 && Short == 8 && Integer == 8 && Short == 2) + return os << "ILP64"; + else if constexpr (Pointer == 8 && Long == 4 && Integer == 8 && Short == 2) + return os << "LLP64"; + else if constexpr (Pointer == 8 && Long == 8 && Integer == 4 && Short == 2) + return os << "LP64"; else return os << "Unknown data model"; } } + namespace spy { - using data_model_type = _::data_model_info; + using data_model_type = + _::data_model_info; constexpr inline auto data_model = data_model_type{}; } + namespace spy::_ { template - inline constexpr data_model_info::operator bool() const noexcept + inline constexpr data_model_info:: + operator bool() const noexcept { return spy::data_model == *this; } } + namespace spy { constexpr inline auto ilp32_ = _::data_model_info<2, 4, sizeof(long), 4>{}; @@ -409,8 +513,10 @@ namespace spy constexpr inline auto llp64_ = _::data_model_info<2, 8, 4, 8>{}; constexpr inline auto lp64_ = _::data_model_info<2, 4, 8, 8>{}; } + #include #include + namespace spy::_ { enum class libC @@ -422,39 +528,59 @@ namespace spy::_ zos_, gnu_ }; + template struct libc_info { static constexpr libC vendor = Lib; static constexpr version_id version = {}; inline constexpr explicit operator bool() const noexcept; - template constexpr bool operator==(libc_info const&) const noexcept { return C2 == vendor; } + + template + constexpr bool operator==(libc_info const&) const noexcept + { + return C2 == vendor; + } + template - constexpr bool operator==(libc_info const& c2) const noexcept + constexpr bool operator==( + libc_info const& c2) const noexcept { return C2 == vendor && version == c2.version; } + template - constexpr auto operator<=>(libc_info const& c2) const noexcept + constexpr auto operator<=>( + libc_info const& c2) const noexcept { if constexpr (vendor == C2) return version <=> c2.version; else return vendor <=> C2; } }; - template<_::stream OS, libC C, int M, int N, int P> auto& operator<<(OS& os, libc_info const& c) + + template<_::stream OS, libC C, int M, int N, int P> + auto& operator<<(OS& os, libc_info const& c) { - if (c.vendor == libC::cloudabi_) return os << "CloudABI Standard C Library " << c.version; - if (c.vendor == libC::uc_) return os << "uClibc Standard C Library " << c.version; - if (c.vendor == libC::vms_) return os << "VMS Standard C Library " << c.version; - if (c.vendor == libC::zos_) return os << "z/OS Standard C Library " << c.version; - if (c.vendor == libC::gnu_) return os << "GNU Standard C Library " << c.version; + if (c.vendor == libC::cloudabi_) + return os << "CloudABI Standard C Library " << c.version; + if (c.vendor == libC::uc_) + return os << "uClibc Standard C Library " << c.version; + if (c.vendor == libC::vms_) + return os << "VMS Standard C Library " << c.version; + if (c.vendor == libC::zos_) + return os << "z/OS Standard C Library " << c.version; + if (c.vendor == libC::gnu_) + return os << "GNU Standard C Library " << c.version; return os << "Undefined Standard C Library"; } - template using cloudabi_t = libc_info; + + template + using cloudabi_t = libc_info; template using uc_t = libc_info; template using vms_t = libc_info; template using zos_t = libc_info; template using gnu_t = libc_info; } + namespace spy { #if defined(__cloudlibc__) @@ -468,28 +594,34 @@ namespace spy using libc_type = _::gnu_t<__GNU_LIBRARY__, __GNU_LIBRARY_MINOR__, 0>; #elif defined(__UCLIBC__) #define SPY_LIBC_IS_UCLIBC - using libc_type = _::uc_t<__UCLIBC_MAJOR__, __UCLIBC_MINOR__, __UCLIBC_SUBLEVEL__>; + using libc_type = + _::uc_t<__UCLIBC_MAJOR__, __UCLIBC_MINOR__, __UCLIBC_SUBLEVEL__>; #elif defined(__CRTL_VER) #define SPY_LIBC_IS_VMS #define SPY0 (__CRTL_VER / 100) - using libc_type = _::vms_t<(SPY0 / 100000) % 100, (SPY0 / 1000) % 100, (SPY0) % 100>; + using libc_type = + _::vms_t<(SPY0 / 100000) % 100, (SPY0 / 1000) % 100, (SPY0) % 100>; #undef SPY0 #elif defined(__LIBREL__) #define SPY_LIBC_IS_ZOS - using libc_type = _::zos_t < (__LIBREL__ & 0xF000000) >> 24, (__LIBREL__ & 0xFF0000) >> 16, (__LIBREL__ & 0xFFFF) > ; + using libc_type = _::zos_t < (__LIBREL__ & 0xF000000) >> 24, + (__LIBREL__ & 0xFF0000) >> 16, (__LIBREL__ & 0xFFFF) > ; #else #define SPY_LIBC_IS_UNKNOWN using libc_type = _::libc_info<_::libC::undefined_, -1, 0, 0>; #endif constexpr inline auto libc = libc_type{}; } + namespace spy::_ { - template inline constexpr libc_info::operator bool() const noexcept + template + inline constexpr libc_info::operator bool() const noexcept { return spy::libc == *this; } } + namespace spy { constexpr inline auto cloudabi_ = _::cloudabi_t<-1, 0, 0>{}; @@ -498,24 +630,29 @@ namespace spy constexpr inline auto zos_ = _::zos_t<-1, 0, 0>{}; constexpr inline auto gnu_ = _::gnu_t<-1, 0, 0>{}; } + namespace spy::literal { template constexpr auto operator""_cloud() { return _::literal_wrap<_::cloudabi_t, c...>(); } + template constexpr auto operator""_uc() { return _::literal_wrap<_::uc_t, c...>(); } + template constexpr auto operator""_vms() { return _::literal_wrap<_::vms_t, c...>(); } + template constexpr auto operator""_zos() { return _::literal_wrap<_::zos_t, c...>(); } + template constexpr auto operator""_gnu() { return _::literal_wrap<_::gnu_t, c...>(); @@ -538,13 +675,21 @@ namespace spy::_ unix_, windows_ }; + template struct os_info { static constexpr systems vendor = OpSys; inline constexpr explicit operator bool() const noexcept; - template constexpr bool operator==(os_info const&) const noexcept { return C2 == vendor; } + + template + constexpr bool operator==(os_info const&) const noexcept + { + return C2 == vendor; + } }; - template<_::stream OS, systems OpSys> auto& operator<<(OS& os, os_info const&) + + template<_::stream OS, systems OpSys> + auto& operator<<(OS& os, os_info const&) { if (OpSys == systems::android_) return os << "Android"; if (OpSys == systems::bsd_) return os << "BSD"; @@ -557,6 +702,7 @@ namespace spy::_ return os << "Undefined Operating System"; } } + namespace spy { #if defined(__ANDROID__) @@ -568,19 +714,23 @@ namespace spy #elif defined(__CYGWIN__) #define SPY_OS_IS_CYGWIN using os_type = _::os_info<_::systems::cygwin_>; -#elif defined(__APPLE__) && defined(__MACH__) && defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) +#elif defined(__APPLE__) && defined(__MACH__) && \ + defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) #define SPY_OS_IS_IOS using os_type = _::os_info<_::systems::ios_>; #elif defined(linux) || defined(__linux) #define SPY_OS_IS_LINUX using os_type = _::os_info<_::systems::linux_>; -#elif defined(macintosh) || defined(Macintosh) || (defined(__APPLE__) && defined(__MACH__)) +#elif defined(macintosh) || defined(Macintosh) || \ + (defined(__APPLE__) && defined(__MACH__)) #define SPY_OS_IS_MACOS using os_type = _::os_info<_::systems::macos_>; -#elif defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) +#elif defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || \ + defined(_POSIX_SOURCE) #define SPY_OS_IS_UNIX using os_type = _::os_info<_::systems::unix_>; -#elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) +#elif defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || \ + defined(__TOS_WIN__) || defined(__WINDOWS__) #define SPY_OS_IS_WINDOWS using os_type = _::os_info<_::systems::windows_>; #else @@ -589,13 +739,16 @@ namespace spy #endif constexpr inline os_type operating_system; } + namespace spy::_ { - template inline constexpr os_info::operator bool() const noexcept + template + inline constexpr os_info::operator bool() const noexcept { return spy::operating_system == *this; } } + namespace spy { constexpr inline auto android_ = _::os_info<_::systems::android_>{}; @@ -607,12 +760,14 @@ namespace spy constexpr inline auto unix_ = _::os_info<_::systems::unix_>{}; constexpr inline auto windows_ = _::os_info<_::systems::windows_>{}; } + namespace spy::supports { #if defined(SPY_DOXYGEN_INVOKED) constexpr inline auto posix_ = **implementation specified * *; #else -#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600) +#if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (_POSIX_C_SOURCE >= 200112L) || \ + (_XOPEN_SOURCE >= 600) #define SPY_SUPPORTS_POSIX constexpr inline auto posix_ = true; #else @@ -654,7 +809,8 @@ namespace spy::supports #else constexpr bool thread_sanitizers_status = false; #endif - constexpr bool sanitizers_status = address_sanitizers_status || thread_sanitizers_status; + constexpr bool sanitizers_status = + address_sanitizers_status || thread_sanitizers_status; } #if defined(SPY_COMPILER_IS_CLANG) || defined(SPY_COMPILER_IS_GCC) #define SPY_DISABLE_ADDRESS_SANITIZERS __attribute__((no_sanitize_address)) @@ -666,7 +822,8 @@ namespace spy::supports #define SPY_DISABLE_ADDRESS_SANITIZERS #define SPY_DISABLE_THREAD_SANITIZERS #endif -#define SPY_DISABLE_SANITIZERS SPY_DISABLE_ADDRESS_SANITIZERS SPY_DISABLE_THREAD_SANITIZERS +#define SPY_DISABLE_SANITIZERS \ + SPY_DISABLE_ADDRESS_SANITIZERS SPY_DISABLE_THREAD_SANITIZERS #if defined(__ARM_FEATURE_SVE2) #if !defined(__ARM_FEATURE_SVE_BITS) || (__ARM_FEATURE_SVE_BITS == 0) #define SPY_SIMD_IS_ARM_FLEXIBLE_SVE2 @@ -722,7 +879,8 @@ namespace spy::supports #define SPY_SIMD_IS_ARM_ASIMD #define SPY_SIMD_DETECTED ::spy::_::simd_version::asimd_ #endif -#if !defined(SPY_SIMD_DETECTED) && ((defined(__ARM_NEON__) || defined(_M_ARM)) && (__ARM_ARCH == 7)) +#if !defined(SPY_SIMD_DETECTED) && \ + ((defined(__ARM_NEON__) || defined(_M_ARM)) && (__ARM_ARCH == 7)) #define SPY_SIMD_IS_ARM_NEON #define SPY_SIMD_DETECTED ::spy::_::simd_version::neon_ #endif @@ -869,7 +1027,8 @@ namespace spy::supports #define SPY_SIMD_IS_X86_SSE3 #define SPY_SIMD_DETECTED ::spy::_::simd_version::sse3_ #endif -#if !defined(SPY_SIMD_DETECTED) && (defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)) +#if !defined(SPY_SIMD_DETECTED) && (defined(__SSE2__) || defined(_M_X64) || \ + (defined(_M_IX86_FP) && _M_IX86_FP >= 2)) #define SPY_SIMD_IS_X86_SSE2 #define SPY_SIMD_DETECTED ::spy::_::simd_version::sse2_ #endif @@ -1001,6 +1160,7 @@ namespace spy::supports #endif } } + namespace spy::_ { enum class simd_isa @@ -1047,17 +1207,25 @@ namespace spy::_ rvv_ = 7000, fixed_rvv_ = 7500 }; - template struct simd_info + + template + struct simd_info { static constexpr auto isa = InsSetArch; static constexpr auto version = Version; static constexpr int width = []() { if constexpr (Version == simd_version::simd128_ || - (Version >= simd_version::sse1_ && Version <= simd_version::sse42_) || - Version == simd_version::neon_ || Version == simd_version::asimd_ || - (Version >= simd_version::vmx_2_03_ && Version <= simd_version::vsx_3_01_)) + (Version >= simd_version::sse1_ && + Version <= simd_version::sse42_) || + Version == simd_version::neon_ || + Version == simd_version::asimd_ || + (Version >= simd_version::vmx_2_03_ && + Version <= simd_version::vsx_3_01_)) return 128; - else if constexpr (Version == simd_version::avx_ || Version == simd_version::avx2_) return 256; + else if constexpr (Version == simd_version::avx_ || + Version == simd_version::avx2_) + return 256; else if constexpr (Version == simd_version::avx512_) return 512; else if constexpr (Version == simd_version::rvv_) return -1; else if constexpr (Version == simd_version::fixed_rvv_) @@ -1068,8 +1236,13 @@ namespace spy::_ return -1; #endif } - else if constexpr (Version == simd_version::sve_ || Version == simd_version::sve2_) { return -1; } - else if constexpr (Version == simd_version::fixed_sve_ || Version == simd_version::fixed_sve2_) + else if constexpr (Version == simd_version::sve_ || + Version == simd_version::sve2_) + { + return -1; + } + else if constexpr (Version == simd_version::fixed_sve_ || + Version == simd_version::fixed_sve2_) { #if defined(__ARM_FEATURE_SVE_BITS) return __ARM_FEATURE_SVE_BITS; @@ -1080,6 +1253,7 @@ namespace spy::_ else return -1; }(); static constexpr bool has_fixed_cardinal() { return width != -1; } + template<_::stream OS> friend auto& operator<<(OS& os, simd_info const&) { if constexpr (Version == simd_version::simd128_) os << "WASM SIMD128"; @@ -1092,12 +1266,14 @@ namespace spy::_ else if constexpr (Version == simd_version::avx_) os << "X86 AVX"; else if constexpr (Version == simd_version::avx2_) os << "X86 AVX2"; else if constexpr (Version == simd_version::avx512_) os << "X86 AVX512"; - else if constexpr (Version >= simd_version::vmx_2_03_ && Version <= simd_version::vmx_3_01_) + else if constexpr (Version >= simd_version::vmx_2_03_ && + Version <= simd_version::vmx_3_01_) { constexpr auto v = static_cast(Version); os << "PPC VMX with ISA v" << ((v - 2000) / 100.); } - else if constexpr (Version >= simd_version::vsx_2_06_ && Version <= simd_version::vsx_3_01_) + else if constexpr (Version >= simd_version::vsx_2_06_ && + Version <= simd_version::vsx_3_01_) { constexpr auto v = static_cast(Version); os << "PPC VSX with ISA v" << ((v - 3000) / 100.); @@ -1105,11 +1281,16 @@ namespace spy::_ else if constexpr (Version == simd_version::neon_) os << "ARM NEON"; else if constexpr (Version == simd_version::asimd_) os << "ARM ASIMD"; else if constexpr (Version == simd_version::sve_) os << "ARM SVE (dyn.)"; - else if constexpr (Version == simd_version::fixed_sve_) os << "ARM SVE (" << simd_info::width << " bits)"; - else if constexpr (Version == simd_version::sve2_) os << "ARM SVE2 (dyn.)"; - else if constexpr (Version == simd_version::fixed_sve2_) os << "ARM SVE2 (" << simd_info::width << " bits)"; - else if constexpr (Version == simd_version::rvv_) os << "RISC-V RVV (dyn.)"; - else if constexpr (Version == simd_version::fixed_rvv_) os << "RISC-V RVV (" << simd_info::width << " bits)"; + else if constexpr (Version == simd_version::fixed_sve_) + os << "ARM SVE (" << simd_info::width << " bits)"; + else if constexpr (Version == simd_version::sve2_) + os << "ARM SVE2 (dyn.)"; + else if constexpr (Version == simd_version::fixed_sve2_) + os << "ARM SVE2 (" << simd_info::width << " bits)"; + else if constexpr (Version == simd_version::rvv_) + os << "RISC-V RVV (dyn.)"; + else if constexpr (Version == simd_version::fixed_rvv_) + os << "RISC-V RVV (" << simd_info::width << " bits)"; else return os << "Undefined SIMD instructions set"; if constexpr (spy::supports::fma_) os << " (with FMA3 support)"; if constexpr (spy::supports::fma4_) os << " (with FMA4 support)"; @@ -1117,31 +1298,40 @@ namespace spy::_ return os; } }; + template constexpr bool operator==(simd_info, simd_info) noexcept { - if constexpr (V1 != simd_version::undefined_ && V2 != simd_version::undefined_) return (I1 == I2) && (V1 == V2); + if constexpr (V1 != simd_version::undefined_ && + V2 != simd_version::undefined_) + return (I1 == I2) && (V1 == V2); else return I1 == I2; } + template - constexpr std::partial_ordering operator<=>(simd_info, simd_info) noexcept + constexpr std::partial_ordering operator<=>(simd_info, + simd_info) noexcept { if constexpr (I1 != I2) return std::partial_ordering::unordered; else return static_cast(V1) <=> static_cast(V2); } } + namespace spy { #if defined(SPY_SIMD_DETECTED) - constexpr inline auto simd_instruction_set = _::simd_info{}; + constexpr inline auto simd_instruction_set = + _::simd_info{}; #else constexpr inline auto simd_instruction_set = _::simd_info<>{}; #endif constexpr inline auto undefined_simd_ = _::simd_info<>{}; - template<_::simd_version V = _::simd_version::undefined_> using wasm_simd_info = _::simd_info<_::simd_isa::wasm_, V>; + template<_::simd_version V = _::simd_version::undefined_> + using wasm_simd_info = _::simd_info<_::simd_isa::wasm_, V>; constexpr inline auto wasm_simd_ = wasm_simd_info<>{}; constexpr inline auto simd128_ = wasm_simd_info<_::simd_version::simd128_>{}; - template<_::simd_version V = _::simd_version::undefined_> using x86_simd_info = _::simd_info<_::simd_isa::x86_, V>; + template<_::simd_version V = _::simd_version::undefined_> + using x86_simd_info = _::simd_info<_::simd_isa::x86_, V>; constexpr inline auto x86_simd_ = x86_simd_info<>{}; constexpr inline auto sse1_ = x86_simd_info<_::simd_version::sse1_>{}; constexpr inline auto sse2_ = x86_simd_info<_::simd_version::sse2_>{}; @@ -1152,7 +1342,8 @@ namespace spy constexpr inline auto avx_ = x86_simd_info<_::simd_version::avx_>{}; constexpr inline auto avx2_ = x86_simd_info<_::simd_version::avx2_>{}; constexpr inline auto avx512_ = x86_simd_info<_::simd_version::avx512_>{}; - template<_::simd_version V = _::simd_version::undefined_> using ppc_simd_info = _::simd_info<_::simd_isa::ppc_, V>; + template<_::simd_version V = _::simd_version::undefined_> + using ppc_simd_info = _::simd_info<_::simd_isa::ppc_, V>; constexpr inline auto ppc_simd_ = ppc_simd_info<>{}; constexpr inline auto vmx_ = ppc_simd_info<_::simd_version::vmx_>{}; constexpr inline auto vmx_2_03_ = ppc_simd_info<_::simd_version::vmx_2_03_>{}; @@ -1166,23 +1357,29 @@ namespace spy constexpr inline auto vsx_2_07_ = ppc_simd_info<_::simd_version::vsx_2_07_>{}; constexpr inline auto vsx_3_00_ = ppc_simd_info<_::simd_version::vsx_3_00_>{}; constexpr inline auto vsx_3_01_ = ppc_simd_info<_::simd_version::vsx_3_01_>{}; - template<_::simd_version V = _::simd_version::undefined_> using arm_simd_info = _::simd_info<_::simd_isa::arm_, V>; + template<_::simd_version V = _::simd_version::undefined_> + using arm_simd_info = _::simd_info<_::simd_isa::arm_, V>; template<_::simd_version V = _::simd_version::undefined_> using sve_simd_info = _::simd_info<_::simd_isa::arm_sve_, V>; constexpr inline auto arm_simd_ = arm_simd_info<>{}; constexpr inline auto neon_ = arm_simd_info<_::simd_version::neon_>{}; constexpr inline auto asimd_ = arm_simd_info<_::simd_version::asimd_>{}; constexpr inline auto sve_ = sve_simd_info<_::simd_version::sve_>{}; - constexpr inline auto fixed_sve_ = sve_simd_info<_::simd_version::fixed_sve_>{}; + constexpr inline auto fixed_sve_ = + sve_simd_info<_::simd_version::fixed_sve_>{}; constexpr inline auto sve2_ = sve_simd_info<_::simd_version::sve2_>{}; - constexpr inline auto fixed_sve2_ = sve_simd_info<_::simd_version::fixed_sve2_>{}; + constexpr inline auto fixed_sve2_ = + sve_simd_info<_::simd_version::fixed_sve2_>{}; template<_::simd_version V = _::simd_version::undefined_> using riscv_simd_info = _::simd_info<_::simd_isa::riscv_, V>; constexpr inline auto riscv_simd_ = riscv_simd_info<>{}; constexpr inline auto rvv_ = riscv_simd_info<_::simd_version::rvv_>{}; - constexpr inline auto fixed_rvv_ = riscv_simd_info<_::simd_version::fixed_rvv_>{}; + constexpr inline auto fixed_rvv_ = + riscv_simd_info<_::simd_version::fixed_rvv_>{}; } + #include + namespace spy::_ { enum class stdlib @@ -1191,45 +1388,62 @@ namespace spy::_ libcpp_, gnucpp_ }; + template struct stdlib_info { static constexpr stdlib vendor = Lib; static constexpr version_id version = {}; inline constexpr explicit operator bool() const noexcept; - template constexpr bool operator==(stdlib_info const&) const noexcept + + template + constexpr bool operator==(stdlib_info const&) const noexcept { return C2 == vendor; } + template - constexpr bool operator==(stdlib_info const& c2) const noexcept + constexpr bool operator==( + stdlib_info const& c2) const noexcept { return C2 == vendor && version == c2.version; } + template - constexpr std::partial_ordering operator<=>(stdlib_info const& c2) const noexcept + constexpr std::partial_ordering operator<=>( + stdlib_info const& c2) const noexcept { if constexpr (vendor == C2) return version <=> c2.version; else return std::partial_ordering::unordered; } }; - template<_::stream OS, stdlib SLib, int M, int N, int P> auto& operator<<(OS& os, stdlib_info const& p) + + template<_::stream OS, stdlib SLib, int M, int N, int P> + auto& operator<<(OS& os, stdlib_info const& p) { - if (SLib == stdlib::libcpp_) return os << "libc++ Standard C++ Library " << p.version; - if (SLib == stdlib::gnucpp_) return os << "GNU Standard C++ Library " << p.version; + if (SLib == stdlib::libcpp_) + return os << "libc++ Standard C++ Library " << p.version; + if (SLib == stdlib::gnucpp_) + return os << "GNU Standard C++ Library " << p.version; return os << "Undefined Standard C++ Library"; } - template using libcpp_t = stdlib_info; - template using gnucpp_t = stdlib_info; + + template + using libcpp_t = stdlib_info; + template + using gnucpp_t = stdlib_info; } + namespace spy { #if defined(_LIBCPP_VERSION) #define SPY_STDLIB_IS_LIBCPP - using stdlib_type = _::libcpp_t<(_LIBCPP_VERSION / 1000) % 10, 0, _LIBCPP_VERSION % 1000>; + using stdlib_type = + _::libcpp_t<(_LIBCPP_VERSION / 1000) % 10, 0, _LIBCPP_VERSION % 1000>; #elif defined(__GLIBCXX__) #define SPY_STDLIB_IS_GLIBCXX #define SPY0 (__GLIBCXX__ / 100) - using stdlib_type = _::gnucpp_t<(SPY0 / 100) % 10000, SPY0 % 100, __GLIBCXX__ % 100>; + using stdlib_type = + _::gnucpp_t<(SPY0 / 100) % 10000, SPY0 % 100, __GLIBCXX__ % 100>; #undef SPY0 #else #define SPY_STDLIB_IS_UNKNOWN @@ -1237,71 +1451,77 @@ namespace spy #endif constexpr inline auto stdlib = stdlib_type{}; } + namespace spy::_ { - template inline constexpr stdlib_info::operator bool() const noexcept + template + inline constexpr stdlib_info::operator bool() const noexcept { return spy::stdlib == *this; } } + namespace spy { constexpr inline auto libcpp_ = _::libcpp_t<-1, 0, 0>{}; constexpr inline auto gnucpp_ = _::gnucpp_t<-1, 0, 0>{}; } + namespace spy::literal { template constexpr auto operator""_libcpp() { return _::literal_wrap<_::libcpp_t, c...>(); } + template constexpr auto operator""_gnucpp() { return _::literal_wrap<_::gnucpp_t, c...>(); } } #if defined(SPY_ARCH_IS_ARM) - #if defined(__ARM_FP16_FORMAT_IEEE) && __ARM_FP16_FORMAT_IEEE == 1 \ - && (!defined(__ARM_FP16_FORMAT_ALTERNATIVE) || __ARM_FP16_FORMAT_ALTERNATIVE == 0) - #define SPY_SUPPORTS_FP16_TYPE - #if defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC) - #define SPY_SUPPORTS_FP16_SCALAR_OPS - #endif - #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) - #define SPY_SUPPORTS_FP16_VECTOR_OPS - #endif - #endif +#if defined(__ARM_FP16_FORMAT_IEEE) && __ARM_FP16_FORMAT_IEEE == 1 && \ + (!defined(__ARM_FP16_FORMAT_ALTERNATIVE) || \ + __ARM_FP16_FORMAT_ALTERNATIVE == 0) +#define SPY_SUPPORTS_FP16_TYPE +#if defined(__ARM_FEATURE_FP16_SCALAR_ARITHMETIC) +#define SPY_SUPPORTS_FP16_SCALAR_OPS +#endif +#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) +#define SPY_SUPPORTS_FP16_VECTOR_OPS +#endif +#endif #elif defined(SPY_ARCH_IS_X86) - #define SPY_SUPPORTS_FP16_TYPE +#define SPY_SUPPORTS_FP16_TYPE #elif defined(SPY_ARCH_IS_AMD64) - #define SPY_SUPPORTS_FP16_TYPE - #if defined(__AVX512FP16__) - #define SPY_SUPPORTS_FP16_SCALAR_OPS - #define SPY_SUPPORTS_FP16_VECTOR_OPS - #endif +#define SPY_SUPPORTS_FP16_TYPE +#if defined(__AVX512FP16__) +#define SPY_SUPPORTS_FP16_SCALAR_OPS +#define SPY_SUPPORTS_FP16_VECTOR_OPS +#endif #elif defined(SPY_ARCH_IS_RISCV) - #define SPY_SUPPORTS_FP16_TYPE - #if defined(__riscv_zfh) - #define SPY_SUPPORTS_FP16_SCALAR_OPS - #define SPY_SUPPORTS_FP16_VECTOR_OPS - #endif +#define SPY_SUPPORTS_FP16_TYPE +#if defined(__riscv_zfh) +#define SPY_SUPPORTS_FP16_SCALAR_OPS +#define SPY_SUPPORTS_FP16_VECTOR_OPS +#endif #endif namespace spy::supports::fp16 { #ifdef SPY_SUPPORTS_FP16_TYPE - static constexpr bool type = true; + static constexpr bool type = true; #else - static constexpr bool type = false; + static constexpr bool type = false; #endif #ifdef SPY_SUPPORTS_FP16_SCALAR_OPS - static constexpr bool scalar_ops = true; + static constexpr bool scalar_ops = true; #else - static constexpr bool scalar_ops = false; + static constexpr bool scalar_ops = false; #endif #ifdef SPY_SUPPORTS_FP16_VECTOR_OPS - static constexpr bool vector_ops = true; + static constexpr bool vector_ops = true; #else - static constexpr bool vector_ops = false; + static constexpr bool vector_ops = false; #endif } -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/format.hpp b/include/rotgen/format.hpp index ad9d29c..e2355c3 100644 --- a/include/rotgen/format.hpp +++ b/include/rotgen/format.hpp @@ -11,4 +11,4 @@ #include #else #include -#endif \ No newline at end of file +#endif diff --git a/include/rotgen/format/dynamic.hpp b/include/rotgen/format/dynamic.hpp index 02bfe0b..3475852 100644 --- a/include/rotgen/format/dynamic.hpp +++ b/include/rotgen/format/dynamic.hpp @@ -15,36 +15,36 @@ namespace rotgen { class ROTGEN_EXPORT ioformat { - private: + private: struct payload; std::unique_ptr storage_; - public: - ioformat( int precision, int flags = 0 - , std::string const& coeffSeparator = " " - , std::string const& rowSeparator = "\n" - , std::string const& rowPrefix = "", std::string const& rowSuffix = "" - , std::string const& matPrefix = "", std::string const& matSuffix = "" - , char fill = ' ' - ); - + public: + ioformat(int precision, + int flags = 0, + std::string const& coeffSeparator = " ", + std::string const& rowSeparator = "\n", + std::string const& rowPrefix = "", + std::string const& rowSuffix = "", + std::string const& matPrefix = "", + std::string const& matSuffix = "", + char fill = ' '); ~ioformat(); std::unique_ptr const& storage() const { return storage_; } }; - template - struct format + template struct format { - format(const M& m, const ioformat& f) : matrix_(m), format_(f) {} + format(M const& m, ioformat const& f) : matrix_(m), format_(f) {} - M const& matrix_; - ioformat const& format_; + M const& matrix_; + ioformat const& format_; }; - template - std::ostream& operator<<(std::ostream& os, const format& f) + template + std::ostream& operator<<(std::ostream& os, format const& f) { return os << format{f.matrix_.base(), f.format_}; } diff --git a/include/rotgen/format/fixed.hpp b/include/rotgen/format/fixed.hpp index fb890bc..2217712 100644 --- a/include/rotgen/format/fixed.hpp +++ b/include/rotgen/format/fixed.hpp @@ -17,19 +17,19 @@ namespace rotgen { using ioformat = Eigen::IOFormat; - template - struct format + template struct format { - format(const M& m, const ioformat& f) : matrix_(m), format_(f) {} + format(M const& m, ioformat const& f) : matrix_(m), format_(f) {} - M const& matrix_; - ioformat const& format_; + M const& matrix_; + ioformat const& format_; }; - template - std::ostream& operator<<(std::ostream& os, const format& f) + template + std::ostream& operator<<(std::ostream& os, format const& f) { - if constexpr(concepts::eigen_compatible) return os << f.matrix_.format(f.format_); - else return os << f.matrix_.base().format(f.format_); + if constexpr (concepts::eigen_compatible) + return os << f.matrix_.format(f.format_); + else return os << f.matrix_.base().format(f.format_); } } diff --git a/include/rotgen/functions.hpp b/include/rotgen/functions.hpp index 6434144..9c9b91d 100644 --- a/include/rotgen/functions.hpp +++ b/include/rotgen/functions.hpp @@ -10,4 +10,4 @@ #include #include #include -#include \ No newline at end of file +#include diff --git a/include/rotgen/functions/extract.hpp b/include/rotgen/functions/extract.hpp index d2b4fc7..d77e7f0 100644 --- a/include/rotgen/functions/extract.hpp +++ b/include/rotgen/functions/extract.hpp @@ -13,10 +13,11 @@ namespace rotgen namespace detail { template - void validate_extract ( [[maybe_unused]] Entity& e - , [[maybe_unused]] Index i0, [[maybe_unused]] Index j0 - , [[maybe_unused]] Index ni, [[maybe_unused]] Index nj - ) + void validate_extract([[maybe_unused]] Entity& e, + [[maybe_unused]] Index i0, + [[maybe_unused]] Index j0, + [[maybe_unused]] Index ni, + [[maybe_unused]] Index nj) { assert(i0 >= 0 && "block extraction uses negative row index."); assert(j0 >= 0 && "block extraction uses negative col index."); @@ -24,37 +25,36 @@ namespace rotgen assert(j0 + nj <= e.cols() && "block extraction cols is out of range."); } } + //======================== EXTRACT ======================== template auto extract(Entity& e, Index i0, Index j0, Index ni, Index nj) { - detail::validate_extract(e,i0,j0,ni,nj); - if constexpr(concepts::reference) + detail::validate_extract(e, i0, j0, ni, nj); + if constexpr (concepts::reference) return extract(e.base(), i0, j0, ni, nj); - else - return block>(e, i0, j0, ni, nj); + else return block>(e, i0, j0, ni, nj); } template - requires(NI!=-1 && NJ!=-1) + requires(NI != -1 && NJ != -1) auto extract(Entity& e, Index i0, Index j0) { - detail::validate_extract(e,i0,j0,NI,NJ); - if constexpr(concepts::reference) - return extract(e.base(), i0, j0); - else - return block ,NI,NJ>(e, i0, j0); + detail::validate_extract(e, i0, j0, NI, NJ); + if constexpr (concepts::reference) + return extract(e.base(), i0, j0); + else return block, NI, NJ>(e, i0, j0); } template - requires((NI!=-1) != (NJ!=-1)) + requires((NI != -1) != (NJ != -1)) auto extract(Entity& e, Index i0, Index j0, Index ni, Index nj) { - detail::validate_extract(e,i0,j0,ni,nj); - if constexpr(concepts::reference) - return extract(e.base(), i0, j0, ni, nj); + detail::validate_extract(e, i0, j0, ni, nj); + if constexpr (concepts::reference) + return extract(e.base(), i0, j0, ni, nj); else - return block,NI,NJ>(e, i0, j0, ni, nj); + return block, NI, NJ>(e, i0, j0, ni, nj); } //======================== TOP LEFT CORNER ======================== @@ -67,7 +67,7 @@ namespace rotgen template auto topLeftCorner(Entity& e) { - return extract(e, 0, 0); + return extract(e, 0, 0); } //======================== TOP RIGHT CORNER ======================== @@ -80,7 +80,7 @@ namespace rotgen template auto topRightCorner(Entity& e) { - return extract(e, 0, e.cols()-NJ); + return extract(e, 0, e.cols() - NJ); } //======================== BOTTOM LEFT CORNER ======================== @@ -93,7 +93,7 @@ namespace rotgen template auto bottomLeftCorner(Entity& e) { - return extract(e, e.rows()-NI, 0); + return extract(e, e.rows() - NI, 0); } //======================== BOTTOM RIGHT CORNER ======================== @@ -106,20 +106,18 @@ namespace rotgen template auto bottomRightCorner(Entity& e) { - return extract(e, e.rows()-NI, e.cols()-NJ); + return extract(e, e.rows() - NI, e.cols() - NJ); } //======================== TOP ROWS ======================== - template - auto topRows(Entity& e, Index ni) + template auto topRows(Entity& e, Index ni) { return extract(e, 0, 0, ni, e.cols()); } - template - auto topRows(Entity& e) + template auto topRows(Entity& e) { - return extract(e, 0, 0, NI,e.cols()); + return extract(e, 0, 0, NI, e.cols()); } //======================== MIDDLE ROWS ======================== @@ -132,33 +130,29 @@ namespace rotgen template auto middleRows(Entity& e, Index i0) { - return extract(e, i0, 0,NI,e.cols()); + return extract(e, i0, 0, NI, e.cols()); } //======================== BOTTOM ROWS ======================== - template - auto bottomRows(Entity& e, Index ni) + template auto bottomRows(Entity& e, Index ni) { return extract(e, e.rows() - ni, 0, ni, e.cols()); } - template - auto bottomRows(Entity& e) + template auto bottomRows(Entity& e) { - return extract(e, e.rows()-NI, 0,NI,e.cols()); + return extract(e, e.rows() - NI, 0, NI, e.cols()); } //======================== LEFT COLS ======================== - template - auto leftCols(Entity& e, Index nj) + template auto leftCols(Entity& e, Index nj) { return extract(e, 0, 0, e.rows(), nj); } - template - auto leftCols(Entity& e) + template auto leftCols(Entity& e) { - return extract<-1,NJ>(e, 0, 0,e.rows(),NJ); + return extract<-1, NJ>(e, 0, 0, e.rows(), NJ); } //======================== MIDDLE COLS ======================== @@ -171,81 +165,90 @@ namespace rotgen template auto middleCols(Entity& e, Index j0) { - return extract<-1,NJ>(e, 0, j0,e.rows(),NJ); + return extract<-1, NJ>(e, 0, j0, e.rows(), NJ); } //======================== RIGHT COLS ======================== - template - auto rightCols(Entity& e, Index nj) + template auto rightCols(Entity& e, Index nj) { return extract(e, 0, e.cols() - nj, e.rows(), nj); } - template - auto rightCols(Entity& e) + template auto rightCols(Entity& e) { - return extract<-1,NJ>(e, 0, e.cols()-NJ,e.rows(),NJ); + return extract<-1, NJ>(e, 0, e.cols() - NJ, e.rows(), NJ); } //======================== ROW ======================== - template - auto row(Entity& e, Index i0) + template auto row(Entity& e, Index i0) { - return extract<1,-1>(e, i0, 0, 1, e.cols()); + return extract<1, -1>(e, i0, 0, 1, e.cols()); } //======================== COL ======================== - template - auto col(Entity& e, Index j0) + template auto col(Entity& e, Index j0) { - return extract<-1,1>(e, 0, j0, e.rows(), 1); + return extract<-1, 1>(e, 0, j0, e.rows(), 1); } //======================== VECTOR HEAD ======================== template auto head(Entity& e, Index n) - requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,Dynamic>(e,0,0,1,n); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,0,0,n,1); + if constexpr (Entity::RowsAtCompileTime == 1) + return extract<1, Dynamic>(e, 0, 0, 1, n); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, 0, 0, n, 1); } template - auto head(Entity& e) requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + auto head(Entity& e) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,N>(e,0,0); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,0,0); + if constexpr (Entity::RowsAtCompileTime == 1) return extract<1, N>(e, 0, 0); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, 0, 0); } //======================== VECTOR TAIL ======================== template auto tail(Entity& e, Index n) - requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,Dynamic>(e,0,e.cols()-n,1,n); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,e.rows()-n,0,n,1); + if constexpr (Entity::RowsAtCompileTime == 1) + return extract<1, Dynamic>(e, 0, e.cols() - n, 1, n); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, e.rows() - n, 0, n, 1); } template - auto tail(Entity& e) requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + auto tail(Entity& e) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,N>(e,0,e.cols()-N); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,e.rows()-N,0); + if constexpr (Entity::RowsAtCompileTime == 1) + return extract<1, N>(e, 0, e.cols() - N); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, e.rows() - N, 0); } //======================== VECTOR SEGMENT ======================== template auto segment(Entity& e, Index s, Index n) - requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,Dynamic>(e,0,s,1,n); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,s,0,n,1); + if constexpr (Entity::RowsAtCompileTime == 1) + return extract<1, Dynamic>(e, 0, s, 1, n); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, s, 0, n, 1); } template - auto segment(Entity& e, Index s) requires(Entity::RowsAtCompileTime==1 || Entity::ColsAtCompileTime==1) + auto segment(Entity& e, Index s) + requires(Entity::RowsAtCompileTime == 1 || Entity::ColsAtCompileTime == 1) { - if constexpr(Entity::RowsAtCompileTime==1) return extract<1,N>(e,0,s); - else if constexpr(Entity::ColsAtCompileTime==1) return extract(e,s,0); + if constexpr (Entity::RowsAtCompileTime == 1) return extract<1, N>(e, 0, s); + else if constexpr (Entity::ColsAtCompileTime == 1) + return extract(e, s, 0); } } diff --git a/include/rotgen/functions/functions.hpp b/include/rotgen/functions/functions.hpp index 81464bb..c727959 100644 --- a/include/rotgen/functions/functions.hpp +++ b/include/rotgen/functions/functions.hpp @@ -14,19 +14,44 @@ 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(); } + std::size_t rows(auto const& m) + requires(requires { m.rows(); }) + { + return m.rows(); + } - 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); } + std::size_t cols(auto const& m) + requires(requires { m.cols(); }) + { + return m.cols(); + } - void conservativeResize(auto& a, int s) requires requires{a.conservativeResize(s);} + 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);} + void conservativeResize(auto& a, int r, int c) + requires requires { a.conservativeResize(r, c); } { a.conservativeResize(r, c); } @@ -34,70 +59,129 @@ namespace rotgen //----------------------------------------------------------------------------------------------- // 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(); } + decltype(auto) normalized(auto const& m) + requires(requires { m.normalized(); }) + { + return m.normalized(); + } - 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(); } + 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(); } + 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)); + 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); + 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); + 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)); + 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); + 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); + 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)); + if constexpr (!use_expression_templates) + return mul(generalize_t(a), generalize_t(b)); + else return base_of(a).cwiseProduct(base_of(b)); } template @@ -115,8 +199,9 @@ namespace rotgen 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(); + if constexpr (!use_expression_templates) + return div(generalize_t(a), generalize_t(b)); + else return base_of(a).array() / base_of(b).array(); } template @@ -125,47 +210,86 @@ namespace rotgen return a / b; } - template - auto square(A const& a) + template auto square(A const& a) { - return mul(a,a); + return mul(a, a); } //----------------------------------------------------------------------------------------------- // 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(); } + 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) + 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)); + 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(); } + 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) + 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) + 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

();} ) + auto lpNorm(T const& arg) + requires(requires { arg.template lpNorm

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

(); @@ -175,19 +299,22 @@ namespace rotgen // Expression handling //----------------------------------------------------------------------------------------------- template - decltype(auto) noalias(T&& t) requires( requires{std::forward(t).noalias();} ) + 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();} ) + 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();} ) + auto evaluate(T&& t) + requires(requires { std::forward(t).eval(); }) { return std::forward(t).eval(); } @@ -196,142 +323,168 @@ namespace rotgen // Generators //----------------------------------------------------------------------------------------------- template - auto setZero(T&& t) requires( requires{std::forward(t).setZero();} ) + auto setZero(T&& t) + requires(requires { std::forward(t).setZero(); }) { return std::forward(t).setZero(); } template - auto setZero() requires( requires{T::Zero();} ) + auto setZero() + requires(requires { T::Zero(); }) { return T::Zero(); } template - auto setZero(std::integral auto n) requires( requires{T::Zero(n);} ) + auto setZero(std::integral auto n) + requires(requires { T::Zero(n); }) { - return T::Zero(n); + return T::Zero(n); } template - auto setZero(std::integral auto r,std::integral auto c) requires( requires{T::Zero(r,c);} ) + auto setZero(std::integral auto r, std::integral auto c) + requires(requires { T::Zero(r, c); }) { - return T::Zero(r,c); + return T::Zero(r, c); } template - auto setOnes(T&& t) requires( requires{std::forward(t).setOnes();} ) + auto setOnes(T&& t) + requires(requires { std::forward(t).setOnes(); }) { return std::forward(t).setOnes(); } template - auto setOnes() requires( requires{T::Ones();} ) + auto setOnes() + requires(requires { T::Ones(); }) { return T::Ones(); } template - auto setOnes(std::integral auto n) requires( requires{T::Ones(n);} ) + auto setOnes(std::integral auto n) + requires(requires { T::Ones(n); }) { - return T::Ones(n); + return T::Ones(n); } template - auto setOnes(std::integral auto r,std::integral auto c) requires( requires{T::Ones(r,c);} ) + auto setOnes(std::integral auto r, std::integral auto c) + requires(requires { T::Ones(r, c); }) { - return T::Ones(r,c); + return T::Ones(r, c); } template - auto setIdentity(T&& t) requires( requires{std::forward(t).setIdentity();} ) + auto setIdentity(T&& t) + requires(requires { std::forward(t).setIdentity(); }) { return std::forward(t).setIdentity(); } template - auto setIdentity() requires( requires{T::Identity();} ) + auto setIdentity() + requires(requires { T::Identity(); }) { return T::Identity(); } template - auto setIdentity(std::integral auto n) requires( requires{T::Identity(n);} ) + auto setIdentity(std::integral auto n) + requires(requires { T::Identity(n); }) { - return T::Identity(n); + return T::Identity(n); } template - auto setIdentity(std::integral auto r,std::integral auto c) requires( requires{T::Identity(r,c);} ) + auto setIdentity(std::integral auto r, std::integral auto c) + requires(requires { T::Identity(r, c); }) { - return T::Identity(r,c); + return T::Identity(r, c); } template - auto setRandom(T&& t) requires( requires{std::forward(t).setRandom();} ) + auto setRandom(T&& t) + requires(requires { std::forward(t).setRandom(); }) { return std::forward(t).setRandom(); } template - auto setRandom() requires( requires{T::Random();} ) + auto setRandom() + requires(requires { T::Random(); }) { return T::Random(); } template - auto setRandom(std::integral auto n) requires( requires{T::Random(n);} ) + auto setRandom(std::integral auto n) + requires(requires { T::Random(n); }) { - return T::Random(n); + return T::Random(n); } template - auto setRandom(std::integral auto r,std::integral auto c) requires( requires{T::Random(r,c);} ) + auto setRandom(std::integral auto r, std::integral auto c) + requires(requires { T::Random(r, c); }) { - return T::Random(r,c); + return T::Random(r, c); } template - auto setConstant(T&& t, auto v) requires( requires{std::forward(t).setConstant(v);} ) + 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);} ) + 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);} ) + auto setConstant(std::integral auto n, auto v) + requires(requires { T::Constant(n, v); }) { - return 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);} ) + 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); + return T::Constant(r, c, v); } //----------------------------------------------------------------------------------------------- // Others - // TODO: Adapt other functions ot behave as inverse and limit code in non-ref/non-map containers + // 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(); + 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) + 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;} ) + 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); + else return l.cross(r); } -} \ No newline at end of file +} diff --git a/include/rotgen/functions/operators.hpp b/include/rotgen/functions/operators.hpp index 2ff082b..7147e5d 100644 --- a/include/rotgen/functions/operators.hpp +++ b/include/rotgen/functions/operators.hpp @@ -23,50 +23,58 @@ namespace rotgen constexpr bool operator==(A const& a, B const& b) noexcept requires(concepts::entity || concepts::entity) { - static_assert ( std::same_as - , "[ROTGEN] Incompatible type in operator==" - ); - if constexpr(!use_expression_templates) return generalize_t(a) == generalize_t(b); - else return base_of(a) == base_of(b); + static_assert(std::same_as, + "[ROTGEN] Incompatible type in operator=="); + if constexpr (!use_expression_templates) + return generalize_t(a) == generalize_t(b); + else return base_of(a) == base_of(b); } template constexpr bool operator!=(A const& a, B const& b) noexcept requires(concepts::entity || concepts::entity) { - static_assert ( std::same_as - , "[ROTGEN] Incompatible type in operator!=" - ); - if constexpr(!use_expression_templates) return generalize_t(a) != generalize_t(b); - else return base_of(a) != base_of(b); + static_assert(std::same_as, + "[ROTGEN] Incompatible type in operator!="); + if constexpr (!use_expression_templates) + return generalize_t(a) != generalize_t(b); + else return base_of(a) != base_of(b); } template - auto operator+(A const& a, B const& b) requires(concepts::entity || concepts::entity) + auto operator+(A const& a, B const& b) + requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) + generalize_t(b); - else return base_of(a) + base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) + generalize_t(b); + else return base_of(a) + base_of(b); } template - auto operator-(A const& a, B const& b) requires(concepts::entity || concepts::entity) + auto operator-(A const& a, B const& b) + requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) - generalize_t(b); - else return base_of(a) - base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) - generalize_t(b); + else return base_of(a) - base_of(b); } template - auto operator*(A const& a, B const& b) requires(concepts::entity || concepts::entity) + auto operator*(A const& a, B const& b) + requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) * generalize_t(b); - else return base_of(a) * base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) * generalize_t(b); + else return base_of(a) * base_of(b); } template - auto operator/(A const& a, B const& b) requires(concepts::entity && std::is_arithmetic_v) + auto operator/(A const& a, B const& b) + requires(concepts::entity && std::is_arithmetic_v) { - if constexpr(!use_expression_templates) return generalize_t(a) / b; - else return base_of(a) / b; + if constexpr (!use_expression_templates) + return generalize_t(a) / b; + else return base_of(a) / b; } //------------------------------------------------------------------------------------------------ @@ -75,23 +83,26 @@ namespace rotgen auto operator+=(A& a, B const& b) requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) += generalize_t(b); - else return base_of(a) += base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) += generalize_t(b); + else return base_of(a) += base_of(b); } template auto operator-=(A& a, B const& b) requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) -= generalize_t(b); - else return base_of(a) -= base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) -= generalize_t(b); + else return base_of(a) -= base_of(b); } template auto operator*=(A& a, B const& b) requires(concepts::entity || concepts::entity) { - if constexpr(!use_expression_templates) return generalize_t(a) *= generalize_t(b); - else return base_of(a) *= base_of(b); + if constexpr (!use_expression_templates) + return generalize_t(a) *= generalize_t(b); + else return base_of(a) *= base_of(b); } -} \ No newline at end of file +} diff --git a/include/rotgen/functions/reshaper.hpp b/include/rotgen/functions/reshaper.hpp index 3bc460a..b47d347 100644 --- a/include/rotgen/functions/reshaper.hpp +++ b/include/rotgen/functions/reshaper.hpp @@ -16,64 +16,62 @@ namespace rotgen concrete_type sum() const { - concrete_type res(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.sum(); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.sum(); }); return res; } concrete_type mean() const { - concrete_type res(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.mean(); }); + 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(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.prod(); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.prod(); }); return res; } concrete_type maxCoeff() const { - concrete_type res(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.maxCoeff(); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); return res; } concrete_type minCoeff() const { - concrete_type res(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.minCoeff(); }); + 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(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.squaredNorm(); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); return res; } concrete_type norm() const { - concrete_type res(target_.rows(),1); - apply([&](auto r, auto i){ res(i) = r.norm(); }); + concrete_type res(target_.rows(), 1); + apply([&](auto r, auto i) { res(i) = r.norm(); }); return res; } - private: + private: template void apply(Func f) { - for(Index i = 0; i < target_.rows(); ++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 < target_.rows(); ++i) - f(row(target_,i), i); + for (Index i = 0; i < target_.rows(); ++i) f(row(target_, i), i); } }; @@ -85,75 +83,73 @@ namespace rotgen concrete_type sum() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.sum(); }); + apply([&](auto r, auto i) { res(i) = r.sum(); }); return res; } concrete_type mean() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.mean(); }); + apply([&](auto r, auto i) { res(i) = r.mean(); }); return res; } - concrete_type prod() const + concrete_type prod() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.prod(); }); + apply([&](auto r, auto i) { res(i) = r.prod(); }); return res; } concrete_type maxCoeff() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.maxCoeff(); }); + apply([&](auto r, auto i) { res(i) = r.maxCoeff(); }); return res; } concrete_type minCoeff() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.minCoeff(); }); + apply([&](auto r, auto i) { res(i) = r.minCoeff(); }); return res; } - concrete_type squaredNorm() const + concrete_type squaredNorm() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.squaredNorm(); }); + apply([&](auto r, auto i) { res(i) = r.squaredNorm(); }); return res; } concrete_type norm() const { concrete_type res(1, target_.cols()); - apply([&](auto r, auto i){ res(i) = r.norm(); }); + apply([&](auto r, auto i) { res(i) = r.norm(); }); return res; } - private: + private: template void apply(Func f) { - for(Index i = 0; i < target_.cols(); ++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 < target_.cols(); ++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}; } -} \ No newline at end of file +} diff --git a/include/rotgen/rotgen.hpp b/include/rotgen/rotgen.hpp index 882b956..2b14aa7 100644 --- a/include/rotgen/rotgen.hpp +++ b/include/rotgen/rotgen.hpp @@ -7,9 +7,11 @@ //================================================================================================== #pragma once +//clang-format off #include #include #include #include #include #include +//clang-format on diff --git a/src/block/generate.cpp b/src/block/generate.cpp index 5eb5314..7202234 100644 --- a/src/block/generate.cpp +++ b/src/block/generate.cpp @@ -9,10 +9,10 @@ #define TYPE double #define STORAGE_ORDER Eigen::ColMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME @@ -21,10 +21,10 @@ #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME @@ -39,10 +39,10 @@ #define TYPE float #define STORAGE_ORDER Eigen::ColMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME @@ -51,10 +51,10 @@ #undef STORAGE_ORDER #define STORAGE_ORDER Eigen::RowMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 "model.cpp" #undef CLASSNAME #undef TRANSSOURCENAME @@ -63,4 +63,4 @@ #undef STORAGE_ORDER #undef SIZE -#undef TYPE \ No newline at end of file +#undef TYPE diff --git a/src/block/impl.cpp b/src/block/impl.cpp index a450e16..fe8f510 100644 --- a/src/block/impl.cpp +++ b/src/block/impl.cpp @@ -13,21 +13,21 @@ namespace rotgen { - #define USE_CONST - #define CONST const - #define BASENAME block_const_impl - #define BASEMAP map_const_impl - #include "generate.cpp" - #undef BASENAME - #undef BASEMAP - #undef USE_CONST - #undef CONST +#define USE_CONST +#define CONST const +#define BASENAME block_const_impl +#define BASEMAP map_const_impl +#include "generate.cpp" +#undef BASENAME +#undef BASEMAP +#undef USE_CONST +#undef CONST - #define CONST - #define BASENAME block_impl - #define BASEMAP map_impl - #include "generate.cpp" - #undef BASENAME - #undef BASEMAP - #undef CONST +#define CONST +#define BASENAME block_impl +#define BASEMAP map_impl +#include "generate.cpp" +#undef BASENAME +#undef BASEMAP +#undef CONST } diff --git a/src/block/model.cpp b/src/block/model.cpp index a7eba05..104c007 100644 --- a/src/block/model.cpp +++ b/src/block/model.cpp @@ -17,518 +17,528 @@ //================================================================================================== struct CLASSNAME::payload { - using stride_type = Eigen::Stride; - using matrix_type = Eigen::Matrix; + using stride_type = Eigen::Stride; + using matrix_type = + Eigen::Matrix; using matrix_block_type = Eigen::Block; - using matrix_storage_t = std::pair; - using map_type = Eigen::Map; - using map_block_type = Eigen::Block; - using map_storage_t = std::pair; - using data_type = std::variant; + using matrix_storage_t = std::pair; + using map_type = Eigen::Map; + using map_block_type = Eigen::Block; + using map_storage_t = std::pair; + using data_type = std::variant; - data_type data; - rotgen::Index abs_i0 = 0; // absolute start row in original matrix - rotgen::Index abs_j0 = 0; // absolute start col in original matrix - rotgen::Index rel_i0 = 0; // relative start row in original matrix - rotgen::Index rel_j0 = 0; // relative start col in original matrix + data_type data; + rotgen::Index abs_i0 = 0; // absolute start row in original matrix + rotgen::Index abs_j0 = 0; // absolute start col in original matrix + rotgen::Index rel_i0 = 0; // relative start row in original matrix + rotgen::Index rel_j0 = 0; // relative start col in original matrix - template - void apply(Func f) { std::visit([&](auto& blk) { return f(blk.first); }, data); } + template void apply(Func f) + { + std::visit([&](auto& blk) { return f(blk.first); }, data); + } - template - void apply(Func f) const { std::visit([&](auto const& blk) { return f(blk.first); }, data); } + template void apply(Func f) const + { + std::visit([&](auto const& blk) { return f(blk.first); }, data); + } - payload (data_type const& o) : data(o) {} + payload(data_type const& o) : data(o) {} - payload (SOURCENAME CONST& o, rotgen::Index i0, rotgen::Index j0, rotgen::Index ni, rotgen::Index nj) - : data(matrix_storage_t{matrix_block_type{o.storage()->data,i0,j0,ni,nj},&o.storage()->data}) - , abs_i0(i0), abs_j0(j0), rel_i0(i0), rel_j0(j0) - {} + payload(SOURCENAME CONST& o, + rotgen::Index i0, + rotgen::Index j0, + rotgen::Index ni, + rotgen::Index nj) + : data( + matrix_storage_t{matrix_block_type{o.storage()->data, i0, j0, ni, nj}, + &o.storage()->data}), + abs_i0(i0), abs_j0(j0), rel_i0(i0), rel_j0(j0) + { + } - payload (MAPNAME CONST& o, rotgen::Index i0, rotgen::Index j0, rotgen::Index ni, rotgen::Index nj) - : data(map_storage_t{map_block_type{o.storage()->data,i0,j0,ni,nj},&o.storage()->data}) - , abs_i0(i0), abs_j0(j0), rel_i0(i0), rel_j0(j0) - {} + payload(MAPNAME CONST& o, + rotgen::Index i0, + rotgen::Index j0, + rotgen::Index ni, + rotgen::Index nj) + : data(map_storage_t{map_block_type{o.storage()->data, i0, j0, ni, nj}, + &o.storage()->data}), + abs_i0(i0), abs_j0(j0), rel_i0(i0), rel_j0(j0) + { + } }; - //================================================================================================== - // Constructors & Special Members - //================================================================================================== - CLASSNAME::CLASSNAME(SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj) - : storage_(std::make_unique(r, i0,j0,ni,nj)) - {} +//================================================================================================== +// Constructors & Special Members +//================================================================================================== +CLASSNAME::CLASSNAME( + SOURCENAME CONST& r, Index i0, Index j0, Index ni, Index nj) + : storage_(std::make_unique(r, i0, j0, ni, nj)) +{ +} - CLASSNAME::CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj) - : storage_(std::make_unique(r, i0,j0,ni,nj)) - {} +CLASSNAME::CLASSNAME(MAPNAME CONST& r, Index i0, Index j0, Index ni, Index nj) + : storage_(std::make_unique(r, i0, j0, ni, nj)) +{ +} - // We're building a block from a block - So we have to dig around the internals - CLASSNAME::CLASSNAME(payload const& o, Index i0, Index j0, Index ni, Index nj) - { - // Compute absolute indices from the parent stored block - Index abs_i0 = 0; - Index abs_j0 = 0; - std::visit( [&](auto const& blk) - { - abs_i0 = blk.first.startRow() + i0; - abs_j0 = blk.first.startCol() + j0; - } - , o.data - ); +// We're building a block from a block - So we have to dig around the internals +CLASSNAME::CLASSNAME(payload const& o, Index i0, Index j0, Index ni, Index nj) +{ + // Compute absolute indices from the parent stored block + Index abs_i0 = 0; + Index abs_j0 = 0; + std::visit( + [&](auto const& blk) { + abs_i0 = blk.first.startRow() + i0; + abs_j0 = blk.first.startCol() + j0; + }, + o.data); - // Build a payload::data_type that holds the child block using absolute indices - payload::data_type new_data = - std::visit([&](T const& blk) -> payload::data_type - { - auto& [parent_block, ref] = blk; - using block_type = typename T::first_type; - return T{ block_type{ *ref, abs_i0, abs_j0, ni, nj }, ref }; - }, o.data); + // Build a payload::data_type that holds the child block using absolute + // indices + payload::data_type new_data = std::visit( + [&](T const& blk) -> payload::data_type { + auto& [parent_block, ref] = blk; + using block_type = typename T::first_type; + return T{block_type{*ref, abs_i0, abs_j0, ni, nj}, ref}; + }, + o.data); - storage_ = std::make_unique(new_data); - storage_->abs_i0 = abs_i0; - storage_->abs_j0 = abs_j0; - storage_->rel_i0 = i0; - storage_->rel_j0 = j0; - } + storage_ = std::make_unique(new_data); + storage_->abs_i0 = abs_i0; + storage_->abs_j0 = abs_j0; + storage_->rel_i0 = i0; + storage_->rel_j0 = j0; +} - CLASSNAME::CLASSNAME(CLASSNAME const& o) +CLASSNAME::CLASSNAME(CLASSNAME const& o) : storage_(std::make_unique(o.storage_->data)) - {} +{ +} - CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; +CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; - #if !defined(USE_CONST) - CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) - { - if (this != &o) { storage_->data = o.storage_->data; } - return *this; - } +#if !defined(USE_CONST) +CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) +{ + if (this != &o) { storage_->data = o.storage_->data; } + return *this; +} - CLASSNAME& CLASSNAME::operator=(CLASSNAME&& o) noexcept - { - if (this != &o) { storage_->data = std::move(o.storage_->data); } - return *this; - } - #endif +CLASSNAME& CLASSNAME::operator=(CLASSNAME&& o) noexcept +{ + if (this != &o) { storage_->data = std::move(o.storage_->data); } + return *this; +} +#endif +CLASSNAME::~CLASSNAME() = default; - CLASSNAME::~CLASSNAME() = default; +#if !defined(USE_CONST) +void CLASSNAME::assign(SOURCENAME const& m) +{ + storage_->apply([&](auto& blk) { blk = m.storage()->data; }); +} +#endif - #if !defined(USE_CONST) - void CLASSNAME::assign(SOURCENAME const& m) - { - storage_->apply([&](auto& blk) - { - blk = m.storage()->data; - }); - } - #endif +//================================================================================================== +// Matrix API +//================================================================================================== +rotgen::Index CLASSNAME::rows() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.rows(); }); + return that; +} - //================================================================================================== - // Matrix API - //================================================================================================== - rotgen::Index CLASSNAME::rows() const - { - rotgen::Index that; - storage_->apply([&](const auto& 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::cols() const - { - rotgen::Index that; - storage_->apply([&](const auto& blk) { that = blk.cols(); }); - return that; - } +rotgen::Index CLASSNAME::size() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.size(); }); + return that; +} - rotgen::Index CLASSNAME::size() const - { - rotgen::Index that; - storage_->apply([&](const auto& blk) { that = blk.size(); }); - return that; - } +rotgen::Index CLASSNAME::innerStride() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.innerStride(); }); + return that; +} - rotgen::Index CLASSNAME::innerStride() const - { - rotgen::Index that; - storage_->apply([&](const auto& blk) { that = blk.innerStride(); }); - return that; - } +rotgen::Index CLASSNAME::outerStride() const +{ + rotgen::Index that; + storage_->apply([&](auto const& blk) { that = blk.outerStride(); }); + return that; +} - rotgen::Index CLASSNAME::outerStride() const - { - rotgen::Index that; - storage_->apply([&](const auto& blk) { that = blk.outerStride(); }); - return that; - } +rotgen::Index CLASSNAME::startRow() const +{ + return storage_->rel_i0; +} - rotgen::Index CLASSNAME::startRow() const - { - return storage_->rel_i0; - } +rotgen::Index CLASSNAME::startCol() const +{ + return storage_->rel_j0; +} - rotgen::Index CLASSNAME::startCol() const - { - return storage_->rel_j0; - } +// Element access by (i,j) +#if !defined(USE_CONST) +TYPE& CLASSNAME::operator()(Index i, Index j) +{ + TYPE* ptr = nullptr; + storage_->apply([&](auto& blk) { ptr = &blk(i, j); }); + return *ptr; +} +#endif - // Element access by (i,j) - #if !defined(USE_CONST) - TYPE& CLASSNAME::operator()(Index i, Index j) - { - TYPE* ptr = nullptr; - storage_->apply([&](auto& blk) { ptr = &blk(i,j); }); - return *ptr; - } - #endif +TYPE CLASSNAME::operator()(Index i, Index j) const +{ + TYPE ptr; + storage_->apply([&](auto const& blk) { ptr = blk(i, j); }); + return ptr; +} - TYPE CLASSNAME::operator()(Index i, Index j) const - { - TYPE ptr; - storage_->apply([&](auto const& blk) { ptr = blk(i,j); }); - return ptr; - } +// Element access by linear index +#if !defined(USE_CONST) +TYPE& CLASSNAME::operator()(Index index) +{ + TYPE* ptr = nullptr; + storage_->apply([&](auto& blk) { ptr = blk.data() + index; }); + return *ptr; +} +#endif - // Element access by linear index - #if !defined(USE_CONST) - TYPE& CLASSNAME::operator()(Index index) - { - TYPE* ptr = nullptr; - storage_->apply([&](auto& blk) { ptr = blk.data() + index; }); - return *ptr; - } - #endif +TYPE CLASSNAME::operator()(Index index) const +{ + TYPE ptr; + storage_->apply([&](auto const& blk) { ptr = *(blk.data() + index); }); + return ptr; +} - TYPE CLASSNAME::operator()(Index index) const - { - TYPE ptr; - storage_->apply([&](auto const& blk) { ptr = *(blk.data() + index); }); - return ptr; - } +// Raw pointer access +#if !defined(USE_CONST) +TYPE* CLASSNAME::data() +{ + TYPE* ptr = nullptr; + storage_->apply([&](auto& blk) { ptr = blk.data(); }); + return ptr; +} +#endif - // Raw pointer access - #if !defined(USE_CONST) - TYPE* CLASSNAME::data() - { - TYPE* ptr = nullptr; - storage_->apply([&](auto& blk) { ptr = blk.data(); }); - return ptr; - } - #endif +TYPE const* CLASSNAME::data() const +{ + TYPE const* ptr = nullptr; + storage_->apply([&](auto const& blk) { ptr = blk.data(); }); + return ptr; +} - TYPE const* CLASSNAME::data() const - { - TYPE const* ptr = nullptr; - storage_->apply([&](auto const& blk) { ptr = blk.data(); }); - return ptr; - } +//================================================================================================== +// Matrix operations +//================================================================================================== +SOURCENAME CLASSNAME::normalized() const +{ + SOURCENAME result; + storage_->apply([&](auto const& blk) { + result.storage()->assign(blk.normalized().eval()); + }); + return result; +} - //================================================================================================== - // Matrix operations - //================================================================================================== - SOURCENAME CLASSNAME::normalized() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.normalized().eval()); }); - return result; - } +SOURCENAME CLASSNAME::transpose() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.transpose().eval()); }); + return result; +} - SOURCENAME CLASSNAME::transpose() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.transpose().eval()); }); - return result; - } +SOURCENAME CLASSNAME::conjugate() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.conjugate().eval()); }); + return result; +} - SOURCENAME CLASSNAME::conjugate() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.conjugate().eval()); }); - return result; - } +SOURCENAME CLASSNAME::adjoint() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.adjoint().eval()); }); + return result; +} - SOURCENAME CLASSNAME::adjoint() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.adjoint().eval()); }); - return result; - } +SOURCENAME CLASSNAME::cwiseAbs() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.cwiseAbs().eval()); }); + return result; +} - SOURCENAME CLASSNAME::cwiseAbs() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseAbs().eval()); }); - return result; - } +SOURCENAME CLASSNAME::cwiseAbs2() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.cwiseAbs2().eval()); }); + return result; +} - SOURCENAME CLASSNAME::cwiseAbs2() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseAbs2().eval()); }); - return result; - } +SOURCENAME CLASSNAME::cwiseInverse() const +{ + SOURCENAME result; + storage_->apply([&](auto const& blk) { + result.storage()->assign(blk.cwiseInverse().eval()); + }); + return result; +} - SOURCENAME CLASSNAME::cwiseInverse() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseInverse().eval()); }); - return result; - } +SOURCENAME CLASSNAME::cwiseSqrt() const +{ + SOURCENAME result; + storage_->apply( + [&](auto const& blk) { result.storage()->assign(blk.cwiseSqrt().eval()); }); + return result; +} - SOURCENAME CLASSNAME::cwiseSqrt() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk.cwiseSqrt().eval()); }); - return result; - } +#if !defined(USE_CONST) +void CLASSNAME::normalize() +{ + storage_->apply([](auto& blk) { blk.normalize(); }); +} - #if !defined(USE_CONST) - void CLASSNAME::normalize() - { - storage_->apply([](auto& blk) { blk.normalize(); }); - } +void CLASSNAME::transposeInPlace() +{ + storage_->apply([](auto& blk) { blk.transposeInPlace(); }); +} - void CLASSNAME::transposeInPlace() - { - storage_->apply([](auto& blk) { blk.transposeInPlace(); }); - } +void CLASSNAME::adjointInPlace() +{ + storage_->apply([](auto& blk) { blk.adjointInPlace(); }); +} +#endif - void CLASSNAME::adjointInPlace() - { - storage_->apply([](auto& blk) { blk.adjointInPlace(); }); - } - #endif +//================================================================================================== +// Reductions +//================================================================================================== +TYPE CLASSNAME::sum() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.sum(); }); + return val; +} - //================================================================================================== - // Reductions - //================================================================================================== - TYPE CLASSNAME::sum() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.sum(); }); - return val; - } +TYPE CLASSNAME::prod() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.prod(); }); + return val; +} - TYPE CLASSNAME::prod() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.prod(); }); - return val; - } +TYPE CLASSNAME::mean() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.mean(); }); + return val; +} - TYPE CLASSNAME::mean() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.mean(); }); - return val; - } +TYPE CLASSNAME::trace() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.trace(); }); + return val; +} - TYPE CLASSNAME::trace() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.trace(); }); - return val; - } +TYPE CLASSNAME::minCoeff() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.minCoeff(); }); + return val; +} - TYPE CLASSNAME::minCoeff() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.minCoeff(); }); - return val; - } +TYPE CLASSNAME::maxCoeff() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.maxCoeff(); }); + return val; +} - TYPE CLASSNAME::maxCoeff() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.maxCoeff(); }); - return val; - } +TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.minCoeff(row, col); }); + return val; +} - TYPE CLASSNAME::minCoeff(Index* row, Index* col) const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.minCoeff(row, col); }); - return val; - } +TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.maxCoeff(row, col); }); + return val; +} - TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.maxCoeff(row, col); }); - return val; - } +TYPE CLASSNAME::squaredNorm() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.squaredNorm(); }); + return val; +} - TYPE CLASSNAME::squaredNorm() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.squaredNorm(); }); - return val; - } +TYPE CLASSNAME::norm() const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { val = blk.norm(); }); + return val; +} - TYPE CLASSNAME::norm() const - { - TYPE val{}; - storage_->apply([&](const auto& blk) { val = blk.norm(); }); - return val; - } +TYPE CLASSNAME::lpNorm(int p) const +{ + TYPE val{}; + storage_->apply([&](auto const& blk) { + if (p == 1) val = blk.template lpNorm<1>(); + else if (p == 2) val = blk.template lpNorm<2>(); + else val = blk.template lpNorm(); + }); + return val; +} - TYPE CLASSNAME::lpNorm(int p) const - { - TYPE val{}; - storage_->apply([&](const auto& blk) - { - if (p == 1) val = blk.template lpNorm<1>(); - else if (p == 2) val = blk.template lpNorm<2>(); - else val = blk.template lpNorm(); - }); - return val; - } +//================================================================================================== +// Operators +//================================================================================================== +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) +{ + m.storage_->apply([&](auto const& blk) { os << blk; }); + return os; +} - //================================================================================================== - // Operators - //================================================================================================== - ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) - { - m.storage_->apply([&](const auto& blk) { os << blk; }); - return os; - } +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, + format const& m) +{ + m.matrix_.storage_->apply( + [&](auto const& blk) { os << blk.format(m.format_.storage()->instance); }); + return os; +} - ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,format const& m) - { - m.matrix_.storage_->apply([&](const auto& blk) { os << blk.format(m.format_.storage()->instance); }); - return os; - } +ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) +{ + return std::visit( + [](auto const& lhs_blk, auto const& rhs_blk) { + return lhs_blk.first == rhs_blk.first; + }, + lhs.storage_->data, rhs.storage_->data); +} - ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) - { - return std::visit ( [](auto const& lhs_blk, auto const& rhs_blk) { return lhs_blk.first == rhs_blk.first; } - , lhs.storage_->data - , rhs.storage_->data - ); - } +ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) +{ + return std::visit( + [](auto const& lhs_blk, auto const& rhs_blk) { + return lhs_blk.first != rhs_blk.first; + }, + lhs.storage_->data, rhs.storage_->data); +} - ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) - { - return std::visit ( [](auto const& lhs_blk, auto const& rhs_blk) { return lhs_blk.first != rhs_blk.first; } - , lhs.storage_->data - , rhs.storage_->data - ); - } +SOURCENAME CLASSNAME::operator-() const +{ + SOURCENAME result; + storage_->apply([&](auto const& blk) { result.storage()->assign(blk); }); + return -result; +} +#if !defined(USE_CONST) +CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) +{ + std::visit( + [](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first += rhs_blk.first; }, + storage_->data, rhs.storage_->data); + return *this; +} - SOURCENAME CLASSNAME::operator-() const - { - SOURCENAME result; - storage_->apply([&](const auto& blk) { result.storage()->assign(blk); }); - return -result; - } +CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) +{ + std::visit( + [](auto& lhs_blk, auto const& rhs_blk) { lhs_blk.first -= rhs_blk.first; }, + storage_->data, rhs.storage_->data); + return *this; +} - #if !defined(USE_CONST) - CLASSNAME& CLASSNAME::operator+=(CLASSNAME 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*=(CLASSNAME 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-=(CLASSNAME 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*=(TYPE s) +{ + storage_->apply([&](auto& blk) { blk *= s; }); + return *this; +} - CLASSNAME& CLASSNAME::operator*=(CLASSNAME 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/=(TYPE s) +{ + storage_->apply([&](auto& blk) { blk /= s; }); + return *this; +} +#endif - CLASSNAME& CLASSNAME::operator*=(TYPE s) - { - storage_->apply([&](auto& blk) { blk *= s; }); - return *this; - } +SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign(std::visit( + [](auto const& lhs_blk, auto const& rhs_blk) { + return (lhs_blk.first + rhs_blk.first).eval(); + }, + storage_->data, rhs.storage_->data)); + return result; +} - CLASSNAME& CLASSNAME::operator/=(TYPE s) - { - storage_->apply([&](auto& blk) { blk /= s; }); - return *this; - } - #endif +SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign(std::visit( + [](auto const& lhs_blk, auto const& rhs_blk) { + return (lhs_blk.first - rhs_blk.first).eval(); + }, + storage_->data, rhs.storage_->data)); + return result; +} - SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign( std::visit( [](auto const& lhs_blk, auto const& rhs_blk) - { - return (lhs_blk.first + rhs_blk.first).eval(); - } - , storage_->data - , rhs.storage_->data - ) - ); - return result; - } +SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign(std::visit( + [](auto const& lhs_blk, auto const& rhs_blk) { + return (lhs_blk.first * rhs_blk.first).eval(); + }, + storage_->data, rhs.storage_->data)); + return result; +} - SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign( std::visit( [](auto const& lhs_blk, auto const& rhs_blk) - { - return (lhs_blk.first - rhs_blk.first).eval(); - } - , storage_->data - , rhs.storage_->data - ) - ); - return result; - } +SOURCENAME CLASSNAME::mul(TYPE s) const +{ + SOURCENAME result; + result.storage()->assign( + std::visit([s](auto const& lhs_blk) { return (lhs_blk.first * s).eval(); }, + storage_->data)); + return result; +} - SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign( std::visit( [](auto const& lhs_blk, auto const& rhs_blk) - { - return (lhs_blk.first * rhs_blk.first).eval(); - } - , storage_->data - , rhs.storage_->data - ) - ); - return result; - } - - SOURCENAME CLASSNAME::mul(TYPE s) const - { - SOURCENAME result; - result.storage()->assign( std::visit( [s](auto const& lhs_blk) - { - return (lhs_blk.first * s).eval(); - } - , storage_->data - ) - ); - return result; - } - - SOURCENAME CLASSNAME::div(TYPE s) const - { - SOURCENAME result; - result.storage()->assign( std::visit( [s](auto const& lhs_blk) - { - return (lhs_blk.first / s).eval(); - } - , storage_->data - ) - ); - return result; - } +SOURCENAME CLASSNAME::div(TYPE s) const +{ + SOURCENAME result; + result.storage()->assign( + std::visit([s](auto const& lhs_blk) { return (lhs_blk.first / s).eval(); }, + storage_->data)); + return result; +} diff --git a/src/format.cpp b/src/format.cpp index 4d74c74..b6a5a98 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -14,14 +14,18 @@ namespace rotgen { - ioformat::ioformat( int p, int f - , std::string const& cs, std::string const& rsp - , std::string const& rp, std::string const& rs - , std::string const& mp, std::string const& ms - , char fill - ) - : storage_(std::make_unique(p,f,cs,rsp,rp,rs,mp,ms,fill)) - {} + ioformat::ioformat(int p, + int f, + std::string const& cs, + std::string const& rsp, + std::string const& rp, + std::string const& rs, + std::string const& mp, + std::string const& ms, + char fill) + : storage_(std::make_unique(p, f, cs, rsp, rp, rs, mp, ms, fill)) + { + } ioformat::~ioformat() = default; -} \ No newline at end of file +} diff --git a/src/info.cpp b/src/info.cpp index 8d1d04a..885c012 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -12,7 +12,8 @@ namespace rotgen::detail { ROTGEN_EXPORT std::ostream& dynamic_info(std::ostream& os) { - if constexpr(rotgen::is_forcing_dynamic_status) return os << "[ROTGEN] - Fully Dynamic mode with:" << std::endl; + if constexpr (rotgen::is_forcing_dynamic_status) + return os << "[ROTGEN] - Fully Dynamic mode with:" << std::endl; else return os << "[ROTGEN] - Flexible mode with:" << std::endl; } -} \ No newline at end of file +} diff --git a/src/map/generate.cpp b/src/map/generate.cpp index 0bfdfac..c6ede29 100644 --- a/src/map/generate.cpp +++ b/src/map/generate.cpp @@ -9,11 +9,11 @@ #define TYPE double #define STORAGE_ORDER Eigen::ColMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) -#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME @@ -23,11 +23,11 @@ #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 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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME @@ -43,11 +43,11 @@ #define TYPE float #define STORAGE_ORDER Eigen::ColMajor -#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_col) -#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME,SIZE,_row) -#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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#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 "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME @@ -57,11 +57,11 @@ #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 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) +#define CLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(BASENAME, SIZE, _col) +#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 "model.cpp" #undef CLASSNAME #undef TRANSCLASSNAME diff --git a/src/map/impl.cpp b/src/map/impl.cpp index 6766b92..6061684 100644 --- a/src/map/impl.cpp +++ b/src/map/impl.cpp @@ -13,19 +13,19 @@ namespace rotgen { - #define USE_CONST - #define CONST const - #define BASENAME map_const_impl - #include "generate.cpp" - #undef BASENAME - #undef USE_CONST - #undef CONST +#define USE_CONST +#define CONST const +#define BASENAME map_const_impl +#include "generate.cpp" +#undef BASENAME +#undef USE_CONST +#undef CONST - #define CONST - #define BASENAME map_impl - #include "generate.cpp" - #undef BASENAME - #undef CONST +#define CONST +#define BASENAME map_impl +#include "generate.cpp" +#undef BASENAME +#undef CONST } #include "operators.cpp" diff --git a/src/map/model.cpp b/src/map/model.cpp index 7171af5..0dbe48a 100644 --- a/src/map/model.cpp +++ b/src/map/model.cpp @@ -16,379 +16,465 @@ // Internal payload //================================================================================================== - //================================================================================================== - // Constructors & Special Members - //================================================================================================== - CLASSNAME::CLASSNAME(TYPE CONST* ptr, Index r, Index c) : storage_(std::make_unique(ptr,r,c)) - {} +//================================================================================================== +// Constructors & Special Members +//================================================================================================== +CLASSNAME::CLASSNAME(TYPE CONST* ptr, Index r, Index c) + : storage_(std::make_unique(ptr, r, c)) +{ +} - CLASSNAME::CLASSNAME(TYPE CONST* ptr, Index r, Index c, stride s) - : storage_(std::make_unique(ptr,r,c,payload::stride_type{s.outer(),s.inner()})) - {} +CLASSNAME::CLASSNAME(TYPE CONST* ptr, Index r, Index c, stride s) + : storage_(std::make_unique( + ptr, r, c, payload::stride_type{s.outer(), s.inner()})) +{ +} - CLASSNAME::CLASSNAME(CLASSNAME const& o) : storage_(std::make_unique(o.storage_->data)) - {} - - #if !defined(USE_CONST) - CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) - { - if (this != &o) storage_->data = o.storage_->data; - return *this; - } - - CLASSNAME& CLASSNAME::operator=(CLASSNAME&& o) - { - if (this != &o) storage_->data = std::move(o.storage_->data); - return *this; - } - #endif - - CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; - - CLASSNAME::~CLASSNAME() = default; - - //================================================================================================== - // Matrix API - //================================================================================================== - rotgen::Index CLASSNAME::rows() const { return storage_->data.rows(); } - rotgen::Index CLASSNAME::cols() const { return storage_->data.cols(); } - rotgen::Index CLASSNAME::size() const { return storage_->data.size(); } - rotgen::Index CLASSNAME::innerStride() const { return storage_->data.innerStride(); } - rotgen::Index CLASSNAME::outerStride() const { return storage_->data.outerStride(); } - - const TYPE* CLASSNAME::data() const { return storage_->data.data(); } - - #if !defined(USE_CONST) - TYPE* CLASSNAME::data() { return storage_->data.data(); } - TYPE& CLASSNAME::operator()(Index i, Index j) { return storage_->data(i,j); } - TYPE& CLASSNAME::operator()(Index i) { return storage_->data.data()[i]; } - #endif - - TYPE CLASSNAME::operator()(Index i, Index j) const { return storage_->data(i,j); } - TYPE CLASSNAME::operator()(Index i) const { return storage_->data.data()[i]; } - - SOURCENAME CLASSNAME::normalized() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.normalized().eval()); - return result; - } - - SOURCENAME CLASSNAME::transpose() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.transpose().eval()); - return result; - } - - SOURCENAME CLASSNAME::conjugate() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.conjugate().eval()); - return result; - } - - SOURCENAME CLASSNAME::adjoint() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.adjoint().eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseAbs() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseAbs().eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseAbs2() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseAbs2().eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseInverse() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseInverse().eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseSqrt() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseSqrt().eval()); - return result; - } - - 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 result; - result.storage()->assign(storage_->data.cwiseMax(rhs.storage()->data).eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseProduct(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseProduct(rhs.storage()->data).eval()); - return result; - } - - SOURCENAME CLASSNAME::cwiseQuotient(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data.cwiseQuotient(rhs.storage()->data).eval()); - return result; - } - - 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 result; - result.storage()->assign(storage_->data.cwiseMax(rhs).eval()); - return result; - } - - SOURCENAME CLASSNAME::inverse() const - { - SOURCENAME result; - result.storage()->assign(storage_->data.inverse().eval()); - return result; - } +CLASSNAME::CLASSNAME(CLASSNAME const& o) + : storage_(std::make_unique(o.storage_->data)) +{ +} #if !defined(USE_CONST) - void CLASSNAME::normalize() - { - storage_->data.normalize(); - } +CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) +{ + if (this != &o) storage_->data = o.storage_->data; + return *this; +} - void CLASSNAME::transposeInPlace() - { - storage_->data.transposeInPlace(); - } - - void CLASSNAME::adjointInPlace() - { - storage_->data.adjointInPlace(); - } +CLASSNAME& CLASSNAME::operator=(CLASSNAME&& o) +{ + if (this != &o) storage_->data = std::move(o.storage_->data); + return *this; +} #endif - TYPE CLASSNAME::dot(CLASSNAME const& rhs) const - { - return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); - } +CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; - TYPE CLASSNAME::dot(TRANSCLASSNAME const& rhs) const - { - return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); - } +CLASSNAME::~CLASSNAME() = default; - TYPE CLASSNAME::sum() const { return storage_->data.sum(); } - TYPE CLASSNAME::prod() const { return storage_->data.prod(); } - TYPE CLASSNAME::mean() const { return storage_->data.mean(); } - TYPE CLASSNAME::trace() const { return storage_->data.trace(); } +//================================================================================================== +// Matrix API +//================================================================================================== +rotgen::Index CLASSNAME::rows() const +{ + return storage_->data.rows(); +} - TYPE CLASSNAME::minCoeff() const { return storage_->data.minCoeff(); } - TYPE CLASSNAME::maxCoeff() const { return storage_->data.maxCoeff(); } +rotgen::Index CLASSNAME::cols() const +{ + return storage_->data.cols(); +} - TYPE CLASSNAME::minCoeff(Index* row, Index* col) const { return storage_->data.minCoeff(row, col); } - TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const { return storage_->data.maxCoeff(row, col); } +rotgen::Index CLASSNAME::size() const +{ + return storage_->data.size(); +} - TYPE CLASSNAME::squaredNorm() const { return storage_->data.squaredNorm(); } - TYPE CLASSNAME::norm() const { return storage_->data.norm(); } +rotgen::Index CLASSNAME::innerStride() const +{ + return storage_->data.innerStride(); +} - TYPE CLASSNAME::lpNorm(int p) const - { - if (p == 1) return storage_->data.lpNorm<1>(); - else if (p == 2) return storage_->data.lpNorm<2>(); - else return storage_->data.lpNorm(); - } +rotgen::Index CLASSNAME::outerStride() const +{ + return storage_->data.outerStride(); +} - #if !defined(USE_CONST) - void CLASSNAME::setZero() - { - storage_->data.setZero(); - } +const TYPE* CLASSNAME::data() const +{ + return storage_->data.data(); +} - void CLASSNAME::setOnes() - { - storage_->data.setOnes(); - } +#if !defined(USE_CONST) +TYPE* CLASSNAME::data() +{ + return storage_->data.data(); +} - void CLASSNAME::setIdentity() - { - storage_->data.setIdentity(); - } +TYPE& CLASSNAME::operator()(Index i, Index j) +{ + return storage_->data(i, j); +} - void CLASSNAME::setRandom() - { - storage_->data.setRandom(); - } +TYPE& CLASSNAME::operator()(Index i) +{ + return storage_->data.data()[i]; +} +#endif - void CLASSNAME::setConstant(TYPE s) - { - storage_->data.setConstant(s); - } - #endif +TYPE CLASSNAME::operator()(Index i, Index j) const +{ + return storage_->data(i, j); +} - //================================================================================================== - // Solvers - //================================================================================================== - SOURCENAME CLASSNAME::qr_solve(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data.colPivHouseholderQr().solve(rhs.storage_->data).eval()); - return result; - } +TYPE CLASSNAME::operator()(Index i) const +{ + return storage_->data.data()[i]; +} - //================================================================================================== - // Operators - //================================================================================================== - ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) - { - return os << m.storage_->data; - } +SOURCENAME CLASSNAME::normalized() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.normalized().eval()); + return result; +} - ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,format const& m) - { - return os << m.matrix_.storage_->data.format(m.format_.storage()->instance); - } +SOURCENAME CLASSNAME::transpose() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.transpose().eval()); + return result; +} - ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) - { - return lhs.storage_->data == rhs.storage_->data; - } +SOURCENAME CLASSNAME::conjugate() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.conjugate().eval()); + return result; +} - ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) - { - return lhs.storage_->data != rhs.storage_->data; - } +SOURCENAME CLASSNAME::adjoint() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.adjoint().eval()); + return result; +} - SOURCENAME CLASSNAME::operator-() const - { - SOURCENAME result; - result.storage()->assign(storage_->data); - return -result; - } +SOURCENAME CLASSNAME::cwiseAbs() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseAbs().eval()); + return result; +} - #if !defined(USE_CONST) - CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) - { - storage_->data += rhs.storage_->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseAbs2() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseAbs2().eval()); + return result; +} - CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs) - { - storage_->data += rhs.storage()->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseInverse() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseInverse().eval()); + return result; +} - CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) - { - storage_->data -= rhs.storage_->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseSqrt() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseSqrt().eval()); + return result; +} - CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs) - { - storage_->data -= rhs.storage()->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseMin(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseMin(rhs.storage()->data).eval()); + return result; +} - CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) - { - storage_->data *= rhs.storage_->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseMax(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseMax(rhs.storage()->data).eval()); + return result; +} - CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs) - { - storage_->data *= rhs.storage()->data; - return *this; - } +SOURCENAME CLASSNAME::cwiseProduct(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign( + storage_->data.cwiseProduct(rhs.storage()->data).eval()); + return result; +} - CLASSNAME& CLASSNAME::operator*=(TYPE s) - { - storage_->data *= s; - return *this; - } +SOURCENAME CLASSNAME::cwiseQuotient(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign( + storage_->data.cwiseQuotient(rhs.storage()->data).eval()); + return result; +} - CLASSNAME& CLASSNAME::operator/=(TYPE s) - { - storage_->data /= s; - return *this; - } - #endif +SOURCENAME CLASSNAME::cwiseMin(TYPE rhs) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseMin(rhs).eval()); + return result; +} - SOURCENAME CLASSNAME::add(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data + rhs.storage_->data); - return result; - } +SOURCENAME CLASSNAME::cwiseMax(TYPE rhs) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.cwiseMax(rhs).eval()); + return result; +} - SOURCENAME CLASSNAME::add(TRANSCLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data + rhs.storage()->data); - return result; - } +SOURCENAME CLASSNAME::inverse() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data.inverse().eval()); + return result; +} - SOURCENAME CLASSNAME::sub(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data - rhs.storage_->data); - return result; - } +#if !defined(USE_CONST) +void CLASSNAME::normalize() +{ + storage_->data.normalize(); +} - SOURCENAME CLASSNAME::sub(TRANSCLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data - rhs.storage()->data); - return result; - } +void CLASSNAME::transposeInPlace() +{ + storage_->data.transposeInPlace(); +} - SOURCENAME CLASSNAME::mul(CLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data * rhs.storage_->data); - return result; - } +void CLASSNAME::adjointInPlace() +{ + storage_->data.adjointInPlace(); +} +#endif - SOURCENAME CLASSNAME::mul(TRANSCLASSNAME const& rhs) const - { - SOURCENAME result; - result.storage()->assign(storage_->data * rhs.storage()->data); - return result; - } +TYPE CLASSNAME::dot(CLASSNAME const& rhs) const +{ + return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); +} - SOURCENAME CLASSNAME::mul(TYPE s) const - { - SOURCENAME result; - result.storage()->assign(storage_->data * s); - return result; - } +TYPE CLASSNAME::dot(TRANSCLASSNAME const& rhs) const +{ + return storage_->data.reshaped().dot(rhs.storage()->data.reshaped()); +} - SOURCENAME CLASSNAME::div(TYPE s) const - { - SOURCENAME result; - result.storage()->assign(storage_->data / s); - return result; - } \ No newline at end of file +TYPE CLASSNAME::sum() const +{ + return storage_->data.sum(); +} + +TYPE CLASSNAME::prod() const +{ + return storage_->data.prod(); +} + +TYPE CLASSNAME::mean() const +{ + return storage_->data.mean(); +} + +TYPE CLASSNAME::trace() const +{ + return storage_->data.trace(); +} + +TYPE CLASSNAME::minCoeff() const +{ + return storage_->data.minCoeff(); +} + +TYPE CLASSNAME::maxCoeff() const +{ + return storage_->data.maxCoeff(); +} + +TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +{ + return storage_->data.minCoeff(row, col); +} + +TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +{ + return storage_->data.maxCoeff(row, col); +} + +TYPE CLASSNAME::squaredNorm() const +{ + return storage_->data.squaredNorm(); +} + +TYPE CLASSNAME::norm() const +{ + return storage_->data.norm(); +} + +TYPE CLASSNAME::lpNorm(int p) const +{ + if (p == 1) return storage_->data.lpNorm<1>(); + else if (p == 2) return storage_->data.lpNorm<2>(); + else return storage_->data.lpNorm(); +} + +#if !defined(USE_CONST) +void CLASSNAME::setZero() +{ + storage_->data.setZero(); +} + +void CLASSNAME::setOnes() +{ + storage_->data.setOnes(); +} + +void CLASSNAME::setIdentity() +{ + storage_->data.setIdentity(); +} + +void CLASSNAME::setRandom() +{ + storage_->data.setRandom(); +} + +void CLASSNAME::setConstant(TYPE s) +{ + storage_->data.setConstant(s); +} +#endif + +//================================================================================================== +// Solvers +//================================================================================================== +SOURCENAME CLASSNAME::qr_solve(CLASSNAME const& rhs) const +{ + SOURCENAME result; + result.storage()->assign( + storage_->data.colPivHouseholderQr().solve(rhs.storage_->data).eval()); + return result; +} + +//================================================================================================== +// Operators +//================================================================================================== +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) +{ + return os << m.storage_->data; +} + +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, + format const& m) +{ + return os << m.matrix_.storage_->data.format(m.format_.storage()->instance); +} + +ROTGEN_EXPORT bool operator==(CLASSNAME const& lhs, CLASSNAME const& rhs) +{ + return lhs.storage_->data == rhs.storage_->data; +} + +ROTGEN_EXPORT bool operator!=(CLASSNAME const& lhs, CLASSNAME const& rhs) +{ + return lhs.storage_->data != rhs.storage_->data; +} + +SOURCENAME CLASSNAME::operator-() const +{ + SOURCENAME result; + result.storage()->assign(storage_->data); + return -result; +} + +#if !defined(USE_CONST) +CLASSNAME& CLASSNAME::operator+=(CLASSNAME const& rhs) +{ + storage_->data += rhs.storage_->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator+=(CLASSCONSTNAME const& rhs) +{ + storage_->data += rhs.storage()->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator-=(CLASSNAME const& rhs) +{ + storage_->data -= rhs.storage_->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator-=(CLASSCONSTNAME const& rhs) +{ + storage_->data -= rhs.storage()->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator*=(CLASSNAME const& rhs) +{ + storage_->data *= rhs.storage_->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator*=(CLASSCONSTNAME const& rhs) +{ + storage_->data *= rhs.storage()->data; + return *this; +} + +CLASSNAME& CLASSNAME::operator*=(TYPE s) +{ + storage_->data *= s; + return *this; +} + +CLASSNAME& CLASSNAME::operator/=(TYPE s) +{ + storage_->data /= s; + return *this; +} +#endif + +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 result; + result.storage()->assign(storage_->data + rhs.storage()->data); + return result; +} + +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 result; + result.storage()->assign(storage_->data - rhs.storage()->data); + return result; +} + +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 result; + result.storage()->assign(storage_->data * rhs.storage()->data); + return result; +} + +SOURCENAME CLASSNAME::mul(TYPE s) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data * s); + return result; +} + +SOURCENAME CLASSNAME::div(TYPE s) const +{ + SOURCENAME result; + result.storage()->assign(storage_->data / s); + return result; +} diff --git a/src/map/operators.cpp b/src/map/operators.cpp index 04ffb41..4d88db2 100644 --- a/src/map/operators.cpp +++ b/src/map/operators.cpp @@ -10,28 +10,75 @@ #include #include -#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); } \ -RET operator OP(map_const_impl32_row const& a, map_impl32_row const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl32_row const& a, map_impl32_col const& b ) { return FN(a, b); } \ -RET operator OP(map_impl32_col const& a, map_impl32_row const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl64_col const& a, map_impl64_col const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl64_col const& a, map_impl64_row const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl64_col const& a, map_const_impl64_row const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl64_row const& a, map_impl64_row const& b ) { return FN(a, b); } \ -RET operator OP(map_const_impl64_row const& a, map_impl64_col const& b ) { return FN(a, b); } \ -RET operator OP(map_impl64_col const& a, map_impl64_row const& b ) { return FN(a, b); } \ +#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); \ + } \ + RET operator OP(map_const_impl32_row const& a, map_impl32_row const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl32_row const& a, map_impl32_col const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_impl32_col const& a, map_impl32_row const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl64_col const& a, map_impl64_col const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl64_col const& a, map_impl64_row const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl64_col const& a, \ + map_const_impl64_row const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl64_row const& a, map_impl64_row const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_const_impl64_row const& a, map_impl64_col const& b) \ + { \ + return FN(a, b); \ + } \ + RET operator OP(map_impl64_col const& a, map_impl64_row const& b) \ + { \ + return FN(a, b); \ + } + /**/ namespace rotgen { namespace { - 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; } + 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(==, equal, bool); ROTGEN_IMPL_OP(!=, not_equal, bool); -} \ No newline at end of file +} diff --git a/src/matrix/impl.cpp b/src/matrix/impl.cpp index f3702a9..5467e82 100644 --- a/src/matrix/impl.cpp +++ b/src/matrix/impl.cpp @@ -13,47 +13,47 @@ namespace rotgen { - #define SIZE 64 - #define TYPE double - #define STORAGE_ORDER Eigen::ColMajor +#define SIZE 64 +#define TYPE double +#define STORAGE_ORDER Eigen::ColMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "model.cpp" - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef STORAGE_ORDER +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include "model.cpp" +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef STORAGE_ORDER - #define STORAGE_ORDER Eigen::RowMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "model.cpp" - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef STORAGE_ORDER +#define STORAGE_ORDER Eigen::RowMajor +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include "model.cpp" +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef STORAGE_ORDER - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float - #define STORAGE_ORDER Eigen::ColMajor +#define SIZE 32 +#define TYPE float +#define STORAGE_ORDER Eigen::ColMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "model.cpp" - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef STORAGE_ORDER +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include "model.cpp" +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef STORAGE_ORDER - #define STORAGE_ORDER Eigen::RowMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "model.cpp" - #undef CLASSNAME - #undef TRANSCLASSNAME - #undef STORAGE_ORDER +#define STORAGE_ORDER Eigen::RowMajor +#define CLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#define TRANSCLASSNAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include "model.cpp" +#undef CLASSNAME +#undef TRANSCLASSNAME +#undef STORAGE_ORDER - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE } diff --git a/src/matrix/model.cpp b/src/matrix/model.cpp index edf4566..af29078 100644 --- a/src/matrix/model.cpp +++ b/src/matrix/model.cpp @@ -15,31 +15,35 @@ //================================================================================================== // Constructors & Special Members //================================================================================================== -CLASSNAME::CLASSNAME() : storage_(std::make_unique(0,0)) {} -CLASSNAME::CLASSNAME(std::size_t r, std::size_t c) : storage_(std::make_unique(r,c)) {} +CLASSNAME::CLASSNAME() : storage_(std::make_unique(0, 0)) {} -CLASSNAME::CLASSNAME(std::initializer_list> init) - : storage_(std::make_unique(init)) -{} - -CLASSNAME::CLASSNAME(std::size_t r, std::size_t c,std::initializer_list init) -: CLASSNAME(r,c) +CLASSNAME::CLASSNAME(std::size_t r, std::size_t c) + : storage_(std::make_unique(r, c)) { - auto first = init.begin(); - 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(std::initializer_list> init) + : storage_(std::make_unique(init)) +{ +} + +CLASSNAME::CLASSNAME(std::size_t r, + std::size_t c, + std::initializer_list init) + : CLASSNAME(r, c) +{ + auto first = init.begin(); + for (std::size_t i = 0; i < init.size(); i++) (*this)(i) = first[i]; +} + +CLASSNAME::CLASSNAME(CLASSNAME const& o) : CLASSNAME(o.rows(), o.cols()) { storage_->data = o.storage_->data; } -CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; +CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; - -CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) +CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) { if (this != &o) storage_->data = o.storage_->data; return *this; @@ -47,14 +51,25 @@ CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) CLASSNAME& CLASSNAME::operator=(CLASSNAME&&) noexcept = default; -CLASSNAME::~CLASSNAME() = default; +CLASSNAME::~CLASSNAME() = default; //================================================================================================== // Matrix API //================================================================================================== -rotgen::Index CLASSNAME::rows() const { return storage_->data.rows(); } -rotgen::Index CLASSNAME::cols() const { return storage_->data.cols(); } -rotgen::Index CLASSNAME::size() const { return storage_->data.size(); } +rotgen::Index CLASSNAME::rows() const +{ + return storage_->data.rows(); +} + +rotgen::Index CLASSNAME::cols() const +{ + return storage_->data.cols(); +} + +rotgen::Index CLASSNAME::size() const +{ + return storage_->data.size(); +} void CLASSNAME::resize(std::size_t new_rows, std::size_t new_cols) { @@ -66,14 +81,35 @@ void CLASSNAME::conservativeResize(std::size_t new_rows, std::size_t new_cols) storage_->data.conservativeResize(new_rows, new_cols); } -TYPE& CLASSNAME::operator()(std::size_t i, std::size_t j) { return storage_->data(i,j); } -TYPE const& CLASSNAME::operator()(std::size_t i, std::size_t j) const { return storage_->data(i,j); } +TYPE& CLASSNAME::operator()(std::size_t i, std::size_t j) +{ + return storage_->data(i, j); +} -TYPE& CLASSNAME::operator()(std::size_t index) { return storage_->data(index); } -TYPE const& CLASSNAME::operator()(std::size_t index) const { return storage_->data(index); } +TYPE const& CLASSNAME::operator()(std::size_t i, std::size_t j) const +{ + return storage_->data(i, j); +} -const TYPE* CLASSNAME::data() const { return storage_->data.data(); } -TYPE* CLASSNAME::data() { return storage_->data.data(); } +TYPE& CLASSNAME::operator()(std::size_t index) +{ + return storage_->data(index); +} + +TYPE const& CLASSNAME::operator()(std::size_t index) const +{ + return storage_->data(index); +} + +const TYPE* CLASSNAME::data() const +{ + return storage_->data.data(); +} + +TYPE* CLASSNAME::data() +{ + return storage_->data.data(); +} CLASSNAME CLASSNAME::normalized() const { @@ -146,36 +182,73 @@ CLASSNAME CLASSNAME::cwiseSqrt() const return result; } -TYPE CLASSNAME::sum() const { return storage_->data.sum(); } -TYPE CLASSNAME::prod() const { return storage_->data.prod(); } -TYPE CLASSNAME::mean() const { return storage_->data.mean(); } -TYPE CLASSNAME::trace() const { return storage_->data.trace(); } +TYPE CLASSNAME::sum() const +{ + return storage_->data.sum(); +} -TYPE CLASSNAME::minCoeff() const { return storage_->data.minCoeff(); } -TYPE CLASSNAME::maxCoeff() const { return storage_->data.maxCoeff(); } +TYPE CLASSNAME::prod() const +{ + return storage_->data.prod(); +} -TYPE CLASSNAME::minCoeff(Index* row, Index* col) const { return storage_->data.minCoeff(row, col); } -TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const { return storage_->data.maxCoeff(row, col); } +TYPE CLASSNAME::mean() const +{ + return storage_->data.mean(); +} -TYPE CLASSNAME::squaredNorm() const { return storage_->data.squaredNorm(); } -TYPE CLASSNAME::norm() const { return storage_->data.norm(); } +TYPE CLASSNAME::trace() const +{ + return storage_->data.trace(); +} + +TYPE CLASSNAME::minCoeff() const +{ + return storage_->data.minCoeff(); +} + +TYPE CLASSNAME::maxCoeff() const +{ + return storage_->data.maxCoeff(); +} + +TYPE CLASSNAME::minCoeff(Index* row, Index* col) const +{ + return storage_->data.minCoeff(row, col); +} + +TYPE CLASSNAME::maxCoeff(Index* row, Index* col) const +{ + return storage_->data.maxCoeff(row, col); +} + +TYPE CLASSNAME::squaredNorm() const +{ + return storage_->data.squaredNorm(); +} + +TYPE CLASSNAME::norm() const +{ + return storage_->data.norm(); +} TYPE CLASSNAME::lp_norm(int p) const { - if (p == 1) return storage_->data.lpNorm<1>(); - else if (p == 2) return storage_->data.lpNorm<2>(); - else return storage_->data.lpNorm(); + if (p == 1) return storage_->data.lpNorm<1>(); + else if (p == 2) return storage_->data.lpNorm<2>(); + else return storage_->data.lpNorm(); } //================================================================================================== // Operators //================================================================================================== -ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,CLASSNAME const& m) +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, CLASSNAME const& m) { return os << m.storage_->data; } -ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os,format const& m) +ROTGEN_EXPORT std::ostream& operator<<(std::ostream& os, + format const& m) { return os << m.matrix_.storage_->data.format(m.format_.storage()->instance); } @@ -248,20 +321,23 @@ CLASSNAME CLASSNAME::Zero(std::size_t rows, std::size_t cols) CLASSNAME CLASSNAME::Constant(std::size_t rows, std::size_t cols, TYPE value) { CLASSNAME m; - m.storage_ = std::make_unique(payload::data_type::Constant(rows, cols, value)); + m.storage_ = + std::make_unique(payload::data_type::Constant(rows, cols, value)); return m; } CLASSNAME CLASSNAME::Random(std::size_t rows, std::size_t cols) { CLASSNAME m; - m.storage_ = std::make_unique(payload::data_type::Random(rows, cols)); + m.storage_ = + std::make_unique(payload::data_type::Random(rows, cols)); return m; } CLASSNAME CLASSNAME::Identity(std::size_t rows, std::size_t cols) { CLASSNAME m; - m.storage_ = std::make_unique(payload::data_type::Identity(rows, cols)); + m.storage_ = + std::make_unique(payload::data_type::Identity(rows, cols)); return m; -} \ No newline at end of file +} diff --git a/src/svd/impl.cpp b/src/svd/impl.cpp index b5d4b4f..7f2c6a7 100644 --- a/src/svd/impl.cpp +++ b/src/svd/impl.cpp @@ -15,47 +15,47 @@ namespace rotgen { - #define SIZE 64 - #define TYPE double - #define STORAGE_ORDER Eigen::ColMajor +#define SIZE 64 +#define TYPE double +#define STORAGE_ORDER Eigen::ColMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "model.cpp" - #undef CLASSNAME - #undef SOURCENAME - #undef STORAGE_ORDER +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _col) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include "model.cpp" +#undef CLASSNAME +#undef SOURCENAME +#undef STORAGE_ORDER - #define STORAGE_ORDER Eigen::RowMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "model.cpp" - #undef CLASSNAME - #undef SOURCENAME - #undef STORAGE_ORDER +#define STORAGE_ORDER Eigen::RowMajor +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _row) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include "model.cpp" +#undef CLASSNAME +#undef SOURCENAME +#undef STORAGE_ORDER - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE - #define SIZE 32 - #define TYPE float - #define STORAGE_ORDER Eigen::ColMajor +#define SIZE 32 +#define TYPE float +#define STORAGE_ORDER Eigen::ColMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_col) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_col) - #include "model.cpp" - #undef CLASSNAME - #undef SOURCENAME - #undef STORAGE_ORDER +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _col) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _col) +#include "model.cpp" +#undef CLASSNAME +#undef SOURCENAME +#undef STORAGE_ORDER - #define STORAGE_ORDER Eigen::RowMajor - #define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl,SIZE,_row) - #define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl,SIZE,_row) - #include "model.cpp" - #undef CLASSNAME - #undef SOURCENAME - #undef STORAGE_ORDER +#define STORAGE_ORDER Eigen::RowMajor +#define CLASSNAME ROTGEN_MATRIX_NAME(svd_impl, SIZE, _row) +#define SOURCENAME ROTGEN_MATRIX_NAME(matrix_impl, SIZE, _row) +#include "model.cpp" +#undef CLASSNAME +#undef SOURCENAME +#undef STORAGE_ORDER - #undef SIZE - #undef TYPE +#undef SIZE +#undef TYPE } diff --git a/src/svd/model.cpp b/src/svd/model.cpp index deb3082..c855b18 100644 --- a/src/svd/model.cpp +++ b/src/svd/model.cpp @@ -17,28 +17,32 @@ //================================================================================================== struct CLASSNAME::payload { - using matrix_type = Eigen::Matrix; + using matrix_type = + Eigen::Matrix; Eigen::JacobiSVD data; - payload(SOURCENAME const& src, int options) : data(src.storage()->data,options) {} + payload(SOURCENAME const& src, int options) + : data(src.storage()->data, options) + { + } }; //================================================================================================== // Constructors & Special Members //================================================================================================== CLASSNAME::CLASSNAME(SOURCENAME const& m, int options) -: storage_(std::make_unique(m,options)) -{} - - -CLASSNAME::CLASSNAME(CLASSNAME const& o) -: storage_(std::make_unique(*o.storage_)) + : storage_(std::make_unique(m, options)) { } -CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; +CLASSNAME::CLASSNAME(CLASSNAME const& o) + : storage_(std::make_unique(*o.storage_)) +{ +} -CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) +CLASSNAME::CLASSNAME(CLASSNAME&&) noexcept = default; + +CLASSNAME& CLASSNAME::operator=(CLASSNAME const& o) { if (this != &o) storage_->data = o.storage_->data; return *this; @@ -52,60 +56,64 @@ CLASSNAME& CLASSNAME::operator=(CLASSNAME&& o) noexcept CLASSNAME::~CLASSNAME() = default; -int CLASSNAME::rank() const { return storage_->data.rank(); } +int CLASSNAME::rank() const +{ + return storage_->data.rank(); +} -SOURCENAME CLASSNAME::U() const +SOURCENAME CLASSNAME::U() const { SOURCENAME result; result.storage()->assign(storage_->data.matrixU()); return result; } -SOURCENAME CLASSNAME::U(int r) const +SOURCENAME CLASSNAME::U(int r) const { SOURCENAME result; - result.storage()->assign( storage_->data.matrixU().leftCols(r) ); + result.storage()->assign(storage_->data.matrixU().leftCols(r)); return result; } -SOURCENAME CLASSNAME::singular_values() const +SOURCENAME CLASSNAME::singular_values() const { SOURCENAME result; result.storage()->assign(storage_->data.singularValues()); return result; } -SOURCENAME CLASSNAME::singular_values(int r) const +SOURCENAME CLASSNAME::singular_values(int r) const { SOURCENAME result; result.storage()->assign(storage_->data.singularValues().head(r)); return result; } -SOURCENAME CLASSNAME::D() const +SOURCENAME CLASSNAME::D() const { SOURCENAME result; result.storage()->assign(storage_->data.singularValues().asDiagonal()); return result; } -SOURCENAME CLASSNAME::D(int r) const +SOURCENAME CLASSNAME::D(int r) const { SOURCENAME result; - result.storage()->assign(storage_->data.singularValues().head(r).asDiagonal()); + result.storage()->assign( + storage_->data.singularValues().head(r).asDiagonal()); return result; } -SOURCENAME CLASSNAME::V() const +SOURCENAME CLASSNAME::V() const { SOURCENAME result; result.storage()->assign(storage_->data.matrixV()); return result; } -SOURCENAME CLASSNAME::V(int r) const +SOURCENAME CLASSNAME::V(int r) const { SOURCENAME result; - result.storage()->assign( storage_->data.matrixV().leftCols(r) ); + result.storage()->assign(storage_->data.matrixV().leftCols(r)); return result; } diff --git a/test/integration/aliasing.cpp b/test/integration/aliasing.cpp index 51cf9d6..b0fc84f 100644 --- a/test/integration/aliasing.cpp +++ b/test/integration/aliasing.cpp @@ -8,40 +8,46 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("noalias behavior - dynamicallly sized", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("noalias behavior - dynamicallly sized", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a{{1,2},{3,4}}; - rotgen::matrix ref{{7,10},{15,22}}; - rotgen::matrix b(2,2),c(2,2),d(2,2); + rotgen::matrix a{{1, 2}, + {3, 4}}; + rotgen::matrix ref{{7, 10}, + {15, 22}}; + rotgen::matrix b(2, 2), + c(2, 2), d(2, 2); rotgen::noalias(b) = a * a; TTS_EQUAL(b, ref); - auto e = rotgen::extract(c,0,0,2,2); + auto e = rotgen::extract(c, 0, 0, 2, 2); rotgen::noalias(e) = a * a; TTS_EQUAL(c, ref); - rotgen::map> m(d.data(),2,2); + rotgen::map> m( + d.data(), 2, 2); rotgen::noalias(m) = a * a; TTS_EQUAL(m, ref); }; -TTS_CASE_TPL("noalias behavior - statically sized", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("noalias behavior - statically sized", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a{{1,2},{3,4}}; - rotgen::matrix ref{{7,10},{15,22}}; - rotgen::matrix b,c,d; + rotgen::matrix a{{1, 2}, {3, 4}}; + rotgen::matrix ref{{7, 10}, {15, 22}}; + rotgen::matrix b, c, d; rotgen::noalias(b) = a * a; TTS_EQUAL(b, ref); - auto e = rotgen::extract(c,0,0,2,2); + auto e = rotgen::extract(c, 0, 0, 2, 2); rotgen::noalias(e) = a * a; TTS_EQUAL(c, ref); - rotgen::map> m(d.data()); + rotgen::map> m(d.data()); rotgen::noalias(m) = a * a; TTS_EQUAL(m, ref); -}; \ No newline at end of file +}; diff --git a/test/integration/extract.cpp b/test/integration/extract.cpp index 864213a..cf54fe0 100644 --- a/test/integration/extract.cpp +++ b/test/integration/extract.cpp @@ -8,63 +8,67 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("Chains of extraction", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Chains of extraction", + rotgen::tests::types)( + tts::type>) { constexpr int N = 8; - auto a = rotgen::matrix::Random(); + auto a = rotgen::matrix::Random(); - auto b = topLeftCorner(a,5,5); + auto b = topLeftCorner(a, 5, 5); TTS_EQUAL(b.startRow(), 0); TTS_EQUAL(b.startCol(), 0); - setConstant(b,-7); + 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); + 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); + auto bb = bottomRightCorner(b, 3, 3); TTS_EQUAL(bb.startRow(), 2); TTS_EQUAL(bb.startCol(), 2); - setConstant(bb,42); + 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); + 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); + auto bbb = row(bb, 1); TTS_EQUAL(bbb.startRow(), 1); TTS_EQUAL(bbb.startCol(), 0); - setConstant(bbb,99.5); + setConstant(bbb, 99.5); - for(rotgen::Index c=3;c<5;c++) - TTS_EQUAL(a(3,c), 99.5); + for (rotgen::Index c = 3; c < 5; c++) TTS_EQUAL(a(3, c), 99.5); - auto bbbb = col(bbb,1); + auto bbbb = col(bbb, 1); TTS_EQUAL(bbbb.startRow(), 0); TTS_EQUAL(bbbb.startCol(), 1); - setConstant(bbbb,0.125); + setConstant(bbbb, 0.125); - TTS_EQUAL(a(3,3), 0.125); + TTS_EQUAL(a(3, 3), 0.125); }; -auto ref_extract ( rotgen::ref > m) { return rotgen::extract(m,0,0,3,4); } -auto ref_cextract( rotgen::ref > m) { return rotgen::extract(m,3,4,4,3); } +auto ref_extract(rotgen::ref> m) +{ + return rotgen::extract(m, 0, 0, 3, 4); +} + +auto ref_cextract(rotgen::ref const> m) +{ + return rotgen::extract(m, 3, 4, 4, 3); +} TTS_CASE("Extraction of ref/ref const") { - auto m = rotgen::setRandom>(); + auto m = rotgen::setRandom>(); auto extracted = ref_extract(m); - extracted = rotgen::setOnes>(); + extracted = rotgen::setOnes>(); - for(rotgen::Index r=0;r<3;r++) - for(rotgen::Index c=0;c<4;c++) - TTS_EQUAL(m(r,c), 1.f); + for (rotgen::Index r = 0; r < 3; r++) + for (rotgen::Index c = 0; c < 4; c++) TTS_EQUAL(m(r, c), 1.f); auto sliced = ref_cextract(m); - rotgen::extract(m,3,4,4,3) = rotgen::setConstant>(5); - for(rotgen::Index r=0;r<4;r++) - for(rotgen::Index c=0;c<3;c++) - TTS_EQUAL(sliced(r,c), 5.f); -}; \ No newline at end of file + rotgen::extract(m, 3, 4, 4, 3) = + rotgen::setConstant>(5); + for (rotgen::Index r = 0; r < 4; r++) + for (rotgen::Index c = 0; c < 3; c++) TTS_EQUAL(sliced(r, c), 5.f); +}; diff --git a/test/integration/io.cpp b/test/integration/io.cpp index be69613..ca3eee9 100644 --- a/test/integration/io.cpp +++ b/test/integration/io.cpp @@ -9,76 +9,81 @@ #include #include -TTS_CASE_TPL("I/O for matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("I/O for matrix", rotgen::tests::types)( + tts::type>) { - rotgen::matrix x({ {1,2} , {3,4} }); + rotgen::matrix x( + {{1, 2}, {3, 4}}); std::ostringstream os; os << x; TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); }; -TTS_CASE_TPL("I/O for block", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("I/O for block", rotgen::tests::types)( + tts::type>) { - rotgen::matrix base({ {1,2} , {3,4} }); + rotgen::matrix base( + {{1, 2}, {3, 4}}); - auto x = rotgen::extract(base,0,0,2,2); + auto x = rotgen::extract(base, 0, 0, 2, 2); std::ostringstream os; os << x; TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); }; -TTS_CASE_TPL("I/O for map test", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("I/O for map test", rotgen::tests::types)( + tts::type>) { - using base = rotgen::matrix; + using base = rotgen::matrix; - T data[] = {1,2,3,4}; + T data[] = {1, 2, 3, 4}; - rotgen::map x(data,2,2); + rotgen::map x(data, 2, 2); std::ostringstream os; os << x; - if constexpr(O::value) TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); - else TTS_EQUAL(os.str(), std::string{"1 3\n2 4"}); + if constexpr (O::value) TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); + else TTS_EQUAL(os.str(), std::string{"1 3\n2 4"}); }; -TTS_CASE_TPL("I/O using format", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("I/O using format", rotgen::tests::types)( + tts::type>) { - rotgen::ioformat io(rotgen::StreamPrecision, 0, ", ", ";\n", "<", ">", "[", "]"); + rotgen::ioformat io(rotgen::StreamPrecision, 0, ", ", ";\n", "<", ">", "[", + "]"); - rotgen::matrix x({ {1,2} , {3,4} }); + rotgen::matrix x( + {{1, 2}, {3, 4}}); { std::ostringstream os; - os << rotgen::format(x,io); + os << rotgen::format(x, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } - rotgen::map> m{x.data()}; + rotgen::map> m{x.data()}; { std::ostringstream os; - os << rotgen::format(m,io); + os << rotgen::format(m, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } - auto b = rotgen::extract(x,0,0,2,2); + auto b = rotgen::extract(x, 0, 0, 2, 2); { std::ostringstream os; - os << rotgen::format(b,io); + os << rotgen::format(b, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } - auto printer = [&](rotgen::ref> r) - { - std::ostringstream st; - st << rotgen::format(r,io); - return st.str(); - }; + auto printer = + [&](rotgen::ref const> r) { + std::ostringstream st; + st << rotgen::format(r, io); + return st.str(); + }; TTS_EQUAL(printer(x), std::string{"[<1, 2>;\n <3, 4>]"}); TTS_EQUAL(printer(m), std::string{"[<1, 2>;\n <3, 4>]"}); diff --git a/test/integration/outer_stride.cpp b/test/integration/outer_stride.cpp index 19db74c..ebd8c5a 100644 --- a/test/integration/outer_stride.cpp +++ b/test/integration/outer_stride.cpp @@ -9,75 +9,94 @@ #include #include -TTS_CASE_TPL("outer_stride<0> interactions", rotgen::tests::types) -( tts::type< tts::types> ) +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}; + T contiguous[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; rotgen::map> m(&contiguous[0], 4, 3); TTS_EQUAL(m.innerStride(), 1); TTS_EQUAL(m.outerStride(), O::value == rotgen::ColMajor ? 4 : 3); - if constexpr(O::value == rotgen::ColMajor) + if constexpr (O::value == rotgen::ColMajor) { - T padded[] = {1,2,3,4, 99, 5,6,7,8, 99,9,10,11,12}; + T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); TTS_EQUAL(sp.innerStride(), 1); TTS_EQUAL(sp.outerStride(), 5); - rotgen::map> dp(&padded[0], 4, 3,rotgen::outer_stride(5)); + rotgen::map> dp(&padded[0], 4, 3, + rotgen::outer_stride(5)); TTS_EQUAL(dp.innerStride(), 1); TTS_EQUAL(dp.outerStride(), 5); - TTS_EQUAL(m , sp); - TTS_EQUAL(m , dp); + TTS_EQUAL(m, sp); + TTS_EQUAL(m, dp); TTS_EQUAL(dp, sp); } else { - T padded[] = {1,2,3, 99, 4,5,6, 99, 7,8,9, 99, 10,11,12}; + T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); TTS_EQUAL(sp.innerStride(), 1); TTS_EQUAL(sp.outerStride(), 4); - rotgen::map> dp(&padded[0], 4, 3,rotgen::outer_stride(4)); + rotgen::map> dp(&padded[0], 4, 3, + rotgen::outer_stride(4)); TTS_EQUAL(dp.innerStride(), 1); TTS_EQUAL(dp.outerStride(), 4); - TTS_EQUAL(m , sp); - TTS_EQUAL(m , dp); + TTS_EQUAL(m, sp); + TTS_EQUAL(m, dp); TTS_EQUAL(dp, sp); } }; -void process_ref(rotgen::ref> ) {} -void process_ref(rotgen::ref>) {} -void process_ref(rotgen::ref>) {} -void process_ref(rotgen::ref>) {} +void process_ref(rotgen::ref const>) {} -TTS_CASE_TPL("Extraction of outer_stride blocks", rotgen::tests::types) -( tts::type< tts::types> ) +void process_ref(rotgen::ref const>) {} + +void process_ref( + rotgen::ref< + rotgen:: + matrix const>) +{ +} + +void process_ref( + rotgen::ref< + rotgen:: + matrix const>) +{ +} + +TTS_CASE_TPL("Extraction of outer_stride blocks", + rotgen::tests::types)( + tts::type>) { using mat_t = rotgen::matrix; - if constexpr(O::value == rotgen::ColMajor) + if constexpr (O::value == rotgen::ColMajor) { - T padded[] = {1,2,3,4, 99, 5,6,7,8, 99,9,10,11,12}; + T padded[] = {1, 2, 3, 4, 99, 5, 6, 7, 8, 99, 9, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); - rotgen::map> dp(&padded[0], 4, 3,rotgen::outer_stride(5)); + rotgen::map> dp(&padded[0], 4, 3, + rotgen::outer_stride(5)); - TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp,0, 0, 3, 2)); } ); - TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp,0, 0, 3, 2)); } ); + TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp, 0, 0, 3, 2)); }); + TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp, 0, 0, 3, 2)); }); } else { - T padded[] = {1,2,3, 99, 4,5,6, 99, 7,8,9, 99, 10,11,12}; + T padded[] = {1, 2, 3, 99, 4, 5, 6, 99, 7, 8, 9, 99, 10, 11, 12}; rotgen::map> sp(&padded[0], 4, 3); - rotgen::map> dp(&padded[0], 4, 3,rotgen::outer_stride(4)); + rotgen::map> dp(&padded[0], 4, 3, + rotgen::outer_stride(4)); - TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp,0, 0, 3, 2)); } ); - TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp,0, 0, 3, 2)); } ); + TTS_EXPECT_COMPILES(sp, { process_ref(extract(sp, 0, 0, 3, 2)); }); + TTS_EXPECT_COMPILES(dp, { process_ref(extract(dp, 0, 0, 3, 2)); }); } }; diff --git a/test/integration/ref_magic.cpp b/test/integration/ref_magic.cpp index 7a04e93..9ec210e 100644 --- a/test/integration/ref_magic.cpp +++ b/test/integration/ref_magic.cpp @@ -8,7 +8,9 @@ #include "unit/tests.hpp" #include -template +template using column = rotgen::matrix; template @@ -17,22 +19,27 @@ using column_ref = rotgen::ref>; template using const_column_ref = rotgen::ref const>; - -template -void process( column_ref v ) +template void process(column_ref v) { v(0) = rotgen::sum(v); } -auto process( column_ref<> v ) +auto process(column_ref<> v) { auto sz = v.size(); - switch(sz) + switch (sz) { - case 1 : process<1>(v); break; - case 2 : process<2>(v); break; - case 3 : process<3>(v); break; - default: break; + case 1: + process<1>(v); + break; + case 2: + process<2>(v); + break; + case 3: + process<3>(v); + break; + default: + break; } return sz; @@ -40,9 +47,9 @@ auto process( column_ref<> v ) TTS_CASE("Reference of reference check") { - auto v1 = rotgen::matrix::Ones(); - auto v2 = rotgen::matrix::Random(); - auto v3 = rotgen::matrix::Constant(6.66); + auto v1 = rotgen::matrix::Ones(); + auto v2 = rotgen::matrix::Random(); + auto v3 = rotgen::matrix::Constant(6.66); auto sum1 = v1(0); auto sum2 = v2(0) + v2(1); @@ -55,4 +62,4 @@ TTS_CASE("Reference of reference check") TTS_EQUAL(v1[0], sum1); TTS_EQUAL(v2[0], sum2); TTS_EQUAL(v3[0], sum3); -}; \ No newline at end of file +}; diff --git a/test/unit/block/arithmetic_functions.cpp b/test/unit/block/arithmetic_functions.cpp index c40bb86..8dd3128 100644 --- a/test/unit/block/arithmetic_functions.cpp +++ b/test/unit/block/arithmetic_functions.cpp @@ -9,104 +9,104 @@ #include "unit/common/arithmetic.hpp" #include -TTS_CASE_TPL("Test dynamic block transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic block transposition-like operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::tests::check_shape_functions(input); } }; -TTS_CASE_TPL("Test static block transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static block transposition-like operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); rotgen::tests::check_shape_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic block reduction-like operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::tests::check_reduction_functions(input); } }; -TTS_CASE_TPL("Test static block reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static block reduction-like operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); rotgen::tests::check_reduction_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; +TTS_CASE_TPL("Test dot product", float, double)(tts::type){ + {auto v = rotgen::setConstant>(1, + 16, + 2); +auto a = rotgen::head(v, 8); +auto b = rotgen::tail(v, 8); +TTS_EQUAL(rotgen::dot(a, b), 32); +} -TTS_CASE_TPL("Test dot product", float, double) -( tts::type ) { - { - auto v = rotgen::setConstant>(1,16,2); - auto a = rotgen::head(v,8); - auto b = rotgen::tail(v,8); + auto v = rotgen::setConstant>(16, 1, 2); + auto a = rotgen::head(v, 8); + auto b = rotgen::tail(v, 8); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto v = rotgen::setConstant>(16,1,2); - auto a = rotgen::head(v,8); - auto b = rotgen::tail(v,8); +{ + auto v = rotgen::setConstant>(1, 16, 2); + auto a = rotgen::head<8>(v); + auto b = rotgen::tail<8>(v); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto v = rotgen::setConstant>(1,16,2); - auto a = rotgen::head<8>(v); - auto b = rotgen::tail<8>(v); +{ + auto v = rotgen::setConstant>(16, 1, 2); + auto a = rotgen::head<8>(v); + auto b = rotgen::tail<8>(v); - TTS_EQUAL(rotgen::dot(a,b), 32); - } - - { - auto v = rotgen::setConstant>(16,1,2); - auto a = rotgen::head<8>(v); - auto b = rotgen::tail<8>(v); - - TTS_EQUAL(rotgen::dot(a,b), 32); - } -}; \ No newline at end of file + TTS_EQUAL(rotgen::dot(a, b), 32); +} +} +; diff --git a/test/unit/block/basic_api.cpp b/test/unit/block/basic_api.cpp index 0a5015f..a0ac871 100644 --- a/test/unit/block/basic_api.cpp +++ b/test/unit/block/basic_api.cpp @@ -12,109 +12,116 @@ // NB: This function must not be turned into a lambda, otherwise // `test-ubuntu-gcc-release` will not pass and the CI will fail. // This is likely due to a compilation bug from GCC 13.3.0. -void fill(auto &m, int r, int c, auto data[]) { - for (int k = 0; k < r * c; ++k) - m.data()[k] = data[k]; +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}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // 1x12 dynamic block at (0,0) - rotgen::matrix dm(1,12); - fill(dm,1,12,data); - auto b1 = rotgen::block(dm, 0,0,1,12); + rotgen::matrix dm(1, 12); + fill(dm, 1, 12, data); + auto b1 = rotgen::block( + dm, 0, 0, 1, 12); TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{12}); // 1x5 dynamic block at (0,2) - auto b2 = rotgen::block(dm, 0,2,1,5); + auto b2 = rotgen::block( + dm, 0, 2, 1, 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); + rotgen::matrix dm2(4, 6); + fill(dm2, 4, 6, data); + auto b3 = rotgen::block( + dm2, 1, 4, 3, 2); TTS_EQUAL(b3.rows(), rotgen::Index{3}); TTS_EQUAL(b3.cols(), rotgen::Index{2}); TTS_EQUAL(b3.size(), rotgen::Index{6}); // 3x4 static block - rotgen::matrix sm; - fill(sm,3,4,data); - auto b4 = rotgen::block(sm, 0,0); + rotgen::matrix sm; + fill(sm, 3, 4, data); + auto b4 = rotgen::block(sm, 0, 0); TTS_EQUAL(b4.rows(), rotgen::Index{3}); TTS_EQUAL(b4.cols(), rotgen::Index{4}); TTS_EQUAL(b4.size(), rotgen::Index{12}); // 6x2 static block - rotgen::matrix sm2; - fill(sm2,6,2,data); - auto b5 = rotgen::block(sm2, 0,0); + rotgen::matrix sm2; + fill(sm2, 6, 2, data); + auto b5 = rotgen::block(sm2, 0, 0); TTS_EQUAL(b5.rows(), rotgen::Index{6}); TTS_EQUAL(b5.cols(), rotgen::Index{2}); TTS_EQUAL(b5.size(), rotgen::Index{12}); }; -TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test coefficient accessors", + rotgen::tests::types)( + tts::type>) { - using base = rotgen::matrix; + using base = rotgen::matrix; - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; - base mat(4,3); - for(int k=0;k<12;++k) mat.data()[k] = data[k]; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + base mat(4, 3); + for (int k = 0; k < 12; ++k) mat.data()[k] = data[k]; - auto b = rotgen::block(mat, 0, 0, 4, 3); - for(rotgen::Index i=0;i<4;i++) + auto b = + rotgen::block(mat, 0, 0, 4, 3); + for (rotgen::Index i = 0; i < 4; i++) { - for(rotgen::Index j=0;j<3;j++) + for (rotgen::Index j = 0; j < 3; j++) { - if constexpr(O::value) TTS_EQUAL(b(i,j), data[j+3*i]); - else TTS_EQUAL(b(i,j), data[i+4*j]); + if constexpr (O::value) TTS_EQUAL(b(i, j), data[j + 3 * i]); + else TTS_EQUAL(b(i, j), data[i + 4 * j]); } } b(1, 1) = 42; - TTS_EQUAL(b(1,1), 42); + TTS_EQUAL(b(1, 1), 42); T& ref = b(2, 2); ref = 17; TTS_EQUAL(b(2, 2), 17); }; -TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test one index coefficient accessors", + rotgen::tests::types)( + tts::type>) { - auto vs = [&]() - { - if constexpr(O::value == rotgen::ColMajor) + auto vs = [&]() { + if constexpr (O::value == rotgen::ColMajor) { - using base = rotgen::matrix; + using base = rotgen::matrix; base m(12); - for(int k=0;k<12;++k) m(k) = k+1; - return std::tuple{m,rotgen::block(m, 0, 0, 1, 12)}; + for (int k = 0; k < 12; ++k) m(k) = k + 1; + return std::tuple{ + m, rotgen::block(m, 0, 0, 1, 12)}; } else { - using base = rotgen::matrix; + using base = rotgen::matrix; base m(12); - for(int k=0;k<12;++k) m(k) = k+1; - return std::tuple{m,rotgen::block(m, 0, 0, 12, 1)}; + for (int k = 0; k < 12; ++k) m(k) = k + 1; + return std::tuple{ + m, rotgen::block(m, 0, 0, 12, 1)}; } }(); auto mat = get<0>(vs); - auto b = get<1>(vs); + auto b = get<1>(vs); TTS_EXPECT(b.IsVectorAtCompileTime); - for(rotgen::Index i=0;i -TTS_CASE_TPL("Test dynamic block cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic block cwise operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::tests::check_cwise_functions(input); } }; -TTS_CASE_TPL("Test static block cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static block cwise operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); rotgen::tests::check_cwise_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; diff --git a/test/unit/block/extract.cpp b/test/unit/block/extract.cpp index 318caa9..e883a8f 100644 --- a/test/unit/block/extract.cpp +++ b/test/unit/block/extract.cpp @@ -11,41 +11,44 @@ template void for_each_element(EigenType const& m, F&& f) { - for(rotgen::Index i = 0; i < m.rows(); ++i) - for(rotgen::Index j = 0; j < m.cols(); ++j) - f(i, j, m(i,j)); + for (rotgen::Index i = 0; i < 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 < m.rows(); ++i) - for(rotgen::Index j = 0; j < m.cols(); ++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 -MatrixType make_initialized_matrix(rotgen::tests::matrix_block_test_case const& matrix_construct) +MatrixType make_initialized_matrix( + rotgen::tests::matrix_block_test_case const& matrix_construct) { - auto[d,i0,j0,ni,nj] = matrix_construct; - auto[r,c,fn] = d; + auto [d, i0, j0, ni, nj] = matrix_construct; + auto [r, c, fn] = d; MatrixType matrix; - if constexpr(MatrixType::RowsAtCompileTime == -1 &&MatrixType::ColsAtCompileTime == -1) + if constexpr (MatrixType::RowsAtCompileTime == -1 && + MatrixType::ColsAtCompileTime == -1) rotgen::resize(matrix, r, c); - for(rotgen::Index i = 0; i < r; ++i) - for(rotgen::Index j = 0; j < c; ++j) + for (rotgen::Index i = 0; i < r; ++i) + for (rotgen::Index j = 0; j < c; ++j) matrix(i, j) = static_cast(fn(i, j)); return matrix; } template -void validate_block_behavior(MatrixType& matrix, BlockType& block, - rotgen::Index block_i, rotgen::Index block_j, - rotgen::Index block_m, rotgen::Index block_n) +void validate_block_behavior(MatrixType& matrix, + BlockType& block, + rotgen::Index block_i, + rotgen::Index block_j, + rotgen::Index block_m, + rotgen::Index block_n) { using T = typename MatrixType::value_type; TTS_EQUAL(block.rows(), block_m); @@ -58,12 +61,11 @@ void validate_block_behavior(MatrixType& matrix, BlockType& block, }); // test aliasing if non immutable - if constexpr(!BlockType::is_immutable) + if constexpr (!BlockType::is_immutable) { T value = 1; - for_each_element(block, [&](auto i, auto j, auto&) { - block(i, j) = value++; - }); + for_each_element(block, + [&](auto i, auto j, auto&) { block(i, j) = value++; }); value = 1; for_each_element(block, [&](auto i, auto j, auto&) { @@ -81,99 +83,140 @@ void validate_block_behavior(MatrixType& matrix, BlockType& block, } template -void test_dynamic_block_extraction(rotgen::tests::matrix_block_test_case const& matrix_construct) +void test_dynamic_block_extraction( + rotgen::tests::matrix_block_test_case const& matrix_construct) { MatrixType matrix = make_initialized_matrix(matrix_construct); MatrixType const c_matrix = matrix; - auto c_block_main = rotgen::extract(c_matrix, matrix_construct.i0, matrix_construct.j0, - matrix_construct.ni, matrix_construct.nj); - auto c_block_top_left_corner = rotgen::topLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); - auto c_block_top_right_corner = rotgen::topRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); - auto c_block_bottom_left_corner = rotgen::bottomLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); - auto c_block_bottom_right_corner = rotgen::bottomRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); + auto c_block_main = + rotgen::extract(c_matrix, matrix_construct.i0, matrix_construct.j0, + matrix_construct.ni, matrix_construct.nj); + auto c_block_top_left_corner = + rotgen::topLeftCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); + auto c_block_top_right_corner = + rotgen::topRightCorner(c_matrix, matrix_construct.ni, matrix_construct.nj); + auto c_block_bottom_left_corner = rotgen::bottomLeftCorner( + c_matrix, matrix_construct.ni, matrix_construct.nj); + auto c_block_bottom_right_corner = rotgen::bottomRightCorner( + c_matrix, matrix_construct.ni, matrix_construct.nj); - auto c_block_top_rows = rotgen::topRows(c_matrix, matrix_construct.ni); - auto c_block_middle_rows = rotgen::middleRows(c_matrix, matrix_construct.i0, matrix_construct.ni); - auto c_block_bottom_rows = rotgen::bottomRows(c_matrix, matrix_construct.ni); + auto c_block_top_rows = rotgen::topRows(c_matrix, matrix_construct.ni); + auto c_block_middle_rows = + rotgen::middleRows(c_matrix, matrix_construct.i0, matrix_construct.ni); + auto c_block_bottom_rows = rotgen::bottomRows(c_matrix, matrix_construct.ni); - auto c_block_left_cols = rotgen::leftCols(c_matrix, matrix_construct.nj); - auto c_block_middle_cols = rotgen::middleCols(c_matrix, matrix_construct.j0, matrix_construct.nj); - auto c_block_right_cols = rotgen::rightCols(c_matrix, matrix_construct.nj); + auto c_block_left_cols = rotgen::leftCols(c_matrix, matrix_construct.nj); + auto c_block_middle_cols = + rotgen::middleCols(c_matrix, matrix_construct.j0, matrix_construct.nj); + auto c_block_right_cols = rotgen::rightCols(c_matrix, matrix_construct.nj); - auto block_main = rotgen::extract(matrix, matrix_construct.i0, matrix_construct.j0, - matrix_construct.ni, matrix_construct.nj); - auto block_top_left_corner = rotgen::topLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj); - auto block_top_right_corner = rotgen::topRightCorner(matrix, matrix_construct.ni, matrix_construct.nj); - auto block_bottom_left_corner = rotgen::bottomLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj); - auto block_bottom_right_corner = rotgen::bottomRightCorner(matrix, matrix_construct.ni, matrix_construct.nj); + auto block_main = + rotgen::extract(matrix, matrix_construct.i0, matrix_construct.j0, + matrix_construct.ni, matrix_construct.nj); + auto block_top_left_corner = + rotgen::topLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj); + auto block_top_right_corner = + rotgen::topRightCorner(matrix, matrix_construct.ni, matrix_construct.nj); + auto block_bottom_left_corner = + rotgen::bottomLeftCorner(matrix, matrix_construct.ni, matrix_construct.nj); + auto block_bottom_right_corner = + rotgen::bottomRightCorner(matrix, matrix_construct.ni, matrix_construct.nj); - auto block_top_rows = rotgen::topRows(matrix, matrix_construct.ni); - auto block_middle_rows = rotgen::middleRows(matrix, matrix_construct.i0, matrix_construct.ni); - auto block_bottom_rows = rotgen::bottomRows(matrix, matrix_construct.ni); + auto block_top_rows = rotgen::topRows(matrix, matrix_construct.ni); + auto block_middle_rows = + rotgen::middleRows(matrix, matrix_construct.i0, matrix_construct.ni); + auto block_bottom_rows = rotgen::bottomRows(matrix, matrix_construct.ni); - auto block_left_cols = rotgen::leftCols(matrix, matrix_construct.nj); - auto block_middle_cols = rotgen::middleCols(matrix, matrix_construct.j0, matrix_construct.nj); - auto block_right_cols = rotgen::rightCols(matrix, matrix_construct.nj); + auto block_left_cols = rotgen::leftCols(matrix, matrix_construct.nj); + auto block_middle_cols = + rotgen::middleCols(matrix, matrix_construct.j0, matrix_construct.nj); + auto block_right_cols = rotgen::rightCols(matrix, matrix_construct.nj); auto blocks = std::make_tuple( // --- CONST TESTS - std::make_tuple(c_block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(c_block_top_right_corner, 0, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(c_block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(c_block_bottom_right_corner, matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj, + std::make_tuple(c_block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj), + std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(c_block_top_right_corner, 0, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(c_block_bottom_left_corner, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(c_block_bottom_right_corner, + matrix.rows() - matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj), std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols()), - std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, matrix_construct.ni, matrix.cols()), - std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix.cols()), + std::make_tuple(c_block_middle_rows, matrix_construct.i0, 0, + matrix_construct.ni, matrix.cols()), + std::make_tuple(c_block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, + matrix_construct.ni, matrix.cols()), - std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj), - std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj), - std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, matrix.rows(), matrix_construct.nj), + std::make_tuple(c_block_left_cols, 0, 0, matrix.rows(), + matrix_construct.nj), + std::make_tuple(c_block_middle_cols, 0, matrix_construct.j0, matrix.rows(), + matrix_construct.nj), + std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, + matrix.rows(), matrix_construct.nj), // --- REGULAR TESTS - std::make_tuple(block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(block_top_right_corner, 0, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix_construct.nj), - std::make_tuple(block_bottom_right_corner, matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj, + std::make_tuple(block_main, matrix_construct.i0, matrix_construct.j0, matrix_construct.ni, matrix_construct.nj), + std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(block_top_right_corner, 0, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(block_bottom_left_corner, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + matrix_construct.nj), + std::make_tuple(block_bottom_right_corner, + matrix.rows() - matrix_construct.ni, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj), std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols()), - std::make_tuple(block_middle_rows, matrix_construct.i0, 0, matrix_construct.ni, matrix.cols()), - std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, matrix.cols()), + std::make_tuple(block_middle_rows, matrix_construct.i0, 0, + matrix_construct.ni, matrix.cols()), + std::make_tuple(block_bottom_rows, matrix.rows() - matrix_construct.ni, 0, + matrix_construct.ni, matrix.cols()), std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj), - std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(), matrix_construct.nj), - std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, matrix.rows(), matrix_construct.nj) - ); + std::make_tuple(block_middle_cols, 0, matrix_construct.j0, matrix.rows(), + matrix_construct.nj), + std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, + matrix.rows(), matrix_construct.nj)); - std::apply([&](auto&&... block_entries) - { - (([&] - { - auto&& [block, i_offset, j_offset, ni, nj] = block_entries; - using block_t = std::remove_reference_t; + std::apply( + [&](auto&&... block_entries) { + (([&] { + auto&& [block, i_offset, j_offset, ni, nj] = block_entries; + using block_t = std::remove_reference_t; - TTS_EQUAL(block_t::RowsAtCompileTime, rotgen::Dynamic); - TTS_EQUAL(block_t::ColsAtCompileTime, rotgen::Dynamic); - TTS_EQUAL(block_t::storage_order, MatrixType::storage_order); - - validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj); - })(), ...); - }, blocks); + TTS_EQUAL(block_t::RowsAtCompileTime, rotgen::Dynamic); + TTS_EQUAL(block_t::ColsAtCompileTime, rotgen::Dynamic); + TTS_EQUAL(block_t::storage_order, MatrixType::storage_order); + validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj); + })(), + ...); + }, + blocks); } template -void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case const& matrix_construct) +void test_static_block_extraction( + rotgen::tests::static_matrix_block_test_case const& + matrix_construct) { - auto[d,i0,j0] = matrix_construct; - auto[r,c,fn] = d; + auto [d, i0, j0] = matrix_construct; + auto [r, c, fn] = d; - MatrixType matrix(r,c); + MatrixType matrix(r, c); for (rotgen::Index i = 0; i < r; ++i) for (rotgen::Index j = 0; j < c; ++j) @@ -181,177 +224,219 @@ void test_static_block_extraction(rotgen::tests::static_matrix_block_test_case(c_matrix, i0, j0); - auto c_block_top_left_corner = rotgen::topLeftCorner(c_matrix); - auto c_block_top_right_corner = rotgen::topRightCorner(c_matrix); - auto c_block_bottom_left_corner = rotgen::bottomLeftCorner(c_matrix); - auto c_block_bottom_right_corner = rotgen::bottomRightCorner(c_matrix); - auto c_block_top_rows = rotgen::topRows(c_matrix); - auto c_block_middle_rows = rotgen::middleRows(c_matrix, i0); - auto c_block_bottom_rows = rotgen::bottomRows(c_matrix); - auto c_block_left_cols = rotgen::leftCols(c_matrix); - auto c_block_middle_cols = rotgen::middleCols(c_matrix, j0); - auto c_block_right_cols = rotgen::rightCols(c_matrix); - auto c_block_row = rotgen::row(c_matrix, i0); - auto c_block_col = rotgen::col(c_matrix, j0); + auto c_block_main = rotgen::extract(c_matrix, i0, j0); + auto c_block_top_left_corner = rotgen::topLeftCorner(c_matrix); + auto c_block_top_right_corner = rotgen::topRightCorner(c_matrix); + auto c_block_bottom_left_corner = rotgen::bottomLeftCorner(c_matrix); + auto c_block_bottom_right_corner = + rotgen::bottomRightCorner(c_matrix); + auto c_block_top_rows = rotgen::topRows(c_matrix); + auto c_block_middle_rows = rotgen::middleRows(c_matrix, i0); + auto c_block_bottom_rows = rotgen::bottomRows(c_matrix); + auto c_block_left_cols = rotgen::leftCols(c_matrix); + auto c_block_middle_cols = rotgen::middleCols(c_matrix, j0); + auto c_block_right_cols = rotgen::rightCols(c_matrix); + auto c_block_row = rotgen::row(c_matrix, i0); + auto c_block_col = rotgen::col(c_matrix, j0); - auto block_main = rotgen::extract(matrix, i0, j0); - auto block_top_left_corner = rotgen::topLeftCorner(matrix); - auto block_top_right_corner = rotgen::topRightCorner(matrix); - auto block_bottom_left_corner = rotgen::bottomLeftCorner(matrix); + auto block_main = rotgen::extract(matrix, i0, j0); + auto block_top_left_corner = rotgen::topLeftCorner(matrix); + auto block_top_right_corner = rotgen::topRightCorner(matrix); + auto block_bottom_left_corner = rotgen::bottomLeftCorner(matrix); auto block_bottom_right_corner = rotgen::bottomRightCorner(matrix); - auto block_top_rows = rotgen::topRows(matrix); - auto block_middle_rows = rotgen::middleRows(matrix, i0); - auto block_bottom_rows = rotgen::bottomRows(matrix); - auto block_left_cols = rotgen::leftCols(matrix); - auto block_middle_cols = rotgen::middleCols(matrix, j0); - auto block_right_cols = rotgen::rightCols(matrix); - auto block_row = rotgen::row(matrix, i0); - auto block_col = rotgen::col(matrix, j0); + auto block_top_rows = rotgen::topRows(matrix); + auto block_middle_rows = rotgen::middleRows(matrix, i0); + auto block_bottom_rows = rotgen::bottomRows(matrix); + auto block_left_cols = rotgen::leftCols(matrix); + auto block_middle_cols = rotgen::middleCols(matrix, j0); + auto block_right_cols = rotgen::rightCols(matrix); + auto block_row = rotgen::row(matrix, i0); + auto block_col = rotgen::col(matrix, j0); auto blocks = std::make_tuple( - // ----- TEST ON BLOCK FROM CONST MATRIX - std::make_tuple(c_block_main, i0, j0, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_top_left_corner, 0, 0, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_top_right_corner, 0, matrix.cols() - matrix_construct.nj, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_bottom_right_corner, matrix.rows() - matrix_construct.ni, + // ----- TEST ON BLOCK FROM CONST MATRIX + std::make_tuple(c_block_main, i0, j0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(c_block_top_left_corner, 0, 0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(c_block_top_right_corner, 0, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(c_block_bottom_left_corner, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(c_block_bottom_right_corner, + matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(c_block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic), + 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, 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_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, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(c_block_middle_cols, 0, j0, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(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, matrix.rows(), + matrix_construct.nj, rotgen::Dynamic, int(NJ)), std::make_tuple(c_block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), + matrix.rows(), matrix_construct.nj, rotgen::Dynamic, + int(NJ)), - std::make_tuple(c_block_row, i0, 0, - 1, matrix.cols(), 1, rotgen::Dynamic), - std::make_tuple(c_block_col, 0, j0, - matrix.rows(), 1, rotgen::Dynamic, 1), + std::make_tuple(c_block_row, i0, 0, 1, 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, matrix.cols() - matrix_construct.nj, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(block_bottom_left_corner, matrix.rows() - matrix_construct.ni, 0, - matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(block_bottom_right_corner, matrix.rows() - matrix_construct.ni, + std::make_tuple(block_main, i0, j0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(block_top_left_corner, 0, 0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(block_top_right_corner, 0, + matrix.cols() - matrix_construct.nj, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(block_bottom_left_corner, + matrix.rows() - matrix_construct.ni, 0, matrix_construct.ni, + matrix_construct.nj, int(NI), int(NJ)), + std::make_tuple(block_bottom_right_corner, + matrix.rows() - matrix_construct.ni, matrix.cols() - matrix_construct.nj, matrix_construct.ni, matrix_construct.nj, int(NI), int(NJ)), - std::make_tuple(block_top_rows, 0, 0, matrix_construct.ni, matrix.cols(), int(NI), rotgen::Dynamic), + 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, 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_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, matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), - std::make_tuple(block_middle_cols, 0, j0, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), + std::make_tuple(block_left_cols, 0, 0, matrix.rows(), matrix_construct.nj, + rotgen::Dynamic, int(NJ)), + std::make_tuple(block_middle_cols, 0, j0, matrix.rows(), + matrix_construct.nj, rotgen::Dynamic, int(NJ)), std::make_tuple(block_right_cols, 0, matrix.cols() - matrix_construct.nj, - matrix.rows(), matrix_construct.nj, rotgen::Dynamic, int(NJ)), + matrix.rows(), matrix_construct.nj, rotgen::Dynamic, + int(NJ)), - std::make_tuple(block_row, i0, 0, - 1, matrix.cols(), 1, rotgen::Dynamic), - std::make_tuple(block_col, 0, j0, - matrix.rows(), 1, rotgen::Dynamic, 1) - ); + std::make_tuple(block_row, i0, 0, 1, matrix.cols(), 1, rotgen::Dynamic), + std::make_tuple(block_col, 0, j0, matrix.rows(), 1, rotgen::Dynamic, 1)); - std::apply([&](auto&&... block_entries) - { - (([&] - { - auto&& [block, i_offset, j_offset, ni, nj, rows_ct, cols_ct] = block_entries; - using block_t = std::remove_reference_t; + std::apply( + [&](auto&&... block_entries) { + (([&] { + auto&& [block, i_offset, j_offset, ni, nj, rows_ct, cols_ct] = + block_entries; + using block_t = std::remove_reference_t; - TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct); - TTS_EQUAL(block_t::ColsAtCompileTime, cols_ct); + TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct); + TTS_EQUAL(block_t::ColsAtCompileTime, cols_ct); - validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj); - })(), ...); - }, blocks); + validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj); + })(), + ...); + }, + blocks); } -TTS_CASE_TPL("Check all dynamic block extractions on a dynamic row-major matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL( + "Check all dynamic block extractions on a dynamic row-major matrix", + rotgen::tests::types)(tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = + rotgen::matrix; std::vector> cases = { - { {6, 11, [](rotgen::Index i, rotgen::Index j) { return T(i * 10 + j); }}, 1, 2, 3, 2 }, - { {7, 10, [](rotgen::Index i, rotgen::Index j) { return T(std::sin(i + j)); }}, 4, 4, 3, 3 }, - { {5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 7); }}, 0, 0, 5, 5 }, - { {9, 14, [](rotgen::Index i, rotgen::Index j) { return T(i+j + 3*j); }}, 3, 7, 1, 1 } - }; + {{6, 11, [](rotgen::Index i, rotgen::Index j) { return T(i * 10 + j); }}, + 1, + 2, + 3, + 2}, + {{7, 10, + [](rotgen::Index i, rotgen::Index j) { return T(std::sin(i + j)); }}, + 4, + 4, + 3, + 3}, + {{5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 7); }}, + 0, + 0, + 5, + 5}, + {{9, 14, [](rotgen::Index i, rotgen::Index j) { return T(i + j + 3 * j); }}, + 3, + 7, + 1, + 1}}; - for (auto const& matrix_case : cases) { + for (auto const& matrix_case : cases) + { test_dynamic_block_extraction(matrix_case); } }; -TTS_CASE_TPL("Check all dynamic block extractions on a static column-major matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL( + "Check all dynamic block extractions on a static column-major matrix", + rotgen::tests::types)(tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; std::vector> cases = { - { {4, 5, [](auto i, auto j) { return T(2*i + j*j*j - 42); } }, 1, 2, 3, 2 }, - { {4, 5, [](auto i, auto j) { return T(std::tan(i*i*j)); } }, 0, 1, 2, 1 }, - { {4, 5, [](auto i, auto j) { return T((i*i + j*j) / 6); } }, 2, 0, 0, 0 } - }; + {{4, 5, [](auto i, auto j) { return T(2 * i + j * j * j - 42); }}, + 1, + 2, + 3, + 2}, + {{4, 5, [](auto i, auto j) { return T(std::tan(i * i * j)); }}, 0, 1, 2, 1}, + {{4, 5, [](auto i, auto j) { return T((i * i + j * j) / 6); }}, + 2, + 0, + 0, + 0}}; - for (auto const& matrix_case : cases) { + for (auto const& matrix_case : cases) + { test_dynamic_block_extraction(matrix_case); } - }; -TTS_CASE_TPL("Check all static block extractions", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check all static block extractions", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; test_static_block_extraction( rotgen::tests::static_matrix_block_test_case{ - {11, 11, [](rotgen::Index i, rotgen::Index j) { return T(i*i*i + 3*j - 127); } }, - 3, 2 - } - ); + {11, 11, + [](rotgen::Index i, rotgen::Index j) { + return T(i * i * i + 3 * j - 127); + }}, + 3, + 2}); test_static_block_extraction( rotgen::tests::static_matrix_block_test_case{ - {14, 15,[](rotgen::Index i, rotgen::Index j) { return T(std::cos(i * j * 2)); }}, - 5, 1 - } - ); + {14, 15, + [](rotgen::Index i, rotgen::Index j) { return T(std::cos(i * j * 2)); }}, + 5, + 1}); test_static_block_extraction( rotgen::tests::static_matrix_block_test_case{ - {5, 5,[](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); }}, - 0, 0 - } - ); + {5, 5, [](rotgen::Index i, rotgen::Index j) { return T((i + j) % 9); }}, + 0, + 0}); }; 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) { + 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) { using block_t = std::remove_reference_t; TTS_EQUAL(block_t::RowsAtCompileTime, rows_ct); @@ -360,12 +445,12 @@ TTS_CASE_TPL("Check vector-only extractions", validate_block_behavior(matrix, block, i_offset, j_offset, ni, nj); }; - if constexpr (O::value == rotgen::RowMajor) { + if constexpr (O::value == rotgen::RowMajor) + { using mat_t = rotgen::matrix; mat_t m(1, 11); - for (rotgen::Index i = 0; i < 11; ++i) - m(i) = 1 + i; + for (rotgen::Index i = 0; i < 11; ++i) m(i) = 1 + i; run_case(m, head(m, 1), 0, 0, 1, 1, 1, rotgen::Dynamic); run_case(m, head(m, 5), 0, 0, 1, 5, 1, rotgen::Dynamic); @@ -385,12 +470,13 @@ TTS_CASE_TPL("Check vector-only extractions", run_case(m, segment<11>(m, 0), 0, 0, 1, 11, 1, 11); run_case(m, segment<7>(m, 0), 0, 0, 1, 7, 1, 7); run_case(m, segment<6>(m, 5), 0, 5, 1, 6, 1, 6); - } else { + } + else + { using mat_t = rotgen::matrix; mat_t m(11, 1); - for (rotgen::Index i = 0; i < 11; ++i) - m(i) = 1 + i; + for (rotgen::Index i = 0; i < 11; ++i) m(i) = 1 + i; run_case(m, head(m, 1), 0, 0, 1, 1, rotgen::Dynamic, 1); run_case(m, head(m, 5), 0, 0, 5, 1, rotgen::Dynamic, 1); diff --git a/test/unit/block/generators.cpp b/test/unit/block/generators.cpp index ac0d071..6a658ea 100644 --- a/test/unit/block/generators.cpp +++ b/test/unit/block/generators.cpp @@ -8,261 +8,269 @@ #include "unit/tests.hpp" #include -void test_value ( const auto& matrix, auto value - , rotgen::Index i0, rotgen::Index j0 - , rotgen::Index rows, rotgen::Index cols - ) +void test_value(auto const& matrix, + auto value, + rotgen::Index i0, + rotgen::Index j0, + rotgen::Index rows, + rotgen::Index cols) { - for(rotgen::Index r=0;r( tts::type< tts::types>) +TTS_CASE_TPL("Test dynamic block::setZero", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); input.setZero(); - test_value(m,T{0},i0,j0,ni,nj); + test_value(m, T{0}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Zero(ni,nj); - test_value(values,T{0},0,0,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::types> ) +TTS_CASE_TPL("Test static block:setZero", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); input.setZero(); - test_value(m,T{0},i0,j0,D::ni,D::nj); + test_value(m, T{0}, i0, j0, D::ni, D::nj); - using input_type = decltype(rotgen::extract(m, i0, j0)); + using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = input_type::Zero(); - test_value(values,T{0},0,0,D::ni,D::nj); + test_value(values, T{0}, 0, 0, D::ni, D::nj); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setOnes", rotgen::tests::types) -( tts::type< tts::types>) +TTS_CASE_TPL("Test dynamic block::setOnes", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); input.setOnes(); - test_value(m,T{1},i0,j0,ni,nj); + test_value(m, T{1}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Ones(ni,nj); - test_value(values,T{1},0,0,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::types> ) +TTS_CASE_TPL("Test static block:setOnes", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); input.setOnes(); - test_value(m,T{1},i0,j0,D::ni,D::nj); + test_value(m, T{1}, i0, j0, D::ni, D::nj); - using input_type = decltype(rotgen::extract(m, i0, j0)); + using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = input_type::Ones(); - test_value(values,T{1},0,0,D::ni,D::nj); + test_value(values, T{1}, 0, 0, D::ni, D::nj); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setConstant", rotgen::tests::types) -( tts::type< tts::types>) +TTS_CASE_TPL("Test dynamic block::setConstant", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); input.setConstant(T{13.37f}); - test_value(m,T{13.37f},i0,j0,ni,nj); + test_value(m, T{13.37f}, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Constant(ni,nj,T{13.37f}); - test_value(values,T{13.37f},0,0,ni,nj); + 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::types> ) +TTS_CASE_TPL("Test static block:setConstant", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); input.setConstant(T{13.37f}); - test_value(m,T{13.37f},i0,j0,D::ni,D::nj); + test_value(m, T{13.37f}, i0, j0, D::ni, D::nj); - using input_type = decltype(rotgen::extract(m, i0, j0)); + using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = input_type::Constant(T{13.37f}); - test_value(values,T{13.37f},0,0,D::ni,D::nj); + test_value(values, T{13.37f}, 0, 0, D::ni, D::nj); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setIdentity", rotgen::tests::types) -( tts::type< tts::types>) +TTS_CASE_TPL("Test dynamic block::setIdentity", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); input.setIdentity(); - test_identity(m,i0,j0,ni,nj); + test_identity(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Identity(ni,nj); - test_identity(values,0,0,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::types> ) +TTS_CASE_TPL("Test static block:setIdentity", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); input.setIdentity(); - test_identity(m,i0,j0,D::ni,D::nj); + test_identity(m, i0, j0, D::ni, D::nj); - using input_type = decltype(rotgen::extract(m, i0, j0)); + using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = input_type::Identity(); - test_identity(values,0,0,D::ni,D::nj); + test_identity(values, 0, 0, D::ni, D::nj); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic block::setRandom", rotgen::tests::types) -( tts::type< tts::types>) +TTS_CASE_TPL("Test dynamic block::setRandom", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); input.setRandom(); - test_random(m,i0,j0,ni,nj); + test_random(m, i0, j0, ni, nj); using input_type = decltype(rotgen::extract(m, i0, j0, ni, nj)); - auto values = input_type::Random(ni,nj); - test_random(values,0,0,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::types> ) +TTS_CASE_TPL("Test static block:setRandom", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); input.setRandom(); - test_random(m,i0,j0,D::ni,D::nj); + test_random(m, i0, j0, D::ni, D::nj); - using input_type = decltype(rotgen::extract(m, i0, j0)); + using input_type = decltype(rotgen::extract(m, i0, j0)); auto values = input_type::Random(); - test_random(values,0,0,D::ni,D::nj); + test_random(values, 0, 0, D::ni, D::nj); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); -}; \ No newline at end of file + std::apply([&](auto const&... d) { (process(d), ...); }, cases); +}; diff --git a/test/unit/block/norms.cpp b/test/unit/block/norms.cpp index 0752910..6ac2947 100644 --- a/test/unit/block/norms.cpp +++ b/test/unit/block/norms.cpp @@ -9,34 +9,35 @@ #include "unit/common/norms.hpp" #include -TTS_CASE_TPL("Test dynamic block norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic block norm operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_block_references(); - for (const auto& [matrix_desc, i0, j0, ni, nj] : cases) + auto const cases = rotgen::tests::generate_block_references(); + for (auto const& [matrix_desc, i0, j0, ni, nj] : cases) { - auto[rows,cols,fn] = matrix_desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); + auto [rows, cols, fn] = matrix_desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); auto input = rotgen::extract(m, i0, j0, ni, nj); rotgen::tests::check_norms_functions(input); } }; -TTS_CASE_TPL("Test static block norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static block norm operations", + rotgen::tests::types)( + tts::type>) { - auto const cases = rotgen::tests::generate_static_block_references(); + auto const cases = rotgen::tests::generate_static_block_references(); - auto process = [](D const& d) - { - auto[desc,i0,j0] = d; - auto[rows,cols,fn] = desc; - rotgen::matrix m(rows, cols); - rotgen::tests::prepare(rows,cols,fn,m); - auto input = rotgen::extract(m, i0, j0); + auto process = [](D const& d) { + auto [desc, i0, j0] = d; + auto [rows, cols, fn] = desc; + rotgen::matrix m(rows, cols); + rotgen::tests::prepare(rows, cols, fn, m); + auto input = rotgen::extract(m, i0, j0); rotgen::tests::check_norms_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; diff --git a/test/unit/block/operators.cpp b/test/unit/block/operators.cpp index cac0fe4..dffd7d6 100644 --- a/test/unit/block/operators.cpp +++ b/test/unit/block/operators.cpp @@ -9,35 +9,38 @@ #include #include -template -void test_block_matrix_operations(rotgen::tests::matrix_block_test_case const& matrix_construct, - auto b_init_fn, auto ops, auto self_ops) +template +void test_block_matrix_operations( + rotgen::tests::matrix_block_test_case const& matrix_construct, + auto b_init_fn, + auto ops, + auto self_ops) { using EigenMatrix = Eigen::Matrix; - auto[d,i0,j0,ni,nj] = matrix_construct; - auto[r,c,fn] = d; + auto [d, i0, j0, ni, nj] = matrix_construct; + auto [r, c, fn] = d; MatrixType a(r, c); MatrixType b(r, c); EigenMatrix ref_a(r, c); EigenMatrix ref_b(r, c); - TTS_EXPECT(verify_rotgen_reentrance(ops(a,b))); + TTS_EXPECT(verify_rotgen_reentrance(ops(a, b))); for (rotgen::Index rr = 0; rr < r; ++rr) { for (rotgen::Index cc = 0; cc < c; ++cc) { - ref_a(rr,cc) = a(rr,cc) = static_cast(fn(rr,cc)); - ref_b(rr,cc) = b(rr,cc) = static_cast(b_init_fn(rr,cc)); + ref_a(rr, cc) = a(rr, cc) = static_cast(fn(rr, cc)); + ref_b(rr, cc) = b(rr, cc) = static_cast(b_init_fn(rr, cc)); } } - auto a_block = rotgen::extract(a, i0, j0,ni, nj); - auto b_block = rotgen::extract(b, i0, j0,ni, nj); - auto ref_a_block = ref_a.block(i0, j0,ni, nj); - auto ref_b_block = ref_b.block(i0, j0,ni, nj); + auto a_block = rotgen::extract(a, i0, j0, ni, nj); + auto b_block = rotgen::extract(b, i0, j0, ni, nj); + auto ref_a_block = ref_a.block(i0, j0, ni, nj); + auto ref_b_block = ref_b.block(i0, j0, ni, nj); auto result_block = ops(a_block, b_block); auto ref_result_block = ops(ref_a_block, ref_b_block); @@ -46,7 +49,7 @@ void test_block_matrix_operations(rotgen::tests::matrix_block_test_case -void test_block_scalar_operations(rotgen::tests::matrix_block_test_case const& matrix_construct, - auto scalar, auto ops, auto self_ops) +template +void test_block_scalar_operations( + rotgen::tests::matrix_block_test_case const& matrix_construct, + auto scalar, + auto ops, + auto self_ops) { using EigenMatrix = Eigen::Matrix; - auto[d,i0,j0,ni,nj] = matrix_construct; - auto[rows,cols,fn] = d; + auto [d, i0, j0, ni, nj] = matrix_construct; + auto [rows, cols, fn] = d; MatrixType a(rows, cols); EigenMatrix ref_a(rows, cols); - TTS_EXPECT(verify_rotgen_reentrance(ops(a,scalar))); + TTS_EXPECT(verify_rotgen_reentrance(ops(a, scalar))); for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) - ref_a(r,c) = a(r,c) = static_cast(fn(r, c)); + ref_a(r, c) = a(r, c) = static_cast(fn(r, c)); - auto a_block = rotgen::extract(a, i0, j0,ni, nj); - auto ref_a_block = ref_a.block(i0, j0,ni, nj); + auto a_block = rotgen::extract(a, i0, j0, ni, nj); + auto ref_a_block = ref_a.block(i0, j0, ni, nj); auto result = ops(a_block, scalar); auto ref_result = ops(ref_a_block, scalar); @@ -91,7 +97,7 @@ void test_block_scalar_operations(rotgen::tests::matrix_block_test_case -void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case const& matrix_construct, - T scalar) +template +void test_scalar_block_multiplications( + rotgen::tests::matrix_block_test_case const& matrix_construct, + T scalar) { using EigenMatrix = Eigen::Matrix; - auto[d,i0,j0,ni,nj] = matrix_construct; - auto[rows,cols,fn] = d; + auto [d, i0, j0, ni, nj] = matrix_construct; + auto [rows, cols, fn] = d; MatrixType a(rows, cols); EigenMatrix ref_a(rows, cols); @@ -120,12 +126,10 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case(fn(r, c)); + ref_a(r, c) = a(r, c) = static_cast(fn(r, c)); - auto a_block = rotgen::extract(a, i0, j0, - ni, nj); - auto ref_a_block = ref_a.block(i0, j0, - ni, nj); + auto a_block = rotgen::extract(a, i0, j0, ni, nj); + auto ref_a_block = ref_a.block(i0, j0, ni, nj); auto a_scalar_multiplication = a_block * scalar; auto scalar_a_multiplication = scalar * a_block; @@ -136,8 +140,10 @@ void test_scalar_block_multiplications(rotgen::tests::matrix_block_test_case -void test_block_multiplication(rotgen::tests::matrix_block_test_case const& a_matrix_construct, - rotgen::tests::matrix_block_test_case const& b_matrix_construct) +template +void test_block_multiplication( + rotgen::tests::matrix_block_test_case const& a_matrix_construct, + rotgen::tests::matrix_block_test_case const& b_matrix_construct) { using EigenMatrix = Eigen::Matrix; - auto[a_d,a_i0,a_j0,a_ni,a_nj] = a_matrix_construct; - auto[a_rows,a_cols,a_fn] = a_d; - - auto[b_d,b_i0,b_j0,b_ni,b_nj] = b_matrix_construct; - auto[b_rows,b_cols,b_fn] = b_d; + auto [a_d, a_i0, a_j0, a_ni, a_nj] = a_matrix_construct; + auto [a_rows, a_cols, a_fn] = a_d; + auto [b_d, b_i0, b_j0, b_ni, b_nj] = b_matrix_construct; + auto [b_rows, b_cols, b_fn] = b_d; MatrixType a(a_rows, a_cols); MatrixType b(b_rows, b_cols); @@ -173,17 +178,16 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case for (rotgen::Index r = 0; r < a_rows; ++r) for (rotgen::Index c = 0; c < a_cols; ++c) - ref_a(r,c) = a(r,c) = static_cast(a_fn(r, c)); + ref_a(r, c) = a(r, c) = static_cast(a_fn(r, c)); for (rotgen::Index r = 0; r < b_rows; ++r) for (rotgen::Index c = 0; c < b_cols; ++c) - ref_b(r,c) = b(r,c) = static_cast(b_fn(r, c)); + ref_b(r, c) = b(r, c) = static_cast(b_fn(r, c)); - - auto a_block = rotgen::extract(a, a_i0, a_j0,a_ni, a_nj); - auto b_block = rotgen::extract(b, b_i0, b_j0,b_ni, b_nj); - auto ref_a_block = ref_a.block(a_i0, a_j0,a_ni, a_nj); - auto ref_b_block = ref_b.block(b_i0, b_j0,b_ni, b_nj); + auto a_block = rotgen::extract(a, a_i0, a_j0, a_ni, a_nj); + auto b_block = rotgen::extract(b, b_i0, b_j0, b_ni, b_nj); + auto ref_a_block = ref_a.block(a_i0, a_j0, a_ni, a_nj); + auto ref_b_block = ref_b.block(b_i0, b_j0, b_ni, b_nj); TTS_EXPECT(verify_rotgen_reentrance(a_block * b_block)); @@ -192,7 +196,7 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case for (rotgen::Index r = 0; r < a_ni; ++r) for (rotgen::Index c = 0; c < a_nj; ++c) - TTS_EQUAL(a_b_product_original (r, c), a_b_product_ref(r, c)); + TTS_EQUAL(a_b_product_original(r, c), a_b_product_ref(r, c)); a_block *= b_block; ref_a_block *= ref_b_block; @@ -202,106 +206,162 @@ void test_block_multiplication(rotgen::tests::matrix_block_test_case TTS_EQUAL(a_block(r, c), ref_a_block(r, c)); for (rotgen::Index r = 0; r < a_rows; ++r) - for (rotgen::Index c = 0; c < a_cols; ++c) - TTS_EQUAL(a(r, c), ref_a(r, c)); + for (rotgen::Index c = 0; c < a_cols; ++c) TTS_EQUAL(a(r, c), ref_a(r, c)); for (rotgen::Index r = 0; r < b_rows; ++r) - for (rotgen::Index c = 0; c < b_cols; ++c) - TTS_EQUAL(b(r, c), ref_b(r, c)); + for (rotgen::Index c = 0; c < b_cols; ++c) TTS_EQUAL(b(r, c), ref_b(r, c)); } // Basic initializers -inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c -12; }; -inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; }; -inline constexpr auto init_0 = [](auto , auto ) { return 0; }; +inline constexpr auto init_a = [](auto r, auto c) { + return 9.9 * r * r * r - 6 * c - 12; +}; +inline constexpr auto init_b = [](auto r, auto c) { + return 3.1 * r + 4.2 * c - 12.3; +}; +inline constexpr auto init_0 = [](auto, auto) { return 0; }; -TTS_CASE_TPL("Check block addition", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check block addition", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a + b; }; - auto s_op = [](auto& a, auto b) { return a += b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a + b; }; + auto s_op = [](auto& a, auto b) { return a += b; }; - test_block_matrix_operations({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op); - test_block_matrix_operations({{13, 15, init_a}, 1, 2, 3, 4}, init_b, op, s_op); - test_block_matrix_operations({{ 5, 9, init_a}, 2, 2, 2, 2}, init_b, op, s_op); - test_block_matrix_operations({{15, 15, init_a}, 3, 4, 5, 5}, init_b, op, s_op); - test_block_matrix_operations({{ 5, 5, init_b}, 1, 0, 3, 2}, init_a, op, s_op); - test_block_matrix_operations({{10, 1, init_a}, 0, 0, 5, 1}, init_b, op, s_op); - test_block_matrix_operations({{ 1, 10, init_a}, 0, 0, 1, 5}, init_b, op, s_op); - test_block_matrix_operations({{21, 5, init_0}, 4, 4, 10, 1}, init_b, op, s_op); - test_block_matrix_operations({{11, 7, init_a}, 2, 0, 7, 5}, init_0, op, s_op); + test_block_matrix_operations({{1, 1, init_a}, 0, 0, 1, 1}, init_b, + op, s_op); + test_block_matrix_operations({{13, 15, init_a}, 1, 2, 3, 4}, init_b, + op, s_op); + test_block_matrix_operations({{5, 9, init_a}, 2, 2, 2, 2}, init_b, + op, s_op); + test_block_matrix_operations({{15, 15, init_a}, 3, 4, 5, 5}, init_b, + op, s_op); + test_block_matrix_operations({{5, 5, init_b}, 1, 0, 3, 2}, init_a, + op, s_op); + test_block_matrix_operations({{10, 1, init_a}, 0, 0, 5, 1}, init_b, + op, s_op); + test_block_matrix_operations({{1, 10, init_a}, 0, 0, 1, 5}, init_b, + op, s_op); + test_block_matrix_operations({{21, 5, init_0}, 4, 4, 10, 1}, init_b, + op, s_op); + test_block_matrix_operations({{11, 7, init_a}, 2, 0, 7, 5}, init_0, + op, s_op); }; -TTS_CASE_TPL("Check block subtraction", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check block subtraction", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a - b; }; - auto s_op = [](auto& a, auto b) { return a -= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a - b; }; + auto s_op = [](auto& a, auto b) { return a -= b; }; - test_block_matrix_operations({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op); - test_block_matrix_operations({{ 1, 1, init_a}, 0, 0, 1, 1}, init_b, op, s_op); - test_block_matrix_operations({{13, 15, init_a}, 1, 2, 3, 4}, init_b, op, s_op); - test_block_matrix_operations({{ 5, 9, init_a}, 2, 2, 2, 2}, init_b, op, s_op); - test_block_matrix_operations({{15, 15, init_a}, 3, 4, 5, 5}, init_b, op, s_op); - test_block_matrix_operations({{ 5, 5, init_b}, 1, 0, 3, 2}, init_a, op, s_op); - test_block_matrix_operations({{10, 1, init_a}, 0, 0, 5, 1}, init_b, op, s_op); - test_block_matrix_operations({{ 1, 10, init_a}, 0, 0, 1, 5}, init_b,op, s_op); - test_block_matrix_operations({{21 , 5, init_0}, 4, 4, 10, 1}, init_b, op, s_op); - test_block_matrix_operations({{11 , 7, init_a}, 2, 0, 7, 5}, init_0, op, s_op); + test_block_matrix_operations({{1, 1, init_a}, 0, 0, 1, 1}, init_b, + op, s_op); + test_block_matrix_operations({{1, 1, init_a}, 0, 0, 1, 1}, init_b, + op, s_op); + test_block_matrix_operations({{13, 15, init_a}, 1, 2, 3, 4}, init_b, + op, s_op); + test_block_matrix_operations({{5, 9, init_a}, 2, 2, 2, 2}, init_b, + op, s_op); + test_block_matrix_operations({{15, 15, init_a}, 3, 4, 5, 5}, init_b, + op, s_op); + test_block_matrix_operations({{5, 5, init_b}, 1, 0, 3, 2}, init_a, + op, s_op); + test_block_matrix_operations({{10, 1, init_a}, 0, 0, 5, 1}, init_b, + op, s_op); + test_block_matrix_operations({{1, 10, init_a}, 0, 0, 1, 5}, init_b, + op, s_op); + test_block_matrix_operations({{21, 5, init_0}, 4, 4, 10, 1}, init_b, + op, s_op); + test_block_matrix_operations({{11, 7, init_a}, 2, 0, 7, 5}, init_0, + op, s_op); }; -TTS_CASE_TPL("Check block multiplications", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check block multiplications", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto init_id = [](rotgen::Index r, rotgen::Index c) { return r == c ? 1 : 0; }; + using mat_t = rotgen::matrix; + auto init_id = [](rotgen::Index r, rotgen::Index c) { + return r == c ? 1 : 0; + }; - test_block_multiplication({{ 1, 1, init_a }, 0, 0, 1, 1}, {{ 1, 1, init_b }, 0, 0, 1, 1}); - test_block_multiplication({{13, 15, init_b }, 1, 2, 4, 4}, {{13, 15, init_b }, 0, 1, 4, 4}); - test_block_multiplication({{ 6, 9, init_a }, 2, 2, 2, 2}, {{ 5, 9, init_b }, 2, 2, 2, 2}); - test_block_multiplication({{15, 15, init_a }, 3, 4, 5, 5}, {{15, 15, init_b }, 0, 0, 5, 5}); - test_block_multiplication({{ 5, 5, init_b }, 1, 0, 3, 3}, {{ 5, 5, init_a }, 0, 0, 3, 3}); - test_block_multiplication({{11, 3, init_id}, 2, 0, 2, 2}, {{18, 7, init_a }, 2, 0, 2, 2}); - test_block_multiplication({{10, 1, init_a }, 0, 0, 1, 1}, {{10, 1, init_a }, 0, 0, 1, 1}); - test_block_multiplication({{ 1, 10, init_a }, 0, 0, 1, 1}, {{ 1, 10, init_id}, 0, 0, 1, 1}); - test_block_multiplication({{21, 5, init_0 }, 1, 1, 3, 3}, {{12, 7, init_0 }, 4, 4, 3, 3}); - test_block_multiplication({{11, 7, init_a }, 2, 0, 7, 7}, {{11, 11, init_a }, 2, 1, 7, 7}); - test_block_multiplication({{11, 7, init_a }, 2, 0, 5, 5}, {{11, 12, init_id}, 0, 0, 5, 5}); + test_block_multiplication({{1, 1, init_a}, 0, 0, 1, 1}, + {{1, 1, init_b}, 0, 0, 1, 1}); + test_block_multiplication({{13, 15, init_b}, 1, 2, 4, 4}, + {{13, 15, init_b}, 0, 1, 4, 4}); + test_block_multiplication({{6, 9, init_a}, 2, 2, 2, 2}, + {{5, 9, init_b}, 2, 2, 2, 2}); + test_block_multiplication({{15, 15, init_a}, 3, 4, 5, 5}, + {{15, 15, init_b}, 0, 0, 5, 5}); + test_block_multiplication({{5, 5, init_b}, 1, 0, 3, 3}, + {{5, 5, init_a}, 0, 0, 3, 3}); + test_block_multiplication({{11, 3, init_id}, 2, 0, 2, 2}, + {{18, 7, init_a}, 2, 0, 2, 2}); + test_block_multiplication({{10, 1, init_a}, 0, 0, 1, 1}, + {{10, 1, init_a}, 0, 0, 1, 1}); + test_block_multiplication({{1, 10, init_a}, 0, 0, 1, 1}, + {{1, 10, init_id}, 0, 0, 1, 1}); + test_block_multiplication({{21, 5, init_0}, 1, 1, 3, 3}, + {{12, 7, init_0}, 4, 4, 3, 3}); + test_block_multiplication({{11, 7, init_a}, 2, 0, 7, 7}, + {{11, 11, init_a}, 2, 1, 7, 7}); + test_block_multiplication({{11, 7, init_a}, 2, 0, 5, 5}, + {{11, 12, init_id}, 0, 0, 5, 5}); }; -TTS_CASE_TPL("Check block multiplication with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check block multiplication with scalar", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; - test_scalar_block_multiplications({{ 1, 1, init_a}, 0, 0, 1, 1}, T{ 3.5}); - test_scalar_block_multiplications({{13, 15, init_a}, 1, 2, 3, 4}, T{ 0.}); - test_scalar_block_multiplications({{ 5 , 9, init_a}, 2, 2, 2, 2}, T{-2.5}); - test_scalar_block_multiplications({{15, 15, init_a}, 3, 4, 5, 5}, T{ 42. }); - test_scalar_block_multiplications({{ 5, 5, init_b}, 1, 0, 3, 2}, T{-5. }); - test_scalar_block_multiplications({{10, 1, init_a}, 0, 0, 5, 1}, T{ 1. }); - test_scalar_block_multiplications({{ 1, 10, init_a}, 0, 0, 1, 5}, T{ 6. }); - test_scalar_block_multiplications({{21, 5, init_0}, 4, 4, 10, 1}, T{ 10.1}); - test_scalar_block_multiplications({{11, 7, init_a}, 2, 0, 7, 5}, T{-0.5}); + test_scalar_block_multiplications({{1, 1, init_a}, 0, 0, 1, 1}, + T{3.5}); + test_scalar_block_multiplications({{13, 15, init_a}, 1, 2, 3, 4}, + T{0.}); + test_scalar_block_multiplications({{5, 9, init_a}, 2, 2, 2, 2}, + T{-2.5}); + test_scalar_block_multiplications({{15, 15, init_a}, 3, 4, 5, 5}, + T{42.}); + test_scalar_block_multiplications({{5, 5, init_b}, 1, 0, 3, 2}, + T{-5.}); + test_scalar_block_multiplications({{10, 1, init_a}, 0, 0, 5, 1}, + T{1.}); + test_scalar_block_multiplications({{1, 10, init_a}, 0, 0, 1, 5}, + T{6.}); + test_scalar_block_multiplications({{21, 5, init_0}, 4, 4, 10, 1}, + T{10.1}); + test_scalar_block_multiplications({{11, 7, init_a}, 2, 0, 7, 5}, + T{-0.5}); }; -TTS_CASE_TPL("Check block division with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check block division with scalar", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a / b; }; - auto s_op = [](auto& a, auto b) { return a /= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a / b; }; + auto s_op = [](auto& a, auto b) { return a /= b; }; - test_block_scalar_operations({{ 1, 1, init_a}, 0, 0, 1, 1}, T{ 3.5}, op, s_op); - test_block_scalar_operations({{13, 15, init_a}, 1, 2, 3, 4}, T{-2.5}, op, s_op); - test_block_scalar_operations({{ 5, 9, init_a}, 2, 2, 2, 2}, T{ 42. }, op, s_op); - test_block_scalar_operations({{15, 15, init_a}, 3, 4, 5, 5}, T{-5. }, op, s_op); - test_block_scalar_operations({{ 5, 5, init_b}, 1, 0, 3, 2}, T{ 1. }, op, s_op); - test_block_scalar_operations({{10, 1, init_a}, 0, 0, 5, 1}, T{ 0. }, op, s_op); - test_block_scalar_operations({{ 1, 10, init_a}, 0, 0, 1, 5}, T{ 6. }, op, s_op); - test_block_scalar_operations({{21, 5, init_0}, 4, 4, 10, 1}, T{ 10.}, op, s_op); - test_block_scalar_operations({{11, 7, init_a}, 2, 0, 7, 5}, T{-0.5}, op, s_op); + test_block_scalar_operations({{1, 1, init_a}, 0, 0, 1, 1}, T{3.5}, + op, s_op); + test_block_scalar_operations({{13, 15, init_a}, 1, 2, 3, 4}, + T{-2.5}, op, s_op); + test_block_scalar_operations({{5, 9, init_a}, 2, 2, 2, 2}, T{42.}, + op, s_op); + test_block_scalar_operations({{15, 15, init_a}, 3, 4, 5, 5}, T{-5.}, + op, s_op); + test_block_scalar_operations({{5, 5, init_b}, 1, 0, 3, 2}, T{1.}, + op, s_op); + test_block_scalar_operations({{10, 1, init_a}, 0, 0, 5, 1}, T{0.}, + op, s_op); + test_block_scalar_operations({{1, 10, init_a}, 0, 0, 1, 5}, T{6.}, + op, s_op); + test_block_scalar_operations({{21, 5, init_0}, 4, 4, 10, 1}, T{10.}, + op, s_op); + test_block_scalar_operations({{11, 7, init_a}, 2, 0, 7, 5}, T{-0.5}, + op, s_op); }; - diff --git a/test/unit/common/arithmetic.hpp b/test/unit/common/arithmetic.hpp index ddd2ccd..7c6e41b 100644 --- a/test/unit/common/arithmetic.hpp +++ b/test/unit/common/arithmetic.hpp @@ -12,21 +12,21 @@ namespace rotgen::tests { - template - void check_shape_functions(T original) + template void check_shape_functions(T original) { - using mat_t = matrix; + using mat_t = + matrix; mat_t result(original.cols(), original.rows()); - prepare([&](auto r, auto c) { return original(c,r); },result); + prepare([&](auto r, auto c) { return original(c, r); }, result); - TTS_EQUAL(transpose(original) , result ); - TTS_EQUAL(conjugate(original) , original); - TTS_EQUAL(adjoint(original) , result ); + TTS_EQUAL(transpose(original), result); + TTS_EQUAL(conjugate(original), original); + TTS_EQUAL(adjoint(original), result); - if constexpr(T::is_defined_static) + if constexpr (T::is_defined_static) { - if constexpr(T::RowsAtCompileTime == T::ColsAtCompileTime) + if constexpr (T::RowsAtCompileTime == T::ColsAtCompileTime) { mat_t ref = original; transposeInPlace(original); @@ -49,37 +49,37 @@ namespace rotgen::tests } } - if constexpr(!rotgen::use_expression_templates) + if constexpr (!rotgen::use_expression_templates) { - TTS_EXPECT(verify_rotgen_reentrance( original.transpose()) ); - TTS_EXPECT(verify_rotgen_reentrance( original.conjugate()) ); - TTS_EXPECT(verify_rotgen_reentrance( original.adjoint()) ); + TTS_EXPECT(verify_rotgen_reentrance(original.transpose())); + TTS_EXPECT(verify_rotgen_reentrance(original.conjugate())); + TTS_EXPECT(verify_rotgen_reentrance(original.adjoint())); } } - template - void check_reduction_functions(const T& input) + template void check_reduction_functions(T const& input) { - using EigenMatrix = Eigen::Matrix; + using EigenMatrix = + Eigen::Matrix; EigenMatrix ref(input.rows(), input.cols()); - prepare([&](auto r, auto c) { return input(r,c); }, ref); + prepare([&](auto r, auto c) { return input(r, c); }, ref); - TTS_ULP_EQUAL(sum(input) , ref.sum() , 2); - TTS_ULP_EQUAL(prod(input) , ref.prod(), 2); - TTS_ULP_EQUAL(mean(input) , ref.mean(), 2); - TTS_EQUAL(trace(input) , ref.trace()); - TTS_EQUAL(minCoeff(input) , ref.minCoeff()); - TTS_EQUAL(maxCoeff(input) , ref.maxCoeff()); + TTS_ULP_EQUAL(sum(input), ref.sum(), 2); + TTS_ULP_EQUAL(prod(input), ref.prod(), 2); + TTS_ULP_EQUAL(mean(input), ref.mean(), 2); + TTS_EQUAL(trace(input), ref.trace()); + TTS_EQUAL(minCoeff(input), ref.minCoeff()); + TTS_EQUAL(maxCoeff(input), ref.maxCoeff()); { int row, col, ref_row, ref_col; - TTS_EQUAL(minCoeff(input,&row, &col), ref.minCoeff(&ref_row, &ref_col)); + TTS_EQUAL(minCoeff(input, &row, &col), ref.minCoeff(&ref_row, &ref_col)); TTS_EQUAL(row, ref_row); TTS_EQUAL(col, ref_col); - TTS_EQUAL(maxCoeff(input,&row, &col), ref.maxCoeff(&ref_row, &ref_col)); + TTS_EQUAL(maxCoeff(input, &row, &col), ref.maxCoeff(&ref_row, &ref_col)); TTS_EQUAL(row, ref_row); TTS_EQUAL(col, ref_col); } diff --git a/test/unit/common/cwise.hpp b/test/unit/common/cwise.hpp index 712de11..f34badb 100644 --- a/test/unit/common/cwise.hpp +++ b/test/unit/common/cwise.hpp @@ -12,81 +12,82 @@ namespace rotgen::tests { - template - void check_cwise_functions(const T& input) + template void check_cwise_functions(T const& input) { - using EigenMatrix = Eigen::Matrix; - using mat_t = matrix; + using EigenMatrix = + Eigen::Matrix; + using mat_t = + matrix; TTS_WHEN("Unary Cwise operations") { EigenMatrix e_ref(input.rows(), input.cols()); - prepare([&](auto r, auto c) { return input(r,c); }, e_ref); + prepare([&](auto r, auto c) { return input(r, c); }, e_ref); mat_t ref(input.rows(), input.cols()); TTS_AND_THEN(".cwiseAbs") { e_ref = e_ref.cwiseAbs(); - prepare([&](auto r, auto c) { return e_ref(r,c); }, ref); + prepare([&](auto r, auto c) { return e_ref(r, c); }, ref); TTS_EQUAL(input.cwiseAbs(), ref); } TTS_AND_THEN(".cwiseAbs2") { e_ref = e_ref.cwiseAbs2(); - prepare([&](auto r, auto c) { return e_ref(r,c); }, ref); + prepare([&](auto r, auto c) { return e_ref(r, c); }, ref); TTS_EQUAL(input.cwiseAbs2(), ref); } TTS_AND_THEN(".cwiseInverse") { e_ref = e_ref.cwiseInverse(); - prepare([&](auto r, auto c) { return e_ref(r,c); }, ref); + prepare([&](auto r, auto c) { return e_ref(r, c); }, ref); TTS_EQUAL(input.cwiseInverse(), ref); } TTS_AND_THEN(".cwiseSqrt") { e_ref = e_ref.cwiseAbs().cwiseSqrt(); - auto mat = input.cwiseAbs(); + auto mat = input.cwiseAbs(); auto proper_input = mat.cwiseSqrt(); - for(rotgen::Index r=0;r - void check_norms_functions(const T& input) + template void check_norms_functions(T const& input) { - using EigenMatrix = Eigen::Matrix; + using EigenMatrix = + Eigen::Matrix; EigenMatrix ref(input.rows(), input.cols()); - prepare([&](auto r, auto c) { return input(r,c); }, ref); + prepare([&](auto r, auto c) { return input(r, c); }, ref); - TTS_EQUAL(rotgen::norm(input) , ref.norm()); - TTS_EQUAL(rotgen::squaredNorm(input) , ref.squaredNorm()); - TTS_EQUAL(rotgen::lpNorm<1>(input) , ref.template lpNorm<1>()); - TTS_EQUAL(rotgen::lpNorm<2>(input) , ref.template lpNorm<2>()); - TTS_EQUAL(rotgen::lpNorm(input) , ref.template lpNorm()); + TTS_EQUAL(rotgen::norm(input), ref.norm()); + TTS_EQUAL(rotgen::squaredNorm(input), ref.squaredNorm()); + TTS_EQUAL(rotgen::lpNorm<1>(input), ref.template lpNorm<1>()); + TTS_EQUAL(rotgen::lpNorm<2>(input), ref.template lpNorm<2>()); + TTS_EQUAL(rotgen::lpNorm(input), + ref.template lpNorm()); - if constexpr(T::IsVectorAtCompileTime) + if constexpr (T::IsVectorAtCompileTime) { EigenMatrix e_norm = ref.normalized(); - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; mat_t norm_ref(input.rows(), input.cols()); - prepare([&](auto r, auto c) { return e_norm(r,c); }, norm_ref); + prepare([&](auto r, auto c) { return e_norm(r, c); }, norm_ref); TTS_EQUAL(rotgen::normalized(input), norm_ref); diff --git a/test/unit/common/references.hpp b/test/unit/common/references.hpp index 15bd14b..3aa662c 100644 --- a/test/unit/common/references.hpp +++ b/test/unit/common/references.hpp @@ -15,26 +15,25 @@ namespace rotgen::tests { struct matrix_descriptor { - rotgen::Index rows, cols; - std::function init_fn; + rotgen::Index rows, cols; + std::function init_fn; }; - template + template struct static_matrix_descriptor { static constexpr rotgen::Index rows = Rows; static constexpr rotgen::Index cols = Cols; - std::function init_fn; + std::function init_fn; }; - template - struct matrix_block_test_case + template struct matrix_block_test_case { matrix_descriptor matrix_desc; - rotgen::Index i0, j0, ni, nj; + rotgen::Index i0, j0, ni, nj; }; - template + template struct static_matrix_block_test_case { matrix_descriptor matrix_desc; @@ -43,25 +42,25 @@ namespace rotgen::tests rotgen::Index i0, j0; }; - void prepare(rotgen::Index rows, rotgen::Index cols, auto const &init_fn, auto& output) + void prepare(rotgen::Index rows, + rotgen::Index cols, + auto const& init_fn, + auto& output) { for (rotgen::Index r = 0; r < rows; ++r) - for (rotgen::Index c = 0; c < cols; ++c) - output(r,c) = init_fn(r, c); + for (rotgen::Index c = 0; c < cols; ++c) output(r, c) = init_fn(r, c); } void prepare(auto fn, auto& output) { for (rotgen::Index r = 0; r < output.rows(); ++r) - for (rotgen::Index c = 0; c < output.cols(); ++c) - output(r,c) = fn(r, c); + for (rotgen::Index c = 0; c < output.cols(); ++c) output(r, c) = fn(r, c); } auto generate_matrix_references() { auto fn = [](auto r, auto c) { return r + 3 * c - 2.5; }; - std::vector cases = - { + std::vector cases = { // Singular matrix {1, 1, fn}, // Square matrix below MAX_SIZE @@ -81,8 +80,7 @@ namespace rotgen::tests // Thick matrix at MAX_SIZE {2, 8, fn}, // Thick matrix above MAX_SIZE - {3, 10, fn} - }; + {3, 10, fn}}; return cases; } @@ -90,102 +88,96 @@ namespace rotgen::tests auto generate_static_matrix_references() { auto fn = [](auto r, auto c) { return r + 3 * c - 2.5; }; - std::tuple cases = - { - // Singular matrix - static_matrix_descriptor< 1, 1>{fn}, - // Square matrix below MAX_SIZE - static_matrix_descriptor< 3, 3>{fn}, - // Square matrix at MAX_SIZE - static_matrix_descriptor< 4, 4>{fn}, - // Square matrix above MAX_SIZE - static_matrix_descriptor< 7, 7>{fn}, - // Tall matrix below MAX_SIZE - static_matrix_descriptor< 5, 2>{fn}, - // Tall matrix at MAX_SIZE - static_matrix_descriptor< 8, 2>{fn}, - // Tall matrix above MAX_SIZE - static_matrix_descriptor<10, 3>{fn}, - // Thick matrix below MAX_SIZE - static_matrix_descriptor< 2, 5>{fn}, - // Thick matrix at MAX_SIZE - static_matrix_descriptor< 2, 8>{fn}, - // Thick matrix above MAX_SIZE - static_matrix_descriptor< 3,10>{fn} - }; + std::tuple cases = {// Singular matrix + static_matrix_descriptor<1, 1>{fn}, + // Square matrix below MAX_SIZE + static_matrix_descriptor<3, 3>{fn}, + // Square matrix at MAX_SIZE + static_matrix_descriptor<4, 4>{fn}, + // Square matrix above MAX_SIZE + static_matrix_descriptor<7, 7>{fn}, + // Tall matrix below MAX_SIZE + static_matrix_descriptor<5, 2>{fn}, + // Tall matrix at MAX_SIZE + static_matrix_descriptor<8, 2>{fn}, + // Tall matrix above MAX_SIZE + static_matrix_descriptor<10, 3>{fn}, + // Thick matrix below MAX_SIZE + static_matrix_descriptor<2, 5>{fn}, + // Thick matrix at MAX_SIZE + static_matrix_descriptor<2, 8>{fn}, + // Thick matrix above MAX_SIZE + static_matrix_descriptor<3, 10>{fn}}; return cases; } - template - auto generate_block_references() + template auto generate_block_references() { - rotgen::tests::matrix_descriptor base{16,16,[](auto r, auto c) { return r + 3 * c - 2.5; }}; + rotgen::tests::matrix_descriptor base{ + 16, 16, [](auto r, auto c) { return r + 3 * c - 2.5; }}; - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; - std::vector> cases = - { + std::vector> cases = { // Singular blocks {base, 0, 0, 1, 1}, {base, 3, 2, 1, 1}, - {base, 4,11, 1, 1}, - {base,15,15, 1, 1}, + {base, 4, 11, 1, 1}, + {base, 15, 15, 1, 1}, // Square block below MAX_SIZE - {base,7,9, 3, 3}, + {base, 7, 9, 3, 3}, // Square block at MAX_SIZE - {base,6,3, 4, 4}, + {base, 6, 3, 4, 4}, // Square block above MAX_SIZE - {base,6,3, 6, 6}, + {base, 6, 3, 6, 6}, // Tall block below MAX_SIZE - {base,6,3, 5, 2}, + {base, 6, 3, 5, 2}, // Tall block at MAX_SIZE - {base,6,3, 8, 2}, + {base, 6, 3, 8, 2}, // Tall block above MAX_SIZE - {base,6,3, 7, 3}, + {base, 6, 3, 7, 3}, // Thick block below MAX_SIZE - {base,6,3, 2, 5}, + {base, 6, 3, 2, 5}, // Thick block at MAX_SIZE - {base,6,3, 2, 8}, + {base, 6, 3, 2, 8}, // Thick block above MAX_SIZE - {base,6,3, 3, 7} - }; + {base, 6, 3, 3, 7}}; return cases; } - template - auto generate_static_block_references() + + template auto generate_static_block_references() { - rotgen::tests::matrix_descriptor base{16,16,[](auto r, auto c) { return r + 3 * c - 2.5; }}; + rotgen::tests::matrix_descriptor base{ + 16, 16, [](auto r, auto c) { return r + 3 * c - 2.5; }}; - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; - std::tuple cases = - { + std::tuple cases = { // Singular blocks static_matrix_block_test_case{base, 0, 0}, static_matrix_block_test_case{base, 3, 2}, - static_matrix_block_test_case{base, 4,11}, - static_matrix_block_test_case{base,15,15}, + static_matrix_block_test_case{base, 4, 11}, + static_matrix_block_test_case{base, 15, 15}, // Square block below MAX_SIZE - static_matrix_block_test_case{base,7,9}, + static_matrix_block_test_case{base, 7, 9}, // Square block at MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Square block above MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Tall block below MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Tall block at MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Tall block above MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Thick block below MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Thick block at MAX_SIZE - static_matrix_block_test_case{base,6,3}, + static_matrix_block_test_case{base, 6, 3}, // Thick block above MAX_SIZE - static_matrix_block_test_case{base,6,3} - }; + static_matrix_block_test_case{base, 6, 3}}; return cases; } diff --git a/test/unit/functions/qr.cpp b/test/unit/functions/qr.cpp index 4ffa6f5..3b0cd01 100644 --- a/test/unit/functions/qr.cpp +++ b/test/unit/functions/qr.cpp @@ -8,27 +8,28 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("System solver using QR", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("System solver using QR", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix - a { { 2.3, -1, 0.1} - , {-1.6, 2.6, -1} - , { 0.3, -1, 2} - }; + rotgen::matrix a{{2.3, -1, 0.1}, + {-1.6, 2.6, -1}, + {0.3, -1, 2}}; - rotgen::matrix b(3,1); - b(0) = b(2) = 1; b(1) = 0; + rotgen::matrix b(3, 1); + b(0) = b(2) = 1; + b(1) = 0; - rotgen::matrix r(3,1), error; + rotgen::matrix r(3, 1), error; - auto x = rotgen::extract(r,0,0,3,1); + auto x = rotgen::extract(r, 0, 0, 3, 1); rotgen::solver::qr(x, a, b); error = a * r - b; auto eps = std::numeric_limits::epsilon(); - TTS_LESS(rotgen::maxCoeff(rotgen::abs(error)) / eps, 5) - << "Result:\n" << r << "\n" - << "Residuals:\n" << error << "\n"; -}; \ No newline at end of file + TTS_LESS(rotgen::maxCoeff(rotgen::abs(error)) / eps, 5) << "Result:\n" + << r << "\n" + << "Residuals:\n" + << error << "\n"; +}; diff --git a/test/unit/functions/rowwise.cpp b/test/unit/functions/rowwise.cpp index a356f2c..bc7f0ba 100644 --- a/test/unit/functions/rowwise.cpp +++ b/test/unit/functions/rowwise.cpp @@ -8,47 +8,58 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("rowwise API", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("rowwise API", rotgen::tests::types)( + tts::type>) { - using e_t = Eigen::Matrix; - e_t ref = e_t::Random(4,4); + using e_t = Eigen::Matrix; + e_t ref = e_t::Random(4, 4); auto ref_rw = ref.rowwise(); - rotgen::matrix mat(4,4); - rotgen::tests::prepare([&](auto r, auto c) { return ref(r,c); }, mat); + rotgen::matrix mat(4, 4); + rotgen::tests::prepare([&](auto r, auto c) { return ref(r, c); }, mat); auto rw = rotgen::rowwise(mat); - for(rotgen::Index i=0;i( tts::type< tts::types> ) +TTS_CASE_TPL("colwise API", rotgen::tests::types)( + tts::type>) { - using e_t = Eigen::Matrix; - e_t ref = e_t::Random(4,4); + using e_t = Eigen::Matrix; + e_t ref = e_t::Random(4, 4); auto ref_rw = ref.colwise(); - rotgen::matrix mat(4,4); - rotgen::tests::prepare([&](auto r, auto c) { return ref(r,c); }, mat); + rotgen::matrix mat(4, 4); + rotgen::tests::prepare([&](auto r, auto c) { return ref(r, c); }, mat); auto rw = rotgen::colwise(mat); - for(rotgen::Index i=0;i #include -template -struct MatrixDescriptor +template struct MatrixDescriptor { std::size_t rows, cols; - std::function init_fn; + std::function init_fn; }; -template -void test_matrix_sizes(std::size_t rows, std::size_t cols, - const std::function &init_fn, - const std::array, N>& resize_dimensions) +template +void test_matrix_sizes( + std::size_t rows, + std::size_t cols, + std::function const& init_fn, + std::array, N> const& resize_dimensions) { MatrixType matrix(rows, cols); for (std::size_t r = 0; r < rows; ++r) - for (std::size_t c = 0; c < cols; ++c) - init_fn(matrix, r, c); + for (std::size_t c = 0; c < cols; ++c) init_fn(matrix, r, c); - TTS_EQUAL(rotgen::size(matrix), rows*cols); + TTS_EQUAL(rotgen::size(matrix), rows * cols); - for (std::size_t i = 0; i < N; ++i) { + for (std::size_t i = 0; i < N; ++i) + { int r = resize_dimensions[i].first; int c = resize_dimensions[i].second; @@ -38,24 +39,22 @@ void test_matrix_sizes(std::size_t rows, std::size_t cols, TTS_EQUAL(rotgen::rows(matrix), static_cast(r)); TTS_EQUAL(rotgen::cols(matrix), static_cast(c)); - TTS_EQUAL(rotgen::size(matrix), static_cast(r*c)); + TTS_EQUAL(rotgen::size(matrix), static_cast(r * c)); } rotgen::conservativeResize(matrix, rows, cols); - TTS_EQUAL(rotgen::size(matrix), rows*cols); + TTS_EQUAL(rotgen::size(matrix), rows * cols); int i = 1; - for(std::size_t r=0;r>> test_matrices = { {3, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r + c; }}, {2, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 0.0; }}, - {2, 7, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = -r*r*r - c*c - 1.23; }}, - {17, 3, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r*c + 0.98; }}, + {2, 7, + [](auto& m, std::size_t r, std::size_t c) { + m(r, c) = -r * r * r - c * c - 1.23; + }}, + {17, 3, + [](auto& m, std::size_t r, std::size_t c) { m(r, c) = r * c + 0.98; }}, {1, 1, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = 42.0; }}, - {10, 11, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = std::tan(r + c); }}, - {1, 5, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = -1.5*r + 2.56*c + 3.33; }}, - {7, 1, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r == c ? 1.0 : 0.0); }}, - {0, 0, [](auto& m, std::size_t r, std::size_t c) { m(r, c) = (r == c ? 1.0 : 0.0); }}, + {10, 11, + [](auto& m, std::size_t r, std::size_t c) { m(r, c) = std::tan(r + c); }}, + {1, 5, + [](auto& m, std::size_t r, std::size_t c) { + m(r, c) = -1.5 * r + 2.56 * c + 3.33; + }}, + {7, 1, + [](auto& m, std::size_t r, std::size_t c) { + m(r, c) = (r == c ? 1.0 : 0.0); + }}, + {0, 0, + [](auto& m, std::size_t r, std::size_t c) { + m(r, c) = (r == c ? 1.0 : 0.0); + }}, }; - for (const auto& [rows, cols, init_fn] : test_matrices) - test_matrix_sizes>(rows, cols, init_fn, std::array{ - std::pair{1, 2}, std::pair{11, 17}, std::pair{4, 5}, - std::pair{9, 1}, std::pair{3, 8}, std::pair{22, 0}, - }); + for (auto const& [rows, cols, init_fn] : test_matrices) + test_matrix_sizes>(rows, cols, init_fn, + std::array{ + std::pair{1, 2}, + std::pair{11, 17}, + std::pair{4, 5}, + std::pair{9, 1}, + std::pair{3, 8}, + std::pair{22, 0}, + }); }; diff --git a/test/unit/functions/svd.cpp b/test/unit/functions/svd.cpp index 6874817..0e836ee 100644 --- a/test/unit/functions/svd.cpp +++ b/test/unit/functions/svd.cpp @@ -8,23 +8,24 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) -( tts::type< tts::types> ) +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::matrix::Random(5,5); + auto m = + rotgen::matrix::Random(5, 5); auto decomp = rotgen::svd(m); - do - { - rank = decomp.rank(); + do { + rank = decomp.rank(); - auto u = decomp.U(rank); - auto d = decomp.singular_values(rank); + auto u = decomp.U(rank); + auto d = decomp.singular_values(rank); auto dd = decomp.D(rank); - auto v = decomp.V(rank); + auto v = decomp.V(rank); TTS_EQUAL(rank, i); @@ -32,34 +33,36 @@ TTS_CASE_TPL("SVD decomposition - Dynamic case", rotgen::tests::types) auto error = m - rec; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.) - << "Result:\n" << rec << "\n" - << "Residuals:\n" << error << "\n"; + << "Result:\n" + << rec << "\n" + << "Residuals:\n" + << error << "\n"; // Reduce rank by duplicating one column i--; - col(m,i) = col(m,0); + col(m, i) = col(m, 0); decomp = rotgen::svd(m); - }while(rank != 1); + } while (rank != 1); }; -TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types) -( tts::type< tts::types> ) +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::matrix::Random(); + auto m = rotgen::matrix::Random(); auto decomp = rotgen::svd(m); - do - { - rank = decomp.rank(); + do { + rank = decomp.rank(); - auto u = decomp.U(rank); - auto d = decomp.singular_values(rank); + auto u = decomp.U(rank); + auto d = decomp.singular_values(rank); auto dd = decomp.D(rank); - auto v = decomp.V(rank); + auto v = decomp.V(rank); TTS_EQUAL(rank, i); @@ -67,13 +70,15 @@ TTS_CASE_TPL("SVD decomposition - Static case", rotgen::tests::types) auto error = m - rec; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 16.) - << "Result:\n" << rec << "\n" - << "Residuals:\n" << error << "\n"; + << "Result:\n" + << rec << "\n" + << "Residuals:\n" + << error << "\n"; // Reduce rank by duplicating one column i--; - col(m,i) = col(m,0); + col(m, i) = col(m, 0); decomp = rotgen::svd(m); - }while(rank != 1); -}; \ No newline at end of file + } while (rank != 1); +}; diff --git a/test/unit/map/arithmetic_functions.cpp b/test/unit/map/arithmetic_functions.cpp index 4257c47..21346d9 100644 --- a/test/unit/map/arithmetic_functions.cpp +++ b/test/unit/map/arithmetic_functions.cpp @@ -9,101 +9,109 @@ #include "unit/common/arithmetic.hpp" #include -TTS_CASE_TPL("Test dynamic map transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic map transposition-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; mat_t base(rows, cols); - rotgen::tests::prepare(rows,cols,fn,base); + rotgen::tests::prepare(rows, cols, fn, base); - rotgen::map input(base.data(),rows,cols); + rotgen::map input(base.data(), rows, cols); rotgen::tests::check_shape_functions(input); } }; -TTS_CASE_TPL("Test static map transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static map transposition-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix base(D::rows,D::cols); - rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base); + auto process = [](D const& desc) { + rotgen::matrix base(D::rows, + D::cols); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); - rotgen::map> input(base.data()); + rotgen::map> input( + base.data()); rotgen::tests::check_shape_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic map reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic map reduction-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix base(rows, cols); - rotgen::tests::prepare(rows,cols,fn,base); + rotgen::matrix base(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, base); - rotgen::map> input(base.data(),rows,cols); + rotgen::map> + input(base.data(), rows, cols); rotgen::tests::check_reduction_functions(input); } }; -TTS_CASE_TPL("Test static map reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static map reduction-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix base(D::rows,D::cols); - rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base); + auto process = [](D const& desc) { + rotgen::matrix base(D::rows, + D::cols); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); - rotgen::map> input(base.data()); + rotgen::map> input( + base.data()); rotgen::tests::check_reduction_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + 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 v = rotgen::setConstant>(1, + 16, + 2); +auto a = rotgen::map(v.data(), 1, 8); +auto b = rotgen::map(v.data() + 8, 1, 8); + +TTS_EQUAL(rotgen::dot(a, b), 32); +} + { - { - auto v = rotgen::setConstant>(1,16,2); - auto a = rotgen::map(v.data(),1,8); - auto b = rotgen::map(v.data()+8,1,8); + auto v = rotgen::setConstant>(16, 1, 2); + auto a = rotgen::map(v.data(), 8, 1); + auto b = rotgen::map(v.data() + 8, 8, 1); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto v = rotgen::setConstant>(16,1,2); - auto a = rotgen::map(v.data(),8,1); - auto b = rotgen::map(v.data()+8,8,1); +{ + auto v = rotgen::setConstant>(1, 16, 2); + auto a = rotgen::map>(v.data()); + auto b = rotgen::map>(v.data() + 8); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto v = rotgen::setConstant>(1,16,2); - auto a = rotgen::map>(v.data()); - auto b = rotgen::map>(v.data()+8); +{ + auto v = rotgen::setConstant>(1, 16, 2); + auto a = rotgen::map>(v.data()); + auto b = rotgen::map>(v.data() + 8); - TTS_EQUAL(rotgen::dot(a,b), 32); - } - - { - auto v = rotgen::setConstant>(1,16,2); - auto a = rotgen::map>(v.data()); - auto b = rotgen::map>(v.data()+8); - - TTS_EQUAL(rotgen::dot(a,b), 32); - } -}; \ No newline at end of file + TTS_EQUAL(rotgen::dot(a, b), 32); +} +} +; diff --git a/test/unit/map/basic_api.cpp b/test/unit/map/basic_api.cpp index 2dfd891..a7bedd8 100644 --- a/test/unit/map/basic_api.cpp +++ b/test/unit/map/basic_api.cpp @@ -8,88 +8,90 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("Function size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Function size", rotgen::tests::types)( + tts::type>) { - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - rotgen::map> dyn_map(data,1,12); + rotgen::map> + dyn_map(data, 1, 12); TTS_EQUAL(dyn_map.rows(), rotgen::Index{1}); TTS_EQUAL(dyn_map.cols(), rotgen::Index{12}); - rotgen::map> s112_map(data); + rotgen::map> s112_map(data); 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); + rotgen::map> s121_map(data); 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); + rotgen::map> s34_map(data); 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); + rotgen::map> s62_map(data); 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::types> ) +TTS_CASE_TPL("Test coefficient accessors", + rotgen::tests::types)( + tts::type>) { - using base = rotgen::matrix; + using base = rotgen::matrix; - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - rotgen::map a(data,4,3); - for(rotgen::Index i=0;i<4;i++) + rotgen::map a(data, 4, 3); + for (rotgen::Index i = 0; i < 4; i++) { - for(rotgen::Index j=0;j<3;j++) + for (rotgen::Index j = 0; j < 3; j++) { - if constexpr(O::value) TTS_EQUAL(a(i,j), data[j+3*i]); - else TTS_EQUAL(a(i,j), data[i+4*j]); + if constexpr (O::value) TTS_EQUAL(a(i, j), data[j + 3 * i]); + else TTS_EQUAL(a(i, j), data[i + 4 * j]); } } a(1, 1) = 42; - TTS_EQUAL(a(1,1), 42); + TTS_EQUAL(a(1, 1), 42); T& ref = a(2, 2); ref = 17; TTS_EQUAL(a(2, 2), 17); }; -TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types) -( tts::type< tts::types> ) +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}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - auto m = [&]() - { - if constexpr(O::value == rotgen::ColMajor) + auto m = [&]() { + if constexpr (O::value == rotgen::ColMajor) { - using base = rotgen::matrix; - rotgen::map a(data,12); + using base = rotgen::matrix; + rotgen::map a(data, 12); return a; } else { - using base = rotgen::matrix; - rotgen::map a(data,12); + using base = rotgen::matrix; + rotgen::map a(data, 12); return a; } }(); TTS_EXPECT(m.IsVectorAtCompileTime); - for(rotgen::Index i=0;i -TTS_CASE_TPL("map constructor from pointer and single static size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("map constructor from pointer and single static size", + rotgen::tests::types)( + tts::type>) { - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - rotgen::map> row_map(data); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(row_map(i), data[i]); + rotgen::map> row_map(data); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(row_map(i), data[i]); - rotgen::map const> const_row_map(data); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(const_row_map(i), data[i]); + rotgen::map const> const_row_map( + data); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_row_map(i), data[i]); - rotgen::map> col_map(data); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(col_map(i), data[i]); + rotgen::map> col_map(data); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(col_map(i), data[i]); - rotgen::map const> const_col_map(data); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(const_col_map(i), data[i]); + rotgen::map const> const_col_map( + data); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_col_map(i), data[i]); }; -TTS_CASE_TPL("map constructor from pointer and static size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("map constructor from pointer and static size", + rotgen::tests::types)( + tts::type>) { - using base = rotgen::matrix; + using base = rotgen::matrix; - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; rotgen::map dyn_map(data); - for(rotgen::Index i=0;i<4;i++) + for (rotgen::Index i = 0; i < 4; i++) { - for(rotgen::Index j=0;j<3;j++) + for (rotgen::Index j = 0; j < 3; j++) { - if constexpr(O::value) TTS_EQUAL(dyn_map(i,j), data[j+3*i]); - else TTS_EQUAL(dyn_map(i,j), data[i+4*j]); + if constexpr (O::value) TTS_EQUAL(dyn_map(i, j), data[j + 3 * i]); + else TTS_EQUAL(dyn_map(i, j), data[i + 4 * j]); } } }; -TTS_CASE_TPL("map constructor from pointer and single dynamic size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("map constructor from pointer and single dynamic size", + rotgen::tests::types)( + tts::type>) { - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - rotgen::map> row_map(data,12); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(row_map(i), data[i]); + rotgen::map> row_map( + data, 12); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(row_map(i), data[i]); - rotgen::map const> const_row_map(data,12); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(const_row_map(i), data[i]); + rotgen::map const> + const_row_map(data, 12); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_row_map(i), data[i]); - rotgen::map> col_map(data,12); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(col_map(i), data[i]); + rotgen::map> col_map( + data, 12); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(col_map(i), data[i]); - rotgen::map const> const_col_map(data,12); - for(rotgen::Index i=0;i<12;i++) - TTS_EQUAL(const_col_map(i), data[i]); + rotgen::map const> + const_col_map(data, 12); + for (rotgen::Index i = 0; i < 12; i++) TTS_EQUAL(const_col_map(i), data[i]); }; -TTS_CASE_TPL("map constructor from pointer and dynamic size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("map constructor from pointer and dynamic size", + rotgen::tests::types)( + tts::type>) { - using base = rotgen::matrix; + using base = rotgen::matrix; - T data[] = {1,2,3,4,5,6,7,8,9,10,11,12}; + T data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - rotgen::map dyn_map(data,4,3); - for(rotgen::Index i=0;i<4;i++) + rotgen::map dyn_map(data, 4, 3); + for (rotgen::Index i = 0; i < 4; i++) { - for(rotgen::Index j=0;j<3;j++) + for (rotgen::Index j = 0; j < 3; j++) { - if constexpr(O::value) TTS_EQUAL(dyn_map(i,j), data[j+3*i]); - else TTS_EQUAL(dyn_map(i,j), data[i+4*j]); + if constexpr (O::value) TTS_EQUAL(dyn_map(i, j), data[j + 3 * i]); + else TTS_EQUAL(dyn_map(i, j), data[i + 4 * j]); } } }; diff --git a/test/unit/map/cwise.cpp b/test/unit/map/cwise.cpp index ddc3fb0..d4b5980 100644 --- a/test/unit/map/cwise.cpp +++ b/test/unit/map/cwise.cpp @@ -9,33 +9,38 @@ #include "unit/common/cwise.hpp" #include -TTS_CASE_TPL("Test dynamic map cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic map cwise operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix base(rows, cols); - rotgen::tests::prepare(rows,cols,fn,base); + rotgen::matrix base(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, base); - rotgen::map> input(base.data(),rows,cols); + rotgen::map> + input(base.data(), rows, cols); rotgen::tests::check_cwise_functions(input); } }; -TTS_CASE_TPL("Test static map cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static map cwise operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix base(D::rows,D::cols); - rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base); + auto process = [](D const& desc) { + rotgen::matrix base(D::rows, + D::cols); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); - rotgen::map> input(base.data()); + rotgen::map> input( + base.data()); rotgen::tests::check_cwise_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); -}; \ No newline at end of file + std::apply([&](auto const&... d) { (process(d), ...); }, cases); +}; diff --git a/test/unit/map/norms.cpp b/test/unit/map/norms.cpp index 610eeeb..8802d33 100644 --- a/test/unit/map/norms.cpp +++ b/test/unit/map/norms.cpp @@ -9,33 +9,38 @@ #include "unit/common/norms.hpp" #include -TTS_CASE_TPL("Test dynamic map norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic map norm operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix base(rows, cols); - rotgen::tests::prepare(rows,cols,fn,base); + rotgen::matrix base(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, base); - rotgen::map> input(base.data(),rows,cols); + rotgen::map> + input(base.data(), rows, cols); rotgen::tests::check_norms_functions(input); } }; -TTS_CASE_TPL("Test static map norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static map norm operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix base(D::rows,D::cols); - rotgen::tests::prepare(base.rows(),base.cols(),desc.init_fn,base); + auto process = [](D const& desc) { + rotgen::matrix base(D::rows, + D::cols); + rotgen::tests::prepare(base.rows(), base.cols(), desc.init_fn, base); - rotgen::map> input(base.data()); + rotgen::map> input( + base.data()); rotgen::tests::check_norms_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); -}; \ No newline at end of file + std::apply([&](auto const&... d) { (process(d), ...); }, cases); +}; diff --git a/test/unit/map/operators.cpp b/test/unit/map/operators.cpp index 508c14f..fc65c21 100644 --- a/test/unit/map/operators.cpp +++ b/test/unit/map/operators.cpp @@ -9,8 +9,13 @@ #include #include -template -void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops) +template +void test_map_operations(rotgen::Index rows, + rotgen::Index cols, + auto a_init_fn, + auto b_init_fn, + auto ops, + auto self_ops) { MatrixType a_data(rows, cols); MatrixType b_data(rows, cols); @@ -19,8 +24,8 @@ void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) { - a_data(r,c) = a_init_fn(r, c); - b_data(r,c) = b_init_fn(r, c); + a_data(r, c) = a_init_fn(r, c); + b_data(r, c) = b_init_fn(r, c); } ref_data = ops(a_data, b_data); @@ -35,15 +40,19 @@ void test_map_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, TTS_EXPECT(verify_rotgen_reentrance(self_ops(a_map, b_map))); } -template -void test_map_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto fn, auto s, auto ops, auto self_ops) +template +void test_map_scalar_operations(rotgen::Index rows, + rotgen::Index cols, + auto fn, + auto s, + auto ops, + auto self_ops) { MatrixType a_data(rows, cols); MatrixType ref_data; for (rotgen::Index r = 0; r < rows; ++r) - for (rotgen::Index c = 0; c < cols; ++c) - a_data(r,c) = fn(r, c); + for (rotgen::Index c = 0; c < cols; ++c) a_data(r, c) = fn(r, c); ref_data = ops(a_data, s); rotgen::map a_map(a_data.data(), rows, cols); @@ -56,15 +65,17 @@ void test_map_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto fn, TTS_EXPECT(verify_rotgen_reentrance(self_ops(a_map, s))); } -template -void test_map_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s) +template +void test_map_scalar_multiplications(rotgen::Index rows, + rotgen::Index cols, + auto fn, + auto s) { MatrixType a_data(rows, cols); MatrixType ref_data; for (rotgen::Index r = 0; r < rows; ++r) - for (rotgen::Index c = 0; c < cols; ++c) - a_data(r,c) = fn(r, c); + for (rotgen::Index c = 0; c < cols; ++c) a_data(r, c) = fn(r, c); ref_data = a_data * s; rotgen::map a_map(a_data.data(), rows, cols); @@ -79,8 +90,11 @@ void test_map_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, aut TTS_EXPECT(verify_rotgen_reentrance(a_map *= s)); } -template -void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn) +template +void test_map_multiplication(rotgen::Index rows, + rotgen::Index cols, + auto a_init_fn, + auto b_init_fn) { MatrixType a_data(rows, cols); MatrixType b_data(cols, rows); @@ -89,8 +103,8 @@ void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init for (rotgen::Index r = 0; r < rows; ++r) for (rotgen::Index c = 0; c < cols; ++c) { - a_data(r,c) = a_init_fn(r,c); - b_data(c,r) = b_init_fn(c,r); + a_data(r, c) = a_init_fn(r, c); + b_data(c, r) = b_init_fn(c, r); } ref_data = a_data * b_data; @@ -100,103 +114,111 @@ void test_map_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init TTS_EQUAL(a_map * b_map, ref_data); TTS_EXPECT(verify_rotgen_reentrance(a_map * b_map)); - if(rows == cols) + if (rows == cols) { a_map *= b_map; TTS_EQUAL(a_map, ref_data); TTS_EXPECT(verify_rotgen_reentrance(a_map *= b_map)); } - } -inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c - 12; }; -inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; }; -inline constexpr auto init_0 = [](auto , auto ) { return 0; }; +inline constexpr auto init_a = [](auto r, auto c) { + return 9.9 * r * r * r - 6 * c - 12; +}; +inline constexpr auto init_b = [](auto r, auto c) { + return 3.1 * r + 4.2 * c - 12.3; +}; +inline constexpr auto init_0 = [](auto, auto) { return 0; }; -TTS_CASE_TPL("Check map addition", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check map addition", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a + b; }; - auto s_op = [](auto& a, auto b) { return a += b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a + b; }; + auto s_op = [](auto& a, auto b) { return a += b; }; - test_map_operations(1 , 1, init_a, init_b, op, s_op); - test_map_operations(3 , 5, init_a, init_b, op, s_op); - test_map_operations(5 , 3, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_b, init_a, op, s_op); + test_map_operations(1, 1, init_a, init_b, op, s_op); + test_map_operations(3, 5, init_a, init_b, op, s_op); + test_map_operations(5, 3, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_b, init_a, op, s_op); test_map_operations(10, 1, init_a, init_b, op, s_op); - test_map_operations(1 ,10, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_0, init_b, op, s_op); - test_map_operations(5 , 5, init_a, init_0, op, s_op); + test_map_operations(1, 10, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_0, init_b, op, s_op); + test_map_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check map subtraction", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check map subtraction", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a - b; }; - auto s_op = [](auto& a, auto b) { return a -= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a - b; }; + auto s_op = [](auto& a, auto b) { return a -= b; }; - test_map_operations(1 , 1, init_a, init_b, op, s_op); - test_map_operations(3 , 5, init_a, init_b, op, s_op); - test_map_operations(5 , 3, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_b, init_a, op, s_op); + test_map_operations(1, 1, init_a, init_b, op, s_op); + test_map_operations(3, 5, init_a, init_b, op, s_op); + test_map_operations(5, 3, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_b, init_a, op, s_op); test_map_operations(10, 1, init_a, init_b, op, s_op); - test_map_operations(1 ,10, init_a, init_b, op, s_op); - test_map_operations(5 , 5, init_0, init_b, op, s_op); - test_map_operations(5 , 5, init_a, init_0, op, s_op); + test_map_operations(1, 10, init_a, init_b, op, s_op); + test_map_operations(5, 5, init_0, init_b, op, s_op); + test_map_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check map multiplications", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check map multiplications", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; }; - test_map_multiplication(1 , 1, init_a , init_b ); - test_map_multiplication(3 , 5, init_a , init_b ); - test_map_multiplication(5 , 3, init_a , init_b ); - test_map_multiplication(5 , 5, init_a , init_b ); - test_map_multiplication(5 , 5, init_b , init_a ); - test_map_multiplication(5 , 5, init_a , init_a ); - test_map_multiplication(5 , 5, init_a , init_id); - test_map_multiplication(5 , 5, init_id, init_a ); - test_map_multiplication(10, 1, init_a , init_b ); - test_map_multiplication(1 ,10, init_a , init_b ); - test_map_multiplication(5 , 5, init_0 , init_b ); - test_map_multiplication(5 , 5, init_a , init_0 ); + test_map_multiplication(1, 1, init_a, init_b); + test_map_multiplication(3, 5, init_a, init_b); + test_map_multiplication(5, 3, init_a, init_b); + test_map_multiplication(5, 5, init_a, init_b); + test_map_multiplication(5, 5, init_b, init_a); + test_map_multiplication(5, 5, init_a, init_a); + test_map_multiplication(5, 5, init_a, init_id); + test_map_multiplication(5, 5, init_id, init_a); + test_map_multiplication(10, 1, init_a, init_b); + test_map_multiplication(1, 10, init_a, init_b); + test_map_multiplication(5, 5, init_0, init_b); + test_map_multiplication(5, 5, init_a, init_0); }; -TTS_CASE_TPL("Check map multiplication with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check map multiplication with scalar", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; - test_map_scalar_multiplications(1 , 1, init_a, T{ 3.5}); - test_map_scalar_multiplications(3 , 5, init_a, T{-2.5}); - test_map_scalar_multiplications(5 , 3, init_a, T{ 4. }); - test_map_scalar_multiplications(5 , 5, init_a, T{-5. }); - test_map_scalar_multiplications(5 , 5, init_a, T{ 1. }); - test_map_scalar_multiplications(5 , 5, init_a, T{ 6. }); - test_map_scalar_multiplications(10, 1, init_a, T{ 10.}); - test_map_scalar_multiplications(1 ,10, init_a, T{-0.5}); + test_map_scalar_multiplications(1, 1, init_a, T{3.5}); + test_map_scalar_multiplications(3, 5, init_a, T{-2.5}); + test_map_scalar_multiplications(5, 3, init_a, T{4.}); + test_map_scalar_multiplications(5, 5, init_a, T{-5.}); + test_map_scalar_multiplications(5, 5, init_a, T{1.}); + test_map_scalar_multiplications(5, 5, init_a, T{6.}); + test_map_scalar_multiplications(10, 1, init_a, T{10.}); + test_map_scalar_multiplications(1, 10, init_a, T{-0.5}); }; -TTS_CASE_TPL("Check map division with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check map division with scalar", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; - auto op = [](auto a, auto b) { return a / b; }; - auto s_op = [](auto& a, auto b) { return a /= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a / b; }; + auto s_op = [](auto& a, auto b) { return a /= b; }; - test_map_scalar_operations(1 , 1, init_a, T{ 3.5}, op, s_op); - test_map_scalar_operations(3 , 5, init_a, T{-2.5}, op, s_op); - test_map_scalar_operations(5 , 3, init_a, T{ 4. }, op, s_op); - test_map_scalar_operations(5 , 5, init_a, T{-5. }, op, s_op); - test_map_scalar_operations(5 , 5, init_a, T{ 1. }, op, s_op); - test_map_scalar_operations(5 , 5, init_a, T{ 6. }, op, s_op); - test_map_scalar_operations(10, 1, init_a, T{ 10.}, op, s_op); - test_map_scalar_operations(1 ,10, init_a, T{-0.5}, op, s_op); + test_map_scalar_operations(1, 1, init_a, T{3.5}, op, s_op); + test_map_scalar_operations(3, 5, init_a, T{-2.5}, op, s_op); + test_map_scalar_operations(5, 3, init_a, T{4.}, op, s_op); + test_map_scalar_operations(5, 5, init_a, T{-5.}, op, s_op); + test_map_scalar_operations(5, 5, init_a, T{1.}, op, s_op); + test_map_scalar_operations(5, 5, init_a, T{6.}, op, s_op); + test_map_scalar_operations(10, 1, init_a, T{10.}, op, s_op); + test_map_scalar_operations(1, 10, init_a, T{-0.5}, op, s_op); }; diff --git a/test/unit/map/strides.cpp b/test/unit/map/strides.cpp index c6900c5..01259b7 100644 --- a/test/unit/map/strides.cpp +++ b/test/unit/map/strides.cpp @@ -15,132 +15,138 @@ auto generate_data(int rows, int cols) std::vector buffer(rows * cols * 3); for (size_t i = 0; i < buffer.size(); ++i) - buffer[i] = static_cast(1+i); + buffer[i] = static_cast(1 + i); return buffer; } template -using r_mat_t = rotgen::matrix; +using r_mat_t = rotgen::matrix; template -using e_mat_t = Eigen::Matrix; +using e_mat_t = Eigen::Matrix; -template using r_map_t = rotgen::map; -template> using e_map_t = Eigen::Map; +template +using r_map_t = rotgen::map; +template> +using e_map_t = Eigen::Map; TTS_CASE("Validate Column Major Map with regular stride behavior") { - auto rows = 3; - auto cols = 4; - auto buffer = generate_data(rows,cols); + auto rows = 3; + auto cols = 4; + auto buffer = generate_data(rows, cols); r_map_t> r_map(buffer.data(), rows, cols); TTS_EQUAL(r_map.innerStride(), 1); TTS_EQUAL(r_map.outerStride(), 3); - e_map_t> e_map(buffer.data(), rows, cols); + e_map_t> e_map(buffer.data(), rows, cols); - for(std::ptrdiff_t r=0;r, rotgen::outer_stride<>> - r_map(buffer.data(), rows, cols, rotgen::outer_stride(rows + 1)); + r_map_t, rotgen::outer_stride<>> r_map( + buffer.data(), rows, cols, rotgen::outer_stride(rows + 1)); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride() , 4); + TTS_EQUAL(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)); + e_map_t, Eigen::OuterStride<>> e_map( + buffer.data(), rows, cols, Eigen::OuterStride<>(rows + 1)); - for(std::ptrdiff_t r=0;r> - r_map(buffer.data(), rows, cols, rotgen::stride(rows, 2)); + r_map_t> r_map(buffer.data(), rows, cols, + rotgen::stride(rows, 2)); - TTS_EQUAL(r_map.innerStride(), 2); - TTS_EQUAL(r_map.outerStride() , 3); + TTS_EQUAL(r_map.innerStride(), 2); + TTS_EQUAL(r_map.outerStride(), 3); - e_map_t,Eigen::Stride> - e_map(buffer.data(), rows, cols, Eigen::Stride(rows,2)); + e_map_t, + Eigen::Stride> + e_map(buffer.data(), rows, cols, + Eigen::Stride(rows, 2)); - for(std::ptrdiff_t r=0;r> r_map(buffer.data(), rows, cols); TTS_EQUAL(r_map.innerStride(), 1); TTS_EQUAL(r_map.outerStride(), 4); - e_map_t> e_map(buffer.data(), rows, cols); + e_map_t> e_map(buffer.data(), rows, cols); - for(std::ptrdiff_t r=0;r, rotgen::outer_stride<>> - r_map(buffer.data(), rows, cols, rotgen::outer_stride(cols + 1)); + r_map_t, rotgen::outer_stride<>> r_map( + buffer.data(), rows, cols, rotgen::outer_stride(cols + 1)); - TTS_EQUAL(r_map.innerStride(), 1); - TTS_EQUAL(r_map.outerStride() , 5); + TTS_EQUAL(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)); + e_map_t, Eigen::OuterStride<>> e_map( + buffer.data(), rows, cols, Eigen::OuterStride<>(cols + 1)); - for(std::ptrdiff_t r=0;r,rotgen::stride> - r_map(buffer.data(), rows, cols, rotgen::stride(2, cols)); + r_map_t, rotgen::stride> r_map( + buffer.data(), rows, cols, rotgen::stride(2, cols)); - TTS_EQUAL(r_map.innerStride(), 4); - TTS_EQUAL(r_map.outerStride() , 2); + TTS_EQUAL(r_map.innerStride(), 4); + TTS_EQUAL(r_map.outerStride(), 2); - e_map_t,Eigen::Stride> - e_map(buffer.data(), rows, cols, Eigen::Stride(2,cols)); + e_map_t, + Eigen::Stride> + e_map(buffer.data(), rows, cols, + Eigen::Stride(2, cols)); - for(std::ptrdiff_t r=0;r -TTS_CASE_TPL("Test dynamic matrix transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic matrix transposition-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix input(rows, cols); - rotgen::tests::prepare(rows,cols,fn,input); + rotgen::matrix input(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, input); rotgen::tests::check_shape_functions(input); } }; -TTS_CASE_TPL("Test static matrix transposition-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static matrix transposition-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix input; - rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input); + auto process = [](D const& desc) { + rotgen::matrix input; + rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); rotgen::tests::check_shape_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; -TTS_CASE_TPL("Test dynamic matrix reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic matrix reduction-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix input(rows, cols); - rotgen::tests::prepare(rows,cols,fn,input); + rotgen::matrix input(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, input); rotgen::tests::check_reduction_functions(input); } }; -TTS_CASE_TPL("Test static matrix reduction-like operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static matrix reduction-like operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix input; - rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input); + auto process = [](D const& desc) { + rotgen::matrix 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); + 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); + +TTS_EQUAL(rotgen::dot(a, b), 32); +} + { - { - auto a = rotgen::setConstant>(1,8,2); - auto b = rotgen::setConstant>(1,8,2); + auto a = rotgen::setConstant>(8, 1, 2); + auto b = rotgen::setConstant>(8, 1, 2); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto a = rotgen::setConstant>(8,1,2); - auto b = rotgen::setConstant>(8,1,2); +{ + auto a = rotgen::setConstant>(2); + auto b = rotgen::setConstant>(2); - TTS_EQUAL(rotgen::dot(a,b), 32); - } + TTS_EQUAL(rotgen::dot(a, b), 32); +} - { - auto a = rotgen::setConstant>(2); - auto b = rotgen::setConstant>(2); +{ + auto a = rotgen::setConstant>(2); + auto b = rotgen::setConstant>(2); - TTS_EQUAL(rotgen::dot(a,b), 32); - } - - { - auto a = rotgen::setConstant>(2); - auto b = rotgen::setConstant>(2); - - TTS_EQUAL(rotgen::dot(a,b), 32); - } -}; + TTS_EQUAL(rotgen::dot(a, b), 32); +} +} +; diff --git a/test/unit/matrix/basic_api.cpp b/test/unit/matrix/basic_api.cpp index 0312c99..72f5810 100644 --- a/test/unit/matrix/basic_api.cpp +++ b/test/unit/matrix/basic_api.cpp @@ -8,13 +8,15 @@ #include "unit/tests.hpp" #include -TTS_CASE_TPL("Function size", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Function size", rotgen::tests::types)( + tts::type>) { - rotgen::matrix empty_matrix; - rotgen::matrix matrix(3,4); - rotgen::matrix row_vector(9,1); - rotgen::matrix column_vector(1,5); + rotgen::matrix empty_matrix; + rotgen::matrix matrix(3, 4); + rotgen::matrix row_vector(9, + 1); + rotgen::matrix column_vector( + 1, 5); TTS_EQUAL(empty_matrix.size(), rotgen::Index{0}); TTS_EQUAL(matrix.size(), rotgen::Index{12}); @@ -22,72 +24,69 @@ 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::types> ) +TTS_CASE_TPL("Resizing dynamic matrix", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(2, 3); + rotgen::matrix a(2, 3); - for(rotgen::Index r=0;r( tts::type< tts::types> ) +TTS_CASE_TPL("Dynamix matrix conservative resizing", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(2, 3); + rotgen::matrix a(2, 3); int i = 1; - for(rotgen::Index r=0;r( tts::type< tts::types> ) +TTS_CASE_TPL("Test coefficient accessors", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(3, 5); + rotgen::matrix a(3, 5); - for(rotgen::Index r=0;r( tts::type< tts::types> ) +TTS_CASE_TPL("Test one index coefficient accessors", + rotgen::tests::types)( + tts::type>) { - auto a = [&]() - { - if constexpr(O::value == rotgen::ColMajor) return rotgen::matrix(1,8); - else return rotgen::matrix(8,1); + auto a = [&]() { + if constexpr (O::value == rotgen::ColMajor) + return rotgen::matrix(1, 8); + else return rotgen::matrix(8, 1); }(); TTS_EXPECT(a.IsVectorAtCompileTime); - for(rotgen::Index s=0;s -TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Default matrix dynamic constructor", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix matrix; + rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), rotgen::Index{0}); TTS_EQUAL(matrix.cols(), rotgen::Index{0}); }; -TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Default matrix static constructor", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix matrix; + rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), rotgen::Index{4}); TTS_EQUAL(matrix.cols(), rotgen::Index{9}); }; -TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Dynamic matrix constructor with row and columns", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix matrix(10, 5); + rotgen::matrix matrix(10, 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) -( tts::type ) +TTS_CASE_TPL("Static matrix constructor with row and columns", + float, + double)(tts::type) { - rotgen::matrix v2(6, 11); - rotgen::matrix w2(6, 11); + rotgen::matrix v2(6, 11); + rotgen::matrix w2(6, 11); TTS_EQUAL(v2(0), T{6}); TTS_EQUAL(v2(1), T{11}); @@ -47,8 +51,8 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double) TTS_EQUAL(w2(0), T{6}); TTS_EQUAL(w2(1), T{11}); - rotgen::matrix v3(6, 11, 125); - rotgen::matrix w3(6, 11, 125); + rotgen::matrix v3(6, 11, 125); + rotgen::matrix w3(6, 11, 125); TTS_EQUAL(v3(0), T{6}); TTS_EQUAL(v3(1), T{11}); @@ -59,52 +63,54 @@ TTS_CASE_TPL("Static matrix constructor with row and columns", float, double) TTS_EQUAL(w3(2), T{125}); }; -TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor produces identical but independent matrix", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(3, 3); + rotgen::matrix a(3, 3); - for(rotgen::Index r=0;r b = a; + rotgen::matrix b = a; TTS_EQUAL(b.rows(), a.rows()); TTS_EQUAL(b.cols(), a.cols()); - for(rotgen::Index r=0;r( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor on default matrix", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a; - rotgen::matrix b = a; + rotgen::matrix a; + rotgen::matrix b = a; 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) -( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor from const matrix", + rotgen::tests::types)( + tts::type>) { - const rotgen::matrix a(2, 2); + rotgen::matrix const a(2, 2); auto b = a; 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) -( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor on static matrix", + rotgen::tests::types)( + tts::type>) { rotgen::matrix a; rotgen::matrix b = a; @@ -112,93 +118,100 @@ TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types) TTS_EQUAL(b.cols(), rotgen::Index{5}); }; -TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor on static/dynamic matrix", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a; - rotgen::matrix b = a; + rotgen::matrix a; + rotgen::matrix b = a; TTS_EQUAL(b.rows(), 11); TTS_EQUAL(b.cols(), 4); }; -TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Copy constructor on dynamic/static matrix", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(5, 7); - rotgen::matrix b = a; + rotgen::matrix a(5, 7); + rotgen::matrix b = a; TTS_EQUAL(b.rows(), 5); TTS_EQUAL(b.cols(), 7); }; -TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Move constructor transfers contents", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix a(3, 3); - a(1,1) = 7; + rotgen::matrix a(3, 3); + a(1, 1) = 7; auto ptr = a.data(); - rotgen::matrix b = std::move(a); + rotgen::matrix b = + std::move(a); - TTS_EQUAL(b(1,1), 7); + TTS_EQUAL(b(1, 1), 7); TTS_EQUAL(b.rows(), rotgen::Index{3}); TTS_EQUAL(b.cols(), rotgen::Index{3}); TTS_EXPECT(b.data() == ptr); }; -TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Move constructor from Rvalue", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix b = rotgen::matrix(2, 2); + rotgen::matrix b = + rotgen::matrix(2, 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) -( tts::type< tts::types> ) +TTS_CASE_TPL("Constructor from Initializer list", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix b1{3.5}; + rotgen::matrix b1{3.5}; TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1}); - TTS_EQUAL(b1(0) , 3.5); + TTS_EQUAL(b1(0), 3.5); - rotgen::matrix b9{0.25, 0.5, 1, 2, 4}; + rotgen::matrix b9{0.25, 0.5, 1, 2, 4}; TTS_EQUAL(b9.rows(), rotgen::Index{5}); TTS_EQUAL(b9.cols(), rotgen::Index{1}); T i = 0.25; - for(rotgen::Index r=0;r b13{1.2,2.3,3.4}; + rotgen::matrix b13{1.2, 2.3, 3.4}; TTS_EQUAL(b13.rows(), rotgen::Index{1}); TTS_EQUAL(b13.cols(), rotgen::Index{3}); - TTS_EQUAL(b13(0) , T(1.2)); - TTS_EQUAL(b13(1) , T(2.3)); - TTS_EQUAL(b13(2) , T(3.4)); + TTS_EQUAL(b13(0), T(1.2)); + TTS_EQUAL(b13(1), T(2.3)); + TTS_EQUAL(b13(2), T(3.4)); }; -TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Constructor from Initializer list of rows", + rotgen::tests::types)( + tts::type>) { - rotgen::matrix b1{{3.5}}; + rotgen::matrix b1{{3.5}}; TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1}); - TTS_EQUAL(b1(0,0) , T(3.5)); + TTS_EQUAL(b1(0, 0), T(3.5)); - rotgen::matrix - b23 { {1.2,2.3,3.4} - , {10,200,3000} - }; + rotgen::matrix b23{ + {1.2, 2.3, 3.4}, + {10, 200, 3000}}; TTS_EQUAL(b23.rows(), rotgen::Index{2}); TTS_EQUAL(b23.cols(), rotgen::Index{3}); - TTS_EQUAL(b23(0,0) , T(1.2)); - TTS_EQUAL(b23(0,1) , T(2.3)); - TTS_EQUAL(b23(0,2) , T(3.4)); - TTS_EQUAL(b23(1,0) , T(10)); - TTS_EQUAL(b23(1,1) , T(200)); - TTS_EQUAL(b23(1,2) , T(3000)); -}; \ No newline at end of file + TTS_EQUAL(b23(0, 0), T(1.2)); + TTS_EQUAL(b23(0, 1), T(2.3)); + TTS_EQUAL(b23(0, 2), T(3.4)); + TTS_EQUAL(b23(1, 0), T(10)); + TTS_EQUAL(b23(1, 1), T(200)); + TTS_EQUAL(b23(1, 2), T(3000)); +}; diff --git a/test/unit/matrix/cwise.cpp b/test/unit/matrix/cwise.cpp index 680a3d1..dba7dde 100644 --- a/test/unit/matrix/cwise.cpp +++ b/test/unit/matrix/cwise.cpp @@ -9,29 +9,31 @@ #include "unit/common/cwise.hpp" #include -TTS_CASE_TPL("Test dynamic matrix cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic matrix cwise operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix input(rows, cols); - rotgen::tests::prepare(rows,cols,fn,input); + rotgen::matrix input(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, input); rotgen::tests::check_cwise_functions(input); } }; -TTS_CASE_TPL("Test static matrix cwise operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static matrix cwise operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix input; - rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input); + auto process = [](D const& desc) { + rotgen::matrix input; + rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); rotgen::tests::check_cwise_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); -}; \ No newline at end of file + std::apply([&](auto const&... d) { (process(d), ...); }, cases); +}; diff --git a/test/unit/matrix/generators.cpp b/test/unit/matrix/generators.cpp index 410b92d..e03744f 100644 --- a/test/unit/matrix/generators.cpp +++ b/test/unit/matrix/generators.cpp @@ -8,134 +8,141 @@ #include "unit/tests.hpp" #include -void test_value(const auto& matrix, std::size_t rows, std::size_t cols, auto constant) +void test_value(auto const& matrix, + std::size_t rows, + std::size_t cols, + auto constant) { TTS_EXPECT(verify_rotgen_reentrance(matrix)); - for(std::size_t r=0;r( tts::type< tts::types> ) +TTS_CASE_TPL("Test zero", rotgen::tests::types)( + tts::type>) { using namespace rotgen; - test_value(setZero >(), 3, 4, 0); - test_value(setZero >(), 1, 1, 0); - test_value(setZero >(), 10, 10, 0); - test_value(setZero>(3, 4), 3, 4, 0); - test_value(setZero >(7, 5), 7, 5, 0); - test_value(setZero >(9, 3), 9, 3, 0); - test_value(setZero >(2, 3), 2, 3, 0); + test_value(setZero>(), 3, 4, 0); + test_value(setZero>(), 1, 1, 0); + test_value(setZero>(), 10, 10, 0); + test_value(setZero>(3, 4), 3, 4, 0); + test_value(setZero>(7, 5), 7, 5, 0); + test_value(setZero>(9, 3), 9, 3, 0); + test_value(setZero>(2, 3), 2, 3, 0); - test_value(setZero(matrix{} ), 3, 4, 0); - test_value(setZero(matrix{} ), 1, 1, 0); - test_value(setZero(matrix{} ), 10, 10, 0); - test_value(setZero(matrix{3, 4}), 3, 4, 0); - test_value(setZero(matrix{} ), 7, 5, 0); - test_value(setZero(matrix{9, 3} ), 9, 3, 0); - test_value(setZero(matrix{2, 3} ), 2, 3, 0); + test_value(setZero(matrix{}), 3, 4, 0); + test_value(setZero(matrix{}), 1, 1, 0); + test_value(setZero(matrix{}), 10, 10, 0); + test_value(setZero(matrix{3, 4}), 3, 4, 0); + test_value(setZero(matrix{}), 7, 5, 0); + test_value(setZero(matrix{9, 3}), 9, 3, 0); + test_value(setZero(matrix{2, 3}), 2, 3, 0); }; -TTS_CASE_TPL("Test ones", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test ones", rotgen::tests::types)( + tts::type>) { using namespace rotgen; - test_value(setOnes >(), 3, 4, 1); - test_value(setOnes >(), 1, 1, 1); - test_value(setOnes >(), 10, 10, 1); - test_value(setOnes>(3, 4), 3, 4, 1); - test_value(setOnes >(7, 5), 7, 5, 1); - test_value(setOnes >(9, 3), 9, 3, 1); - test_value(setOnes >(2, 3), 2, 3, 1); + test_value(setOnes>(), 3, 4, 1); + test_value(setOnes>(), 1, 1, 1); + test_value(setOnes>(), 10, 10, 1); + test_value(setOnes>(3, 4), 3, 4, 1); + test_value(setOnes>(7, 5), 7, 5, 1); + test_value(setOnes>(9, 3), 9, 3, 1); + test_value(setOnes>(2, 3), 2, 3, 1); - test_value(setOnes(matrix{} ), 3, 4, 1); - test_value(setOnes(matrix{} ), 1, 1, 1); - test_value(setOnes(matrix{} ), 10, 10, 1); - test_value(setOnes(matrix{3, 4}), 3, 4, 1); - test_value(setOnes(matrix{} ), 7, 5, 1); - test_value(setOnes(matrix{9, 3} ), 9, 3, 1); - test_value(setOnes(matrix{2, 3} ), 2, 3, 1); + test_value(setOnes(matrix{}), 3, 4, 1); + test_value(setOnes(matrix{}), 1, 1, 1); + test_value(setOnes(matrix{}), 10, 10, 1); + test_value(setOnes(matrix{3, 4}), 3, 4, 1); + test_value(setOnes(matrix{}), 7, 5, 1); + test_value(setOnes(matrix{9, 3}), 9, 3, 1); + test_value(setOnes(matrix{2, 3}), 2, 3, 1); }; -TTS_CASE_TPL("Test constant", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test constant", rotgen::tests::types)( + tts::type>) { using namespace rotgen; - test_value(setConstant >(T(5.12)), 3, 4, T(5.12)); - test_value(setConstant >(T(5.12)), 1, 1, T(5.12)); - test_value(setConstant >(T(5.12)), 10, 10, T(5.12)); - test_value(setConstant>(3, 4, T(5.12)), 3, 4, T(5.12)); - test_value(setConstant >(7, 5, T(5.12)), 7, 5, T(5.12)); - test_value(setConstant >(9, 3, T(5.12)), 9, 3, T(5.12)); - test_value(setConstant >(2, 3, T(5.12)), 2, 3, T(5.12)); + test_value(setConstant>(T(5.12)), 3, 4, T(5.12)); + test_value(setConstant>(T(5.12)), 1, 1, T(5.12)); + test_value(setConstant>(T(5.12)), 10, 10, + T(5.12)); + test_value(setConstant>(3, 4, T(5.12)), + 3, 4, T(5.12)); + test_value(setConstant>(7, 5, T(5.12)), 7, 5, + T(5.12)); + test_value(setConstant>(9, 3, T(5.12)), 9, 3, T(5.12)); + test_value(setConstant>(2, 3, T(5.12)), 2, 3, T(5.12)); - test_value(setConstant(matrix{} , T(5.12)), 3, 4, T(5.12)); - test_value(setConstant(matrix{} , T(5.12)), 1, 1, T(5.12)); - test_value(setConstant(matrix{} , T(5.12)), 10, 10, T(5.12)); - test_value(setConstant(matrix{3, 4}, T(5.12)), 3, 4, T(5.12)); - test_value(setConstant(matrix{} , T(5.12)), 7, 5, T(5.12)); - test_value(setConstant(matrix{9, 3} , T(5.12)), 9, 3, T(5.12)); - test_value(setConstant(matrix{2, 3} , T(5.12)), 2, 3, T(5.12)); + test_value(setConstant(matrix{}, T(5.12)), 3, 4, T(5.12)); + test_value(setConstant(matrix{}, T(5.12)), 1, 1, T(5.12)); + test_value(setConstant(matrix{}, T(5.12)), 10, 10, + T(5.12)); + test_value(setConstant(matrix{3, 4}, T(5.12)), + 3, 4, T(5.12)); + test_value(setConstant(matrix{}, T(5.12)), 7, 5, T(5.12)); + test_value(setConstant(matrix{9, 3}, T(5.12)), 9, 3, T(5.12)); + test_value(setConstant(matrix{2, 3}, T(5.12)), 2, 3, T(5.12)); }; -TTS_CASE_TPL("Test random", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test random", rotgen::tests::types)( + tts::type>) { using namespace rotgen; - test_random(setRandom >(), 3, 4); - test_random(setRandom >(), 1, 1); - test_random(setRandom >(), 10, 10); - test_random(setRandom>(3, 4), 3, 4); - test_random(setRandom >(7, 5), 7, 5); - test_random(setRandom >(9, 3), 9, 3); - test_random(setRandom >(2, 3), 2, 3); + test_random(setRandom>(), 3, 4); + test_random(setRandom>(), 1, 1); + test_random(setRandom>(), 10, 10); + test_random(setRandom>(3, 4), 3, 4); + test_random(setRandom>(7, 5), 7, 5); + test_random(setRandom>(9, 3), 9, 3); + test_random(setRandom>(2, 3), 2, 3); - test_random(setRandom(matrix{} ), 3, 4); - test_random(setRandom(matrix{} ), 1, 1); - test_random(setRandom(matrix{} ), 10, 10); - test_random(setRandom(matrix{3, 4}), 3, 4); - test_random(setRandom(matrix{} ), 7, 5); - test_random(setRandom(matrix{9, 3} ), 9, 3); - test_random(setRandom(matrix{2, 3} ), 2, 3); + test_random(setRandom(matrix{}), 3, 4); + test_random(setRandom(matrix{}), 1, 1); + test_random(setRandom(matrix{}), 10, 10); + test_random(setRandom(matrix{3, 4}), 3, 4); + test_random(setRandom(matrix{}), 7, 5); + test_random(setRandom(matrix{9, 3}), 9, 3); + test_random(setRandom(matrix{2, 3}), 2, 3); }; -TTS_CASE_TPL("Test identity", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test identity", rotgen::tests::types)( + tts::type>) { using namespace rotgen; - test_identity(setIdentity >(), 3, 4); - test_identity(setIdentity >(), 1, 1); - test_identity(setIdentity >(), 10, 10); - test_identity(setIdentity>(3, 4), 3, 4); - test_identity(setIdentity >(7, 5), 7, 5); - test_identity(setIdentity >(9, 3), 9, 3); - test_identity(setIdentity >(2, 3), 2, 3); + test_identity(setIdentity>(), 3, 4); + test_identity(setIdentity>(), 1, 1); + test_identity(setIdentity>(), 10, 10); + test_identity(setIdentity>(3, 4), 3, 4); + test_identity(setIdentity>(7, 5), 7, 5); + test_identity(setIdentity>(9, 3), 9, 3); + test_identity(setIdentity>(2, 3), 2, 3); - test_identity(setIdentity(matrix{} ), 3, 4); - test_identity(setIdentity(matrix{} ), 1, 1); - test_identity(setIdentity(matrix{} ), 10, 10); - test_identity(setIdentity(matrix{3, 4}), 3, 4); - test_identity(setIdentity(matrix{} ), 7, 5); - test_identity(setIdentity(matrix{9, 3} ), 9, 3); - test_identity(setIdentity(matrix{2, 3} ), 2, 3); -}; \ No newline at end of file + test_identity(setIdentity(matrix{}), 3, 4); + test_identity(setIdentity(matrix{}), 1, 1); + test_identity(setIdentity(matrix{}), 10, 10); + test_identity(setIdentity(matrix{3, 4}), 3, 4); + test_identity(setIdentity(matrix{}), 7, 5); + test_identity(setIdentity(matrix{9, 3}), 9, 3); + test_identity(setIdentity(matrix{2, 3}), 2, 3); +}; diff --git a/test/unit/matrix/inverse.cpp b/test/unit/matrix/inverse.cpp index 3850964..78f3800 100644 --- a/test/unit/matrix/inverse.cpp +++ b/test/unit/matrix/inverse.cpp @@ -9,54 +9,59 @@ #include "unit/common/arithmetic.hpp" #include -TTS_CASE_TPL("Test dynamic matrix inverse", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic matrix inverse", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; auto eps = std::numeric_limits::epsilon(); auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [r, c, fn] : cases) + for (auto const& [r, c, fn] : cases) { - if(r == c) + if (r == c) { auto input = mat_t::Random(r, c); auto inv = rotgen::inverse(input); - auto rec = input * inv; - auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec)); - auto error = rec - id; + auto rec = input * inv; + auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec)); + auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.) - << "Result:\n" << rec << "\n" - << "Residuals:\n" << error << "\n"; + << "Result:\n" + << rec << "\n" + << "Residuals:\n" + << error << "\n"; } } }; -TTS_CASE_TPL("Test static matrix inverse", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static matrix inverse", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; auto eps = std::numeric_limits::epsilon(); auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [&](D const&) - { - if constexpr(D::rows == D::cols) + auto process = [&](D const&) { + if constexpr (D::rows == D::cols) { - auto input = rotgen::matrix::Random(); + auto input = rotgen::matrix::Random(); auto inv = rotgen::inverse(input); - auto rec = input * inv; - auto id = mat_t::Identity(rotgen::rows(rec),rotgen::cols(rec)); - auto error = rec - id; + auto rec = input * inv; + auto id = mat_t::Identity(rotgen::rows(rec), rotgen::cols(rec)); + auto error = rec - id; TTS_LESS_EQUAL(rotgen::maxCoeff(rotgen::abs(error)) / eps, 64.) - << "Result:\n" << rec << "\n" - << "Residuals:\n" << error << "\n"; + << "Result:\n" + << rec << "\n" + << "Residuals:\n" + << error << "\n"; } }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); + std::apply([&](auto const&... d) { (process(d), ...); }, cases); }; diff --git a/test/unit/matrix/norms.cpp b/test/unit/matrix/norms.cpp index 4b05866..da09570 100644 --- a/test/unit/matrix/norms.cpp +++ b/test/unit/matrix/norms.cpp @@ -9,29 +9,31 @@ #include "unit/common/norms.hpp" #include -TTS_CASE_TPL("Test dynamic matrix norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test dynamic matrix norm operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_matrix_references(); - for (const auto& [rows, cols, fn] : cases) + for (auto const& [rows, cols, fn] : cases) { - rotgen::matrix input(rows, cols); - rotgen::tests::prepare(rows,cols,fn,input); + rotgen::matrix input(rows, + cols); + rotgen::tests::prepare(rows, cols, fn, input); rotgen::tests::check_norms_functions(input); } }; -TTS_CASE_TPL("Test static matrix norm operations", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Test static matrix norm operations", + rotgen::tests::types)( + tts::type>) { auto const cases = rotgen::tests::generate_static_matrix_references(); - auto process = [](D const& desc) - { - rotgen::matrix input; - rotgen::tests::prepare(input.rows(),input.cols(),desc.init_fn,input); + auto process = [](D const& desc) { + rotgen::matrix input; + rotgen::tests::prepare(input.rows(), input.cols(), desc.init_fn, input); rotgen::tests::check_norms_functions(input); }; - std::apply([&](auto const&... d) { (process(d),...);}, cases); -}; \ No newline at end of file + std::apply([&](auto const&... d) { (process(d), ...); }, cases); +}; diff --git a/test/unit/matrix/operators.cpp b/test/unit/matrix/operators.cpp index 0f207ac..2e43eba 100644 --- a/test/unit/matrix/operators.cpp +++ b/test/unit/matrix/operators.cpp @@ -8,8 +8,13 @@ #include "unit/tests.hpp" #include -template -void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn, auto ops, auto self_ops) +template +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(rows, cols); MatrixType b(rows, cols); @@ -19,22 +24,27 @@ void test_matrix_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_ { for (rotgen::Index c = 0; c < cols; ++c) { - a(r,c) = a_init_fn(r, c); - b(r,c) = b_init_fn(r, c); - ref(r, c) = ops(a(r,c),b(r,c)); + a(r, c) = a_init_fn(r, c); + b(r, c) = b_init_fn(r, c); + ref(r, c) = ops(a(r, c), b(r, c)); } } TTS_EQUAL(ops(a, b), ref); - self_ops(a,b); + self_ops(a, b); TTS_EQUAL(a, ref); TTS_EXPECT(verify_rotgen_reentrance(ops(a, b))); TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, b))); } -template -void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto s, auto ops, auto self_ops) +template +void test_scalar_operations(rotgen::Index rows, + rotgen::Index cols, + auto a_init_fn, + auto s, + auto ops, + auto self_ops) { MatrixType a(rows, cols); MatrixType ref(rows, cols); @@ -43,21 +53,24 @@ void test_scalar_operations(rotgen::Index rows, rotgen::Index cols, auto a_init_ { for (rotgen::Index c = 0; c < cols; ++c) { - a(r,c) = a_init_fn(r, c); - ref(r, c) = ops(a(r,c),s); + a(r, c) = a_init_fn(r, c); + ref(r, c) = ops(a(r, c), s); } } TTS_EQUAL(ops(a, s), ref); - self_ops(a,s); + self_ops(a, s); TTS_EQUAL(a, ref); TTS_EXPECT(verify_rotgen_reentrance(ops(a, s))); TTS_EXPECT(verify_rotgen_reentrance(self_ops(a, s))); } -template -void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn, auto s) +template +void test_scalar_multiplications(rotgen::Index rows, + rotgen::Index cols, + auto fn, + auto s) { MatrixType a(rows, cols); MatrixType ref(rows, cols); @@ -66,8 +79,8 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn { for (rotgen::Index c = 0; c < cols; ++c) { - a(r,c) = fn(r, c); - ref(r, c) = a(r,c) * s; + a(r, c) = fn(r, c); + ref(r, c) = a(r, c) * s; } } @@ -76,25 +89,26 @@ void test_scalar_multiplications(rotgen::Index rows, rotgen::Index cols, auto fn a *= s; TTS_EQUAL(a, ref); - TTS_EXPECT(verify_rotgen_reentrance(a*s)); - TTS_EXPECT(verify_rotgen_reentrance(s*a)); - TTS_EXPECT(verify_rotgen_reentrance(a*=s)); + TTS_EXPECT(verify_rotgen_reentrance(a * s)); + TTS_EXPECT(verify_rotgen_reentrance(s * a)); + TTS_EXPECT(verify_rotgen_reentrance(a *= s)); } -template -void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_init_fn, auto b_init_fn) +template +void test_matrix_multiplication(rotgen::Index rows, + rotgen::Index cols, + auto a_init_fn, + auto b_init_fn) { MatrixType a(rows, cols); MatrixType b(cols, rows); MatrixType ref(rows, rows); 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 c = 0; c < a.cols(); ++c) a(r, c) = a_init_fn(r, c); for (rotgen::Index r = 0; r < b.rows(); ++r) - for (rotgen::Index c = 0; c < b.cols(); ++c) - b(r,c) = b_init_fn(r, c); + for (rotgen::Index c = 0; c < b.cols(); ++c) b(r, c) = b_init_fn(r, c); for (rotgen::Index i = 0; i < a.rows(); ++i) { @@ -107,98 +121,107 @@ void test_matrix_multiplication(rotgen::Index rows, rotgen::Index cols, auto a_i } TTS_EQUAL(a * b, ref); - TTS_EXPECT(verify_rotgen_reentrance(a*b)); + TTS_EXPECT(verify_rotgen_reentrance(a * b)); } // Basic initializers -inline constexpr auto init_a = [](auto r, auto c) { return 9.9*r*r*r - 6*c -12; }; -inline constexpr auto init_b = [](auto r, auto c) { return 3.1*r + 4.2*c - 12.3; }; -inline constexpr auto init_0 = [](auto , auto ) { return 0; }; +inline constexpr auto init_a = [](auto r, auto c) { + return 9.9 * r * r * r - 6 * c - 12; +}; +inline constexpr auto init_b = [](auto r, auto c) { + return 3.1 * r + 4.2 * c - 12.3; +}; +inline constexpr auto init_0 = [](auto, auto) { return 0; }; -TTS_CASE_TPL("Check matrix addition", rotgen::tests::types) -( tts::type< tts::types> ) +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; }; - auto s_op = [](auto& a, auto b) { return a += b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a + b; }; + auto s_op = [](auto& a, auto b) { return a += b; }; - test_matrix_operations(1 , 1, init_a, init_b, op, s_op); - test_matrix_operations(3 , 5, init_a, init_b, op, s_op); - test_matrix_operations(5 , 3, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_b, init_a, op, s_op); + test_matrix_operations(1, 1, init_a, init_b, op, s_op); + test_matrix_operations(3, 5, init_a, init_b, op, s_op); + test_matrix_operations(5, 3, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_b, init_a, op, s_op); test_matrix_operations(10, 1, init_a, init_b, op, s_op); - test_matrix_operations(1 ,10, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_0, init_b, op, s_op); - test_matrix_operations(5 , 5, init_a, init_0, op, s_op); + test_matrix_operations(1, 10, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_0, init_b, op, s_op); + test_matrix_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check matrix substraction", rotgen::tests::types) -( tts::type< tts::types> ) +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; }; - auto s_op = [](auto& a, auto b) { return a -= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a - b; }; + auto s_op = [](auto& a, auto b) { return a -= b; }; - test_matrix_operations(1 , 1, init_a, init_b, op, s_op); - test_matrix_operations(3 , 5, init_a, init_b, op, s_op); - test_matrix_operations(5 , 3, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_b, init_a, op, s_op); + test_matrix_operations(1, 1, init_a, init_b, op, s_op); + test_matrix_operations(3, 5, init_a, init_b, op, s_op); + test_matrix_operations(5, 3, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_b, init_a, op, s_op); test_matrix_operations(10, 1, init_a, init_b, op, s_op); - test_matrix_operations(1 ,10, init_a, init_b, op, s_op); - test_matrix_operations(5 , 5, init_0, init_b, op, s_op); - test_matrix_operations(5 , 5, init_a, init_0, op, s_op); + test_matrix_operations(1, 10, init_a, init_b, op, s_op); + test_matrix_operations(5, 5, init_0, init_b, op, s_op); + test_matrix_operations(5, 5, init_a, init_0, op, s_op); }; -TTS_CASE_TPL("Check matrix multiplications", rotgen::tests::types) -( tts::type< tts::types> ) +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; }; + using mat_t = rotgen::matrix; + auto init_id = [](auto r, auto c) { return r == c ? 1 : 0; }; - test_matrix_multiplication(1 , 1, init_a , init_b ); - test_matrix_multiplication(3 , 5, init_a , init_b ); - test_matrix_multiplication(5 , 3, init_a , init_b ); - test_matrix_multiplication(5 , 5, init_a , init_b ); - test_matrix_multiplication(5 , 5, init_b , init_a ); - test_matrix_multiplication(5 , 5, init_a , init_a ); - test_matrix_multiplication(5 , 5, init_a , init_id); - test_matrix_multiplication(5 , 5, init_id, init_a ); - test_matrix_multiplication(10, 1, init_a , init_b ); - test_matrix_multiplication(1 ,10, init_a , init_b ); - test_matrix_multiplication(5 , 5, init_0 , init_b ); - test_matrix_multiplication(5 , 5, init_a , init_0 ); + test_matrix_multiplication(1, 1, init_a, init_b); + test_matrix_multiplication(3, 5, init_a, init_b); + test_matrix_multiplication(5, 3, init_a, init_b); + test_matrix_multiplication(5, 5, init_a, init_b); + test_matrix_multiplication(5, 5, init_b, init_a); + test_matrix_multiplication(5, 5, init_a, init_a); + test_matrix_multiplication(5, 5, init_a, init_id); + test_matrix_multiplication(5, 5, init_id, init_a); + test_matrix_multiplication(10, 1, init_a, init_b); + test_matrix_multiplication(1, 10, init_a, init_b); + test_matrix_multiplication(5, 5, init_0, init_b); + test_matrix_multiplication(5, 5, init_a, init_0); }; -TTS_CASE_TPL("Check matrix multiplication with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +TTS_CASE_TPL("Check matrix multiplication with scalar", + rotgen::tests::types)( + tts::type>) { - using mat_t = rotgen::matrix; + using mat_t = rotgen::matrix; - test_scalar_multiplications(1 , 1, init_a, T{ 3.5}); - test_scalar_multiplications(3 , 5, init_a, T{-2.5}); - test_scalar_multiplications(5 , 3, init_a, T{ 4. }); - test_scalar_multiplications(5 , 5, init_a, T{-5. }); - test_scalar_multiplications(5 , 5, init_a, T{ 1. }); - test_scalar_multiplications(5 , 5, init_a, T{ 6. }); - test_scalar_multiplications(10, 1, init_a, T{ 10.}); - test_scalar_multiplications(1 ,10, init_a, T{-0.5}); + test_scalar_multiplications(1, 1, init_a, T{3.5}); + test_scalar_multiplications(3, 5, init_a, T{-2.5}); + test_scalar_multiplications(5, 3, init_a, T{4.}); + test_scalar_multiplications(5, 5, init_a, T{-5.}); + test_scalar_multiplications(5, 5, init_a, T{1.}); + test_scalar_multiplications(5, 5, init_a, T{6.}); + test_scalar_multiplications(10, 1, init_a, T{10.}); + test_scalar_multiplications(1, 10, init_a, T{-0.5}); }; -TTS_CASE_TPL("Check matrix division with scalar", rotgen::tests::types) -( tts::type< tts::types> ) +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; }; - auto s_op = [](auto& a, auto b) { return a /= b; }; + using mat_t = rotgen::matrix; + auto op = [](auto a, auto b) { return a / b; }; + auto s_op = [](auto& a, auto b) { return a /= b; }; - test_scalar_operations(1 , 1, init_a, T{ 3.5}, op, s_op); - test_scalar_operations(3 , 5, init_a, T{-2.5}, op, s_op); - test_scalar_operations(5 , 3, init_a, T{ 4. }, op, s_op); - test_scalar_operations(5 , 5, init_a, T{-5. }, op, s_op); - test_scalar_operations(5 , 5, init_a, T{ 1. }, op, s_op); - test_scalar_operations(5 , 5, init_a, T{ 6. }, op, s_op); - test_scalar_operations(10, 1, init_a, T{ 10.}, op, s_op); - test_scalar_operations(1 ,10, init_a, T{-0.5}, op, s_op); + test_scalar_operations(1, 1, init_a, T{3.5}, op, s_op); + test_scalar_operations(3, 5, init_a, T{-2.5}, op, s_op); + test_scalar_operations(5, 3, init_a, T{4.}, op, s_op); + test_scalar_operations(5, 5, init_a, T{-5.}, op, s_op); + test_scalar_operations(5, 5, init_a, T{1.}, op, s_op); + test_scalar_operations(5, 5, init_a, T{6.}, op, s_op); + test_scalar_operations(10, 1, init_a, T{10.}, op, s_op); + test_scalar_operations(1, 10, init_a, T{-0.5}, op, s_op); }; diff --git a/test/unit/tests.hpp b/test/unit/tests.hpp index 876d623..c90c01d 100644 --- a/test/unit/tests.hpp +++ b/test/unit/tests.hpp @@ -15,40 +15,41 @@ namespace rotgen::tests { - template struct constant { static constexpr auto value = N; }; + template struct constant + { + static constexpr auto value = N; + }; - using scalar = tts::types; - using order = tts::types,constant>; + using scalar = tts::types; + using order = tts::types, constant>; - using types = tts::types< tts::types> - , tts::types> - , tts::types> - , tts::types> - >; + using types = tts::types>, + tts::types>, + tts::types>, + tts::types>>; } #include -template -constexpr bool verify_rotgen_reentrance(T const&) +template constexpr bool verify_rotgen_reentrance(T const&) { - if constexpr(rotgen::use_expression_templates) return true; - else return rotgen::concepts::entity; + if constexpr (rotgen::use_expression_templates) return true; + else return rotgen::concepts::entity; } -int main(int argc, char const **argv) +int main(int argc, char const** argv) { - ::tts::initialize(argc,argv); + ::tts::initialize(argc, argv); #ifdef NDEBUG constexpr auto assert_status = "Disabled"; #else constexpr auto assert_status = "Enabled"; #endif - std::cout << "[ROTGEN] - Assertions: " << assert_status << std::endl; + std::cout << "[ROTGEN] - Assertions: " << assert_status << std::endl; rotgen::setup_summary(std::cout); rotgen_main(argc, argv); - return tts::report(0,0); -} \ No newline at end of file + return tts::report(0, 0); +}