Eigen  3.2.93
SparseSolverBase.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 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_SPARSESOLVERBASE_H
11 #define EIGEN_SPARSESOLVERBASE_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
21 template<typename Decomposition, typename Rhs, typename Dest>
22 void solve_sparse_through_dense_panels(const Decomposition &dec, const Rhs& rhs, Dest &dest)
23 {
24  EIGEN_STATIC_ASSERT((Dest::Flags&RowMajorBit)==0,THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
25  typedef typename Dest::Scalar DestScalar;
26  // we process the sparse rhs per block of NbColsAtOnce columns temporarily stored into a dense matrix.
27  static const Index NbColsAtOnce = 4;
28  Index rhsCols = rhs.cols();
29  Index size = rhs.rows();
30  // the temporary matrices do not need more columns than NbColsAtOnce:
31  Index tmpCols = (std::min)(rhsCols, NbColsAtOnce);
34  for(Index k=0; k<rhsCols; k+=NbColsAtOnce)
35  {
36  Index actualCols = std::min<Index>(rhsCols-k, NbColsAtOnce);
37  tmp.leftCols(actualCols) = rhs.middleCols(k,actualCols);
38  tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols));
39  dest.middleCols(k,actualCols) = tmpX.leftCols(actualCols).sparseView();
40  }
41 }
42 
43 } // end namespace internal
44 
52 template<typename Derived>
53 class SparseSolverBase : internal::noncopyable
54 {
55  public:
56 
59  : m_isInitialized(false)
60  {}
61 
63  {}
64 
65  Derived& derived() { return *static_cast<Derived*>(this); }
66  const Derived& derived() const { return *static_cast<const Derived*>(this); }
67 
72  template<typename Rhs>
73  inline const Solve<Derived, Rhs>
74  solve(const MatrixBase<Rhs>& b) const
75  {
76  eigen_assert(m_isInitialized && "Solver is not initialized.");
77  eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
78  return Solve<Derived, Rhs>(derived(), b.derived());
79  }
80 
85  template<typename Rhs>
86  inline const Solve<Derived, Rhs>
87  solve(const SparseMatrixBase<Rhs>& b) const
88  {
89  eigen_assert(m_isInitialized && "Solver is not initialized.");
90  eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b");
91  return Solve<Derived, Rhs>(derived(), b.derived());
92  }
93 
94  #ifndef EIGEN_PARSED_BY_DOXYGEN
95 
96  template<typename Rhs,typename Dest>
97  void _solve_impl(const SparseMatrixBase<Rhs> &b, SparseMatrixBase<Dest> &dest) const
98  {
99  internal::solve_sparse_through_dense_panels(derived(), b.derived(), dest.derived());
100  }
101  #endif // EIGEN_PARSED_BY_DOXYGEN
102 
103  protected:
104 
105  mutable bool m_isInitialized;
106 };
107 
108 } // end namespace Eigen
109 
110 #endif // EIGEN_SPARSESOLVERBASE_H
A base class for sparse solvers.
Definition: SparseSolverBase.h:53
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition: SparseSolverBase.h:74
Namespace containing all symbols from the Eigen library.
Definition: Core:271
Derived & derived()
Definition: EigenBase.h:44
const unsigned int RowMajorBit
Definition: Constants.h:61
Index rows() const
Definition: SparseMatrixBase.h:156
Base class of any sparse matrices or sparse expressions.
Definition: ForwardDeclarations.h:281
Index rows() const
Definition: EigenBase.h:58
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: XprHelper.h:35
Definition: Eigen_Colamd.h:50
const Solve< Derived, Rhs > solve(const SparseMatrixBase< Rhs > &b) const
Definition: SparseSolverBase.h:87
SparseSolverBase()
Definition: SparseSolverBase.h:58
Pseudo expression representing a solving operation.
Definition: Solve.h:62
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:178
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:48