11#ifndef EIGEN_SPARSESOLVERBASE_H
12#define EIGEN_SPARSESOLVERBASE_H
15#include "./InternalHeaderCheck.h"
25template <
typename Decomposition,
typename Rhs,
typename Dest>
26std::enable_if_t<Rhs::ColsAtCompileTime != 1 && Dest::ColsAtCompileTime != 1> solve_sparse_through_dense_panels(
27 const Decomposition& dec,
const Rhs& rhs, Dest& dest) {
28 EIGEN_STATIC_ASSERT((Dest::Flags &
RowMajorBit) == 0, THIS_METHOD_IS_ONLY_FOR_COLUMN_MAJOR_MATRICES);
29 using DestScalar =
typename Dest::Scalar;
31 static const Index NbColsAtOnce = 4;
32 Index rhsCols = rhs.cols();
33 Index size = rhs.rows();
35 Index tmpCols = (std::min)(rhsCols, NbColsAtOnce);
36 Eigen::Matrix<DestScalar, Dynamic, Dynamic> tmp(size, tmpCols);
37 Eigen::Matrix<DestScalar, Dynamic, Dynamic> tmpX(size, tmpCols);
38 for (Index k = 0; k < rhsCols; k += NbColsAtOnce) {
39 Index actualCols = std::min<Index>(rhsCols - k, NbColsAtOnce);
40 tmp.leftCols(actualCols) = rhs.middleCols(k, actualCols);
41 tmpX.leftCols(actualCols) = dec.solve(tmp.leftCols(actualCols));
42 dest.middleCols(k, actualCols) = tmpX.leftCols(actualCols).sparseView();
47template <
typename Decomposition,
typename Rhs,
typename Dest>
48std::enable_if_t<Rhs::ColsAtCompileTime == 1 || Dest::ColsAtCompileTime == 1> solve_sparse_through_dense_panels(
49 const Decomposition& dec,
const Rhs& rhs, Dest& dest) {
50 using DestScalar =
typename Dest::Scalar;
51 Index size = rhs.rows();
52 Eigen::Matrix<DestScalar, Dynamic, 1> rhs_dense(rhs);
53 Eigen::Matrix<DestScalar, Dynamic, 1> dest_dense(size);
54 dest_dense = dec.solve(rhs_dense);
55 dest = dest_dense.sparseView();
67template <
typename Derived>
80 Derived& derived() {
return *
static_cast<Derived*
>(
this); }
81 const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
87 template <
typename Rhs>
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");
98 template <
typename Rhs>
100 eigen_assert(m_isInitialized &&
"Solver is not initialized.");
101 eigen_assert(derived().rows() == b.
rows() &&
"solve(): invalid number of rows of the right hand side matrix b");
105#ifndef EIGEN_PARSED_BY_DOXYGEN
107 template <
typename Rhs,
typename Dest>
109 internal::solve_sparse_through_dense_panels(derived(), b.
derived(), dest.
derived());
114 mutable bool m_isInitialized =
false;
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Pseudo expression representing a solving operation.
Definition Solve.h:63
Base class of any sparse matrices or sparse expressions.
Definition SparseMatrixBase.h:31
Index rows() const
Definition SparseMatrixBase.h:182
A base class for sparse solvers.
Definition SparseSolverBase.h:68
SparseSolverBase()=default
Solve< Derived, Rhs > solve(const SparseMatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:99
Solve< Derived, Rhs > solve(const MatrixBase< Rhs > &b) const
Definition SparseSolverBase.h:88
constexpr unsigned int RowMajorBit
Definition Constants.h:71
constexpr Derived & derived()
Definition EigenBase.h:50