使用迭代方法求解线性系统,使用solveWithGuess和Eigen中的稀疏b向量



我目前正在使用特征3.4.0来求解方程组Ax=b的线性系统,其中Ab都是稀疏的。我使用的是BiCGSTAB方法,它是迭代的,就像这样:

Eigen::SparseMatrix<double> A;
Eigen::SparseVector<double> b;
Eigen::BiCGSTAB<SparseMat, Eigen::IncompleteLUT<double>> solver;
solver.compute(A);
Eigen::SparseVector<double> x = solver.solve(b).eval();

事实证明,在某些情况下,我可能会对解算器有一个初步的猜测(也是一个稀疏向量(。所以我的第一直觉是这样做:

Eigen::SparseVector<double> x0;
Eigen::BiCGSTAB<SparseMat, Eigen::IncompleteLUT<double>> solver;
solver.compute(A);
Eigen::SparseVector<double> x = solver.solveWithGuess(b, x0).eval();

但是我得到了错误No matching member function for call to 'solveWithGuess'。好吧,为什么?所以我尝试了这个代码:

Eigen::SparseVector<double> sv;
VectorXd dv;
solver.solveWithGuess(sv, dv); // ERROR
solver.solveWithGuess(dv, sv); // OK
solver.solveWithGuess(sv, sv); // ERROR
solver.solveWithGuess(dv, dv); // OK

显然,即使我可以用稀疏的b向量调用solve,我也必须用稠密的b向量调用solveWithGuess。为什么?在调用solveWithGuess之前,我唯一的选择真的是将b转换为密集向量吗?这是非常低效的。

Eigen文档中Eigen::BiCGSTAB:的公共函数列表

Inherited from Eigen::IterativeSolverBase<BiCGSTAB<_MatrixType, _Preconditioner>>
const SolveWithGuess<BiCGSTAB<_MatrixType, _Preconditioner>, Rhs, Guess> solveWithGuess(const MatrixBase<Rhs> &b, const Guess &x0) const
Inherited from Eigen::SparseSolverBase<Derived>
template<typename Rhs>
const Solve<Derived, Rhs> solve(const MatrixBase<Rhs> &b) const

template<typename Rhs>
const Solve<Derived, Rhs> solve(const SparseMatrixBase<Rhs> &b) const

正如您所看到的,solve有两种实现——一种采用稀疏参数,另一种采用密集参数。

至于solveWithGuess,只有一种实现需要密集的参数。

这是因为solve来自顶级、最普通的类SparseSolverBasesolveWithGuess来自于从SparseSolverBase派生的IterativeSolverBase,而IterativeSolverBase不适用于稀疏参数。

所以这个函数不在库中,但我不知道它不存在的原因。

最新更新