10#ifndef EIGEN_SPARSESOLVERBASE_H
11#define EIGEN_SPARSESOLVERBASE_H
14#include "./InternalHeaderCheck.h"
24template <
typename Decomposition,
typename Rhs,
typename Dest>
25std::enable_if_t<Rhs::ColsAtCompileTime != 1 && Dest::ColsAtCompileTime != 1> solve_sparse_through_dense_panels(
26 const Decomposition& dec,
const Rhs& rhs, Dest& dest) {
27 EIGEN_STATIC_ASSERT((Dest::Flags &
RowMajorBit) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
28 typedef typename Dest::Scalar DestScalar;
30 static const Index NbColsAtOnce = 4;
31 Index rhsCols = rhs.cols();
32 Index size = rhs.rows();
34 Index tmpCols = (std::min)(rhsCols, NbColsAtOnce);
35 Eigen::Matrix<DestScalar, Dynamic, Dynamic> tmp(size, tmpCols);
36 Eigen::Matrix<DestScalar, Dynamic, Dynamic> tmpX(size, tmpCols);
37 for (
Index k = 0; k < rhsCols; k += NbColsAtOnce) {
38 Index actualCols = std::min<Index>(rhsCols - k, NbColsAtOnce);
39 tmp.leftCols(actualCols) = rhs.middleCols(k, actualCols);
40 tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols));
41 dest.middleCols(k, actualCols) = tmpX.leftCols(actualCols).sparseView();
46template <
typename Decomposition,
typename Rhs,
typename Dest>
47std::enable_if_t<Rhs::ColsAtCompileTime == 1 || Dest::ColsAtCompileTime == 1> solve_sparse_through_dense_panels(
48 const Decomposition& dec,
const Rhs& rhs, Dest& dest) {
49 typedef typename Dest::Scalar DestScalar;
50 Index size = rhs.rows();
51 Eigen::Matrix<DestScalar, Dynamic, 1> rhs_dense(rhs);
52 Eigen::Matrix<DestScalar, Dynamic, 1> dest_dense(size);
53 dest_dense = dec.solve(rhs_dense);
54 dest = dest_dense.sparseView();
66template <
typename Derived>
74 ~SparseSolverBase() {}
76 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
77 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
83 template <
typename Rhs>
85 eigen_assert(m_isInitialized &&
"Solver is not initialized.");
86 eigen_assert(derived().rows() == b.rows() &&
"solve(): invalid number of rows of the right hand side matrix b");
94 template <
typename Rhs>
96 eigen_assert(m_isInitialized &&
"Solver is not initialized.");
97 eigen_assert(derived().rows() == b.
rows() &&
"solve(): invalid number of rows of the right hand side matrix b");
101#ifndef EIGEN_PARSED_BY_DOXYGEN
103 template <
typename Rhs,
typename Dest>
105 internal::solve_sparse_through_dense_panels(derived(), b.
derived(), dest.
derived());
110 mutable bool m_isInitialized;
Base class for all dense matrices, vectors, and expressions.
Definition ForwardDeclarations.h:73
Pseudo expression representing a solving operation.
Definition ForwardDeclarations.h:112
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:30
Index rows() const
Definition SparseMatrixBase.h:182
A base class for sparse solvers.
Definition SparseSolverBase.h:67
const Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:84
const Solve< Derived, Rhs > solve(const SparseMatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:95
SparseSolverBase()
Definition SparseSolverBase.h:70
const unsigned int RowMajorBit
Definition Constants.h:70
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82
constexpr Derived & derived()
Definition EigenBase.h:49