Regression from 3.2.9 or working as intended?
Submitted by Pierre G.
Assigned to Nobody
Link to original bugzilla bug (#1359)
Version: 3.3 (current stable)
Description
Hi,
The following code compiles in Eigen 3.2.9 but fails to compile starting 3.2.10 and in the current release (3.3.1)
#include "include/eigen3/Eigen/Sparse"
#include <iostream>
int main()
{
Eigen::SparseMatrix<double> sm(5,5);
std::vector< Eigen::Triplet<double> > tpl;
tpl.push_back(Eigen::Triplet<double>(0, 0, 1));
tpl.push_back(Eigen::Triplet<double>(0, 1, 2));
sm.setFromTriplets(tpl.begin(), tpl.end());
sm.row(0) *= 2;
std::cout << sm << std::endl;
return 0;
}
The error I get is:
include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h:127:42: error: no type named ‘InnerIterator’ in ‘class Eigen::Block<Eigen::SparseMatrix<double>, 1, -1, false>’
for (typename Derived::InnerIterator i(derived(),j); i; ++i)
^
include/eigen3/Eigen/src/SparseCore/SparseCwiseUnaryOp.h:127:42: error: no type named ‘InnerIterator’ in ‘class Eigen::Block<Eigen::SparseMatrix<double>, 1, -1, false>’
More generally, any function that tries to access InnerIterator on a Block access to a SparseMatrix fails similarly (and perhaps logically). (note: I don't have any other example from within Eigen itself)
The sparse module documentation would indicate this is working as intended since accessing a row of a ColMajor sparse matrix should be read-only. However, it used to work until 3.2.10 (I believe 75602482 introduced the breaking change but the error is different from 3.3 as it relates to the absence of RefValue in the new sparse common iterator class introduced by this commit).
Note that it's possible to work around the bug by doing what the *= operator does without the block in the way: (this work-around is also broken in 3.2.10)
for(int k = 0; k < sm.outerSize(); ++k)
{
for(Eigen::SparseMatrix<double>::InnerIterator it(sm, k); it; ++it)
{
if(it.row() == 0) { it.valueRef() *= 2; }
}
}