【问题标题】:How to instantiate an InnerIterator over a Sparse Block in Eigen 3.3.4?如何在 Eigen 3.3.4 中的稀疏块上实例化 InnerIterator?
【发布时间】:2018-05-18 15:16:54
【问题描述】:

我有一段代码在 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 来定义它。有谁知道新语法是什么?

【问题讨论】:

    标签: block sparse-matrix eigen eigen3


    【解决方案1】:

    你需要写:

    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);
        /* ... */
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2015-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      相关资源
      最近更新 更多