Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SolverBase.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2015 Gael Guennebaud <[email protected]>
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
13// IWYU pragma: private
14#include "./InternalHeaderCheck.h"
15
16namespace Eigen {
17
18namespace internal {
19
20template <typename Derived>
21struct solve_assertion {
22 template <bool Transpose_, typename Rhs>
23 static void run(const Derived& solver, const Rhs& b) {
24 solver.template _check_solve_assertion<Transpose_>(b);
25 }
26};
27
28template <typename Derived>
29struct solve_assertion<Transpose<Derived>> {
30 typedef Transpose<Derived> type;
31
32 template <bool Transpose_, typename Rhs>
33 static void run(const type& transpose, const Rhs& b) {
34 internal::solve_assertion<internal::remove_all_t<Derived>>::template run<true>(transpose.nestedExpression(), b);
35 }
36};
37
38template <typename Scalar, typename Derived>
39struct solve_assertion<CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived>>> {
40 typedef CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived>> type;
41
42 template <bool Transpose_, typename Rhs>
43 static void run(const type& adjoint, const Rhs& b) {
44 internal::solve_assertion<internal::remove_all_t<Transpose<Derived>>>::template run<true>(
45 adjoint.nestedExpression(), b);
46 }
47};
48} // end namespace internal
49
71template <typename Derived>
72class SolverBase : public EigenBase<Derived> {
73 public:
75 typedef typename internal::traits<Derived>::Scalar Scalar;
76 typedef Scalar CoeffReturnType;
77
78 template <typename Derived_>
79 friend struct internal::solve_assertion;
80
81 enum {
82 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime,
83 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime,
84 SizeAtCompileTime = (internal::size_of_xpr_at_compile_time<Derived>::ret),
85 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
86 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
87 MaxSizeAtCompileTime = internal::size_at_compile_time(internal::traits<Derived>::MaxRowsAtCompileTime,
88 internal::traits<Derived>::MaxColsAtCompileTime),
89 IsVectorAtCompileTime =
90 internal::traits<Derived>::MaxRowsAtCompileTime == 1 || internal::traits<Derived>::MaxColsAtCompileTime == 1,
91 NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0
92 : bool(IsVectorAtCompileTime) ? 1
93 : 2
94 };
95
98
99 ~SolverBase() {}
100
101 using Base::derived;
102
105 template <typename Rhs>
106 inline const Solve<Derived, Rhs> solve(const MatrixBase<Rhs>& b) const {
107 internal::solve_assertion<internal::remove_all_t<Derived>>::template run<false>(derived(), b);
108 return Solve<Derived, Rhs>(derived(), b.derived());
109 }
110
112 typedef Transpose<const Derived> ConstTransposeReturnType;
121
123 typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
124 CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const ConstTransposeReturnType>,
125 const ConstTransposeReturnType>
126 AdjointReturnType;
136 inline const AdjointReturnType adjoint() const { return AdjointReturnType(derived().transpose()); }
137
138 protected:
139 template <bool Transpose_, typename Rhs>
140 void _check_solve_assertion(const Rhs& b) const {
141 EIGEN_ONLY_USED_FOR_DEBUG(b);
142 eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
143 eigen_assert((Transpose_ ? derived().cols() : derived().rows()) == b.rows() &&
144 "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
145 }
146};
147
148namespace internal {
149
150template <typename Derived>
151struct generic_xpr_base<Derived, MatrixXpr, SolverStorage> {
152 typedef SolverBase<Derived> type;
153};
154
155} // end namespace internal
156
157} // end namespace Eigen
158
159#endif // EIGEN_SOLVERBASE_H
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition CwiseUnaryOp.h:53
Derived & derived()
Definition EigenBase.h:49
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
Pseudo expression representing a solving operation.
Definition Solve.h:62
A base class for matrix decomposition and solvers.
Definition SolverBase.h:72
SolverBase()
Definition SolverBase.h:97
const ConstTransposeReturnType transpose() const
Definition SolverBase.h:120
Derived & derived()
Definition EigenBase.h:49
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition SolverBase.h:106
const AdjointReturnType adjoint() const
Definition SolverBase.h:136
Expression of the transpose of a matrix.
Definition Transpose.h:56
Namespace containing all symbols from the Eigen library.
Definition Core:137
Definition EigenBase.h:33
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition EigenBase.h:61
Derived & derived()
Definition EigenBase.h:49
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition EigenBase.h:59