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 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template <typename Derived>
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 
28 template <typename Derived>
29 struct solve_assertion<Transpose<Derived>> {
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 
38 template <typename Scalar, typename Derived>
41 
42  template <bool Transpose_, typename Rhs>
43  static void run(const type& adjoint, const Rhs& b) {
45  adjoint.nestedExpression(), b);
46  }
47 };
48 } // end namespace internal
49 
71 template <typename Derived>
72 class SolverBase : public EigenBase<Derived> {
73  public:
77 
78  template <typename Derived_>
80 
81  enum {
93  : 2
94  };
95 
98 
100 
101  using Base::derived;
102 
105  template <typename Rhs>
106  inline const Solve<Derived, Rhs> solve(const MatrixBase<Rhs>& b) const {
108  return Solve<Derived, Rhs>(derived(), b.derived());
109  }
110 
121 
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 {
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 
148 namespace internal {
149 
150 template <typename Derived>
153 };
154 
155 } // end namespace internal
156 
157 } // end namespace Eigen
158 
159 #endif // EIGEN_SOLVERBASE_H
BiCGSTAB< SparseMatrix< double > > solver
Definition: BiCGSTAB_simple.cpp:5
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:922
#define eigen_assert(x)
Definition: Macros.h:910
void adjoint(const MatrixType &m)
Definition: adjoint.cpp:85
Scalar * b
Definition: benchVecAdd.cpp:17
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:53
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
internal::traits< Derived >::Scalar Scalar
Definition: SolverBase.h:75
Transpose< const Derived > ConstTransposeReturnType
Definition: SolverBase.h:112
EigenBase< Derived > Base
Definition: SolverBase.h:74
constexpr EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:49
SolverBase()
Definition: SolverBase.h:97
~SolverBase()
Definition: SolverBase.h:99
const ConstTransposeReturnType transpose() const
Definition: SolverBase.h:120
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:106
Scalar CoeffReturnType
Definition: SolverBase.h:76
@ RowsAtCompileTime
Definition: SolverBase.h:82
@ NumDimensions
Definition: SolverBase.h:91
@ ColsAtCompileTime
Definition: SolverBase.h:83
@ MaxRowsAtCompileTime
Definition: SolverBase.h:85
@ IsVectorAtCompileTime
Definition: SolverBase.h:89
@ MaxSizeAtCompileTime
Definition: SolverBase.h:87
@ MaxColsAtCompileTime
Definition: SolverBase.h:86
@ SizeAtCompileTime
Definition: SolverBase.h:84
void _check_solve_assertion(const Rhs &b) const
Definition: SolverBase.h:140
const AdjointReturnType adjoint() const
Definition: SolverBase.h:136
std::conditional_t< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, const ConstTransposeReturnType >, const ConstTransposeReturnType > AdjointReturnType
Definition: SolverBase.h:126
Expression of the transpose of a matrix.
Definition: Transpose.h:56
@ IsComplex
Definition: common.h:73
return int(ret)+1
@ Rhs
Definition: TensorContractionMapper.h:20
constexpr int size_at_compile_time(int rows, int cols)
Definition: XprHelper.h:373
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
void transpose()
Definition: skew_symmetric_matrix3.cpp:135
Definition: Eigen_Colamd.h:49
Definition: EigenBase.h:33
constexpr EIGEN_DEVICE_FUNC Derived & derived()
Definition: EigenBase.h:49
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:61
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:59
Definition: Constants.h:534
Definition: Constants.h:525
SolverBase< Derived > type
Definition: SolverBase.h:152
Definition: XprHelper.h:575
Template functor to compute the conjugate of a complex value.
Definition: functors/UnaryFunctors.h:132
CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< Scalar >, const Transpose< Derived > > type
Definition: SolverBase.h:40
Transpose< Derived > type
Definition: SolverBase.h:30
static void run(const type &transpose, const Rhs &b)
Definition: SolverBase.h:33
Definition: SolverBase.h:21
static void run(const Derived &solver, const Rhs &b)
Definition: SolverBase.h:23
Definition: ForwardDeclarations.h:21