EmrysFilter 0.1.0
State estimation utilities in C++23 using Eigen
Loading...
Searching...
No Matches
Multiply.h
Go to the documentation of this file.
1#pragma once
2
10
11#include <concepts>
12
13#include <Eigen/Core>
14
15namespace Emrys::internal
16{
17
21inline constexpr int largeProductSize = EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD;
22
26[[nodiscard]] consteval bool
27isLargeFixedShape(int rows, int depth, int cols)
28{
29 if (rows == Eigen::Dynamic || depth == Eigen::Dynamic || cols == Eigen::Dynamic)
30 {
31 return false;
32 }
33 return depth > 1 && !(rows == 1 && cols == 1)
34 && (depth >= largeProductSize || (rows >= largeProductSize && cols >= largeProductSize));
35}
36
43template <typename Lhs, typename Rhs>
44inline constexpr bool isLargeFixedProduct =
45 isLargeFixedShape(Lhs::RowsAtCompileTime, Lhs::ColsAtCompileTime, Rhs::ColsAtCompileTime);
46
60template <typename Lhs, typename Rhs>
61[[nodiscard]] auto
62multiply(Eigen::EigenBase<Lhs> const & lhs, Eigen::EigenBase<Rhs> const & rhs)
63{
64 if constexpr (std::derived_from<Lhs, Eigen::MatrixBase<Lhs>> && std::derived_from<Rhs, Eigen::MatrixBase<Rhs>>
65 && isLargeFixedProduct<Lhs, Rhs>)
66 {
67 return lhs.derived().lazyProduct(rhs.derived());
68 }
69 else
70 {
71 return lhs.derived() * rhs.derived();
72 }
73}
74
84template <int Mode, typename Derived>
85[[nodiscard]] auto
86asTriangular(Eigen::MatrixBase<Derived> const & matrix)
87{
88 if constexpr (Derived::RowsAtCompileTime != Eigen::Dynamic && Derived::ColsAtCompileTime != Eigen::Dynamic)
89 {
90 typename Derived::PlainObject result = matrix.template triangularView<Mode>();
91 return result;
92 }
93 else
94 {
95 return matrix.template triangularView<Mode>();
96 }
97}
98
99} // namespace Emrys::internal