WPILibC++ 2023.4.3-108-ge5452e3
SolverBase.h
Go to the documentation of this file.
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_SOLVERBASE_H
11#define EIGEN_SOLVERBASE_H
12
13namespace Eigen {
14
15namespace internal {
16
17template<typename Derived>
19 template<bool Transpose_, typename Rhs>
20 static void run(const Derived& solver, const Rhs& b) { solver.template _check_solve_assertion<Transpose_>(b); }
21};
22
23template<typename Derived>
24struct solve_assertion<Transpose<Derived> >
25{
27
28 template<bool Transpose_, typename Rhs>
29 static void run(const type& transpose, const Rhs& b)
30 {
32 }
33};
34
35template<typename Scalar, typename Derived>
37{
39
40 template<bool Transpose_, typename Rhs>
41 static void run(const type& adjoint, const Rhs& b)
42 {
44 }
45};
46} // end namespace internal
47
48/** \class SolverBase
49 * \brief A base class for matrix decomposition and solvers
50 *
51 * \tparam Derived the actual type of the decomposition/solver.
52 *
53 * Any matrix decomposition inheriting this base class provide the following API:
54 *
55 * \code
56 * MatrixType A, b, x;
57 * DecompositionType dec(A);
58 * x = dec.solve(b); // solve A * x = b
59 * x = dec.transpose().solve(b); // solve A^T * x = b
60 * x = dec.adjoint().solve(b); // solve A' * x = b
61 * \endcode
62 *
63 * \warning Currently, any other usage of transpose() and adjoint() are not supported and will produce compilation errors.
64 *
65 * \sa class PartialPivLU, class FullPivLU, class HouseholderQR, class ColPivHouseholderQR, class FullPivHouseholderQR, class CompleteOrthogonalDecomposition, class LLT, class LDLT, class SVDBase
66 */
67template<typename Derived>
68class SolverBase : public EigenBase<Derived>
69{
70 public:
71
75
76 template<typename Derived_>
78
79 enum {
90 NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2
91 };
92
93 /** Default constructor */
95 {}
96
98 {}
99
100 using Base::derived;
101
102 /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A.
103 */
104 template<typename Rhs>
105 inline const Solve<Derived, Rhs>
106 solve(const MatrixBase<Rhs>& b) const
107 {
109 return Solve<Derived, Rhs>(derived(), b.derived());
110 }
111
112 /** \internal the return type of transpose() */
114 /** \returns an expression of the transposed of the factored matrix.
115 *
116 * A typical usage is to solve for the transposed problem A^T x = b:
117 * \code x = dec.transpose().solve(b); \endcode
118 *
119 * \sa adjoint(), solve()
120 */
122 {
124 }
125
126 /** \internal the return type of adjoint() */
131 /** \returns an expression of the adjoint of the factored matrix
132 *
133 * A typical usage is to solve for the adjoint problem A' x = b:
134 * \code x = dec.adjoint().solve(b); \endcode
135 *
136 * For real scalar types, this function is equivalent to transpose().
137 *
138 * \sa transpose(), solve()
139 */
141 {
143 }
144
145 protected:
146
147 template<bool Transpose_, typename Rhs>
148 void _check_solve_assertion(const Rhs& b) const {
150 eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
151 eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
152 }
153};
154
155namespace internal {
156
157template<typename Derived>
159{
161
162};
163
164} // end namespace internal
165
166} // end namespace Eigen
167
168#endif // EIGEN_SOLVERBASE_H
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:1059
#define eigen_assert(x)
Definition: Macros.h:1047
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:56
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all< XprTypeNested >::type & nestedExpression() const
Definition: CwiseUnaryOp.h:80
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:50
Pseudo expression representing a solving operation.
Definition: Solve.h:63
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:69
AdjointReturnType adjoint() const
Definition: SolverBase.h:140
internal::traits< Derived >::Scalar Scalar
Definition: SolverBase.h:73
EigenBase< Derived > Base
Definition: SolverBase.h:72
internal::add_const< Transpose< constDerived > >::type ConstTransposeReturnType
Definition: SolverBase.h:113
internal::conditional< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, ConstTransposeReturnType >, ConstTransposeReturnType >::type AdjointReturnType
Definition: SolverBase.h:130
SolverBase()
Default constructor.
Definition: SolverBase.h:94
~SolverBase()
Definition: SolverBase.h:97
ConstTransposeReturnType transpose() const
Definition: SolverBase.h:121
Scalar CoeffReturnType
Definition: SolverBase.h:74
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:106
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
void _check_solve_assertion(const Rhs &b) const
Definition: SolverBase.h:148
@ RowsAtCompileTime
Definition: SolverBase.h:80
@ NumDimensions
Definition: SolverBase.h:90
@ ColsAtCompileTime
Definition: SolverBase.h:81
@ MaxRowsAtCompileTime
Definition: SolverBase.h:84
@ IsVectorAtCompileTime
Definition: SolverBase.h:88
@ MaxSizeAtCompileTime
Definition: SolverBase.h:86
@ MaxColsAtCompileTime
Definition: SolverBase.h:85
@ SizeAtCompileTime
Definition: SolverBase.h:82
Expression of the transpose of a matrix.
Definition: Transpose.h:54
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const internal::remove_all< MatrixTypeNested >::type & nestedExpression() const
Definition: Transpose.h:76
type
Definition: core.h:575
Namespace containing all symbols from the Eigen library.
Definition: Core:141
Definition: Eigen_Colamd.h:50
b
Definition: data.h:44
Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor Matrix...
Definition: EigenBase.h:30
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:63
EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:46
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:60
The type used to identify a matrix expression.
Definition: Constants.h:522
The type used to identify a general solver (factored) storage.
Definition: Constants.h:513
Definition: Meta.h:208
Definition: Meta.h:109
SolverBase< Derived > type
Definition: SolverBase.h:160
Definition: XprHelper.h:501
Definition: UnaryFunctors.h:109
Definition: XprHelper.h:282
CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< Scalar >, const Transpose< Derived > > type
Definition: SolverBase.h:38
Transpose< Derived > type
Definition: SolverBase.h:26
static void run(const type &transpose, const Rhs &b)
Definition: SolverBase.h:29
Definition: SolverBase.h:18
static void run(const Derived &solver, const Rhs &b)
Definition: SolverBase.h:20
Definition: ForwardDeclarations.h:17
Definition: Meta.h:96