New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1088 - Sparse setIdentity incorrect if matrix not compressed
Summary: Sparse setIdentity incorrect if matrix not compressed
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Sparse (show other bugs)
Version: 3.2
Hardware: x86 - 64-bit Linux
: Normal Wrong Result
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-16 13:13 UTC by Iain
Modified: 2015-10-25 21:10 UTC (History)
2 users (show)



Attachments

Description Iain 2015-10-16 13:13:14 UTC
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.

MWE:

#include <iostream>
#define EIGEN_DONT_PARALLELIZE
#include <Eigen/Sparse>

using namespace std;
using namespace Eigen;

int main()
{
    //Create 5x5 identity matrix
    SparseMatrix<float> tmp(5,5);
    tmp.setIdentity();
    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
    tmp.setIdentity();
    cout<<"Incorrect 5x5 identity:\n\n"<<tmp<<endl;      // INCORRECT !!!!!!

    return 0;
}
Comment 1 Gael Guennebaud 2015-10-25 21:10:17 UTC
Thank you for the report.

devel: https://bitbucket.org/eigen/eigen/commits/52ce287938b9/
3.2: https://bitbucket.org/eigen/eigen/commits/dc628d9a5d16/

Note You need to log in before you can comment on or make changes to this bug.