如何在 Eigen 3.3.4 中在稀疏块上实例化内部迭代器?



我有一段代码在 Eigen 3.2 中运行良好,但在 Eigen 3.3.4 中不再有效。这是代码:

// Temporary Eigen blocks
Eigen::Block<const Eigen::SparseMatrix<double> > 
tmpAPotentialBlock(A.block(startPotential, startPotential, sizePotential,sizePotential)), 
tmpAFlowBlock(A.block(startFlow, startPotential, sizeFlow, sizePotential));
for (Eigen::SparseMatrix<double>::Index k=0; k<sizePotential; ++k) {
// Iterator to the first term of the column k of the potential block and the flow block.
Eigen::Block<const Eigen::SparseMatrix<double> >::InnerIterator itAPotential(tmpAPotentialBlock,k),
itAFlow(tmpAFlowBlock,k);
...
}

基本上问题在于不再为块或至少稀疏块定义InnerIterator

我知道您现在需要使用evaluator来定义这一点。有谁知道新语法是什么?

你需要写:

Eigen::InnerIterator<SpBlock> it(tmp,k)

下面是一个独立的 C++11 示例:

using SpMat = Eigen::SparseMatrix<double>;
using SpBlock = Eigen::Block<const SpMat>;
SpMat A;
Index i, s;
SpBlock tmp(A, i, i, s, s);
for (Eigen::Index k=0; k<s; ++k) {
Eigen::InnerIterator<SpBlock> it(tmp,k);
/* ... */
}

在 C++17 中可以变得更漂亮:

Eigen::SparseMatrix<double> A;
Index i, s;
auto tmp = A.block(i, i, s, s);
for (Eigen::Index k=0; k<s; ++k) {
Eigen::InnerIterator it(tmp,k);
/* ... */
}

最新更新