Eigen  3.4.90 (git rev a4098ac676528a83cfb73d4d26ce1b42ec05f47c)
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 <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
13#include "./InternalHeaderCheck.h"
14
15namespace Eigen {
16
17namespace internal {
18
19template<typename Derived>
20struct solve_assertion {
21 template<bool Transpose_, typename Rhs>
22 static void run(const Derived& solver, const Rhs& b) { solver.template _check_solve_assertion<Transpose_>(b); }
23};
24
25template<typename Derived>
26struct solve_assertion<Transpose<Derived> >
27{
28 typedef Transpose<Derived> type;
29
30 template<bool Transpose_, typename Rhs>
31 static void run(const type& transpose, const Rhs& b)
32 {
33 internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<true>(transpose.nestedExpression(), b);
34 }
35};
36
37template<typename Scalar, typename Derived>
38struct solve_assertion<CwiseUnaryOp<Eigen::internal::scalar_conjugate_op<Scalar>, const Transpose<Derived> > >
39{
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 {
45 internal::solve_assertion<typename internal::remove_all<Transpose<Derived> >::type>::template run<true>(adjoint.nestedExpression(), b);
46 }
47};
48} // end namespace internal
49
69template<typename Derived>
70class SolverBase : public EigenBase<Derived>
71{
72 public:
73
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_at_compile_time<internal::traits<Derived>::RowsAtCompileTime,
85 internal::traits<Derived>::ColsAtCompileTime>::ret),
86 MaxRowsAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime,
87 MaxColsAtCompileTime = internal::traits<Derived>::MaxColsAtCompileTime,
88 MaxSizeAtCompileTime = (internal::size_at_compile_time<internal::traits<Derived>::MaxRowsAtCompileTime,
89 internal::traits<Derived>::MaxColsAtCompileTime>::ret),
90 IsVectorAtCompileTime = internal::traits<Derived>::MaxRowsAtCompileTime == 1
91 || internal::traits<Derived>::MaxColsAtCompileTime == 1,
92 NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2
93 };
94
97 {}
98
100 {}
101
102 using Base::derived;
103
106 template<typename Rhs>
107 inline const Solve<Derived, Rhs>
108 solve(const MatrixBase<Rhs>& b) const
109 {
110 internal::solve_assertion<typename internal::remove_all<Derived>::type>::template run<false>(derived(), b);
111 return Solve<Derived, Rhs>(derived(), b.derived());
112 }
113
115 typedef typename internal::add_const<Transpose<const Derived> >::type ConstTransposeReturnType;
124 {
126 }
127
129 typedef typename internal::conditional<NumTraits<Scalar>::IsComplex,
131 ConstTransposeReturnType
132 >::type AdjointReturnType;
142 inline AdjointReturnType adjoint() const
143 {
144 return AdjointReturnType(derived().transpose());
145 }
146
147 protected:
148
149 template<bool Transpose_, typename Rhs>
150 void _check_solve_assertion(const Rhs& b) const {
151 EIGEN_ONLY_USED_FOR_DEBUG(b);
152 eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
153 eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
154 }
155};
156
157namespace internal {
158
159template<typename Derived>
160struct generic_xpr_base<Derived, MatrixXpr, SolverStorage>
161{
162 typedef SolverBase<Derived> type;
163
164};
165
166} // end namespace internal
167
168} // end namespace Eigen
169
170#endif // EIGEN_SOLVERBASE_H
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
Derived & derived()
Definition: EigenBase.h:48
Expression of a diagonal/subdiagonal/superdiagonal in a matrix.
Definition: Diagonal.h:67
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
Pseudo expression representing a solving operation.
Definition: Solve.h:65
A base class for matrix decomposition and solvers.
Definition: SolverBase.h:71
AdjointReturnType adjoint() const
Definition: SolverBase.h:142
SolverBase()
Definition: SolverBase.h:96
ConstTransposeReturnType transpose() const
Definition: SolverBase.h:123
Derived & derived()
Definition: EigenBase.h:48
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:108
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
Definition: EigenBase.h:32
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:65
Derived & derived()
Definition: EigenBase.h:48
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62