Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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 
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 
74  typedef EigenBase<Derived> Base;
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 = internal::traits<Derived>::MaxRowsAtCompileTime == 1
90  || internal::traits<Derived>::MaxColsAtCompileTime == 1,
91  NumDimensions = int(MaxSizeAtCompileTime) == 1 ? 0 : bool(IsVectorAtCompileTime) ? 1 : 2
92  };
93 
96  {}
97 
98  ~SolverBase()
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 
114  typedef Transpose<const Derived> ConstTransposeReturnType;
122  inline const ConstTransposeReturnType transpose() const
123  {
125  }
126 
128  typedef std::conditional_t<NumTraits<Scalar>::IsComplex,
129  CwiseUnaryOp<internal::scalar_conjugate_op<Scalar>, const ConstTransposeReturnType>,
130  const ConstTransposeReturnType
131  > AdjointReturnType;
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 {
150  EIGEN_ONLY_USED_FOR_DEBUG(b);
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
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:58
Derived & derived()
Definition: EigenBase.h:48
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
Derived & derived()
Definition: EigenBase.h:48
SolverBase()
Definition: SolverBase.h:95
const ConstTransposeReturnType transpose() const
Definition: SolverBase.h:122
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SolverBase.h:107
const AdjointReturnType adjoint() const
Definition: SolverBase.h:141
Expression of the transpose of a matrix.
Definition: Transpose.h:56
Namespace containing all symbols from the Eigen library.
Definition: Core:139
Definition: EigenBase.h:32
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