Medial Code Documentation
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
15namespace internal {
16
21template<typename Decomposition, typename Rhs, typename Dest>
22void 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
52template<typename Derived>
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>
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
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
Pseudo expression representing a solving operation.
Definition Solve.h:63
A base class for sparse solvers.
Definition SparseSolverBase.h:54
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:74
const Solve< Derived, Rhs > solve(const SparseMatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:87
SparseSolverBase()
Default constructor.
Definition SparseSolverBase.h:58
Definition Meta.h:232
const unsigned int RowMajorBit
for a matrix, this means that the storage order is row-major.
Definition Constants.h:61