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 #include "./InternalHeaderCheck.h"
14 
15 namespace Eigen {
16 
17 namespace internal {
18 
19 template<typename Derived>
20 struct 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 
25 template<typename Derived>
26 struct 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<internal::remove_all_t<Derived>>::template run<true>(transpose.nestedExpression(), b);
34  }
35 };
36 
37 template<typename Scalar, typename Derived>
38 struct 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<internal::remove_all_t<Transpose<Derived> >>::template run<true>(adjoint.nestedExpression(), b);
46  }
47 };
48 } // end namespace internal
49 
69 template<typename Derived>
70 class SolverBase : public EigenBase<Derived>
71 {
72  public:
73 
75  typedef typename internal::traits<Derived>::Scalar Scalar;
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 = internal::traits<Derived>::MaxRowsAtCompileTime == 1
90  || internal::traits<Derived>::MaxColsAtCompileTime == 1,
92  };
93 
96  {}
97 
99  {}
100 
101  using Base::derived;
102 
105  template<typename Rhs>
106  inline const Solve<Derived, Rhs>
107  solve(const MatrixBase<Rhs>& b) const
108  {
109  internal::solve_assertion<internal::remove_all_t<Derived>>::template run<false>(derived(), b);
110  return Solve<Derived, Rhs>(derived(), b.derived());
111  }
112 
122  inline const ConstTransposeReturnType transpose() const
123  {
125  }
126 
128  typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
141  inline const AdjointReturnType adjoint() const
142  {
143  return AdjointReturnType(derived().transpose());
144  }
145 
146  protected:
147 
148  template<bool Transpose_, typename Rhs>
149  void _check_solve_assertion(const Rhs& b) const {
151  eigen_assert(derived().m_isInitialized && "Solver is not initialized.");
152  eigen_assert((Transpose_?derived().cols():derived().rows())==b.rows() && "SolverBase::solve(): invalid number of rows of the right hand side matrix b");
153  }
154 };
155 
156 namespace internal {
157 
158 template<typename Derived>
159 struct generic_xpr_base<Derived, MatrixXpr, SolverStorage>
160 {
161  typedef SolverBase<Derived> type;
162 
163 };
164 
165 } // end namespace internal
166 
167 } // end namespace Eigen
168 
169 #endif // EIGEN_SOLVERBASE_H
Array< int, 3, 1 > b
BiCGSTAB< SparseMatrix< double > > solver
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
Definition: Macros.h:914
#define eigen_assert(x)
Definition: Macros.h:902
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
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
internal::traits< Derived >::Scalar Scalar
Definition: SolverBase.h:75
std::conditional_t< NumTraits< Scalar >::IsComplex, CwiseUnaryOp< internal::scalar_conjugate_op< Scalar >, const ConstTransposeReturnType >, const ConstTransposeReturnType > AdjointReturnType
Definition: SolverBase.h:131
Transpose< const Derived > ConstTransposeReturnType
Definition: SolverBase.h:114
EigenBase< Derived > Base
Definition: SolverBase.h:74
Derived & derived()
Definition: EigenBase.h:48
const ConstTransposeReturnType transpose() const
Definition: SolverBase.h:122
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:107
Scalar CoeffReturnType
Definition: SolverBase.h:76
void _check_solve_assertion(const Rhs &b) const
Definition: SolverBase.h:149
const AdjointReturnType adjoint() const
Definition: SolverBase.h:141
Expression of the transpose of a matrix.
Definition: Transpose.h:56
constexpr int size_at_compile_time(int rows, int cols)
Definition: XprHelper.h:313
: InteropHeaders
Definition: Core:139
Derived & derived()
Definition: EigenBase.h:48
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: EigenBase.h:65
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: EigenBase.h:62