Using setIdentity() on a sparse matrix leads to incorrect result if there are off-trace terms, i.e. there are still off-trace non-zero terms after setIdentity(). The setIdentity() function does not check if the matrix is in compressed form. Compressing the matrix seems to fix this issue on the test below.
using namespace std;
using namespace Eigen;
//Create 5x5 identity matrix
cout<<"Correct 5x5 identity:\n\n"<<tmp<<endl; // CORRECT
//Add a value off the trace
tmp.coeffRef(3,1) = 5.0;
//tmp.makeCompressed(); // UNCOMMENT TO FIX
cout<<"5x5 identity with additional off-trace value:\n\n"<<tmp<<endl;
//Reset to the identity
cout<<"Incorrect 5x5 identity:\n\n"<<tmp<<endl; // INCORRECT !!!!!!
Thank you for the report.
-- GitLab Migration Automatic Message --
This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1088.