如何在 Eigen 3.3.4 中的稀疏块上实例化 InnerIterator?
How to instantiate an InnerIterator over a Sparse Block in 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 example:
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);
/* ... */
}
我有一段代码在 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 example:
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);
/* ... */
}