This forum has been archived. All content is frozen. Please use KDE Discuss instead.

operator = of sparse matrix behaves weirdly.

Tags: None
(comma "," separated)
facat
Registered Member
Posts
1
Karma
0
a short code snippet as below
Code: Select all
int main()
{
    Eigen::SparseMatrix<double/*,Eigen::RowMajor*/> m(2,2);
    m.coeffRef(0,0) = 3;
    m.coeffRef(1,0) = 2.5;
    m.coeffRef(0,1) = -1;
    m.coeffRef(1,1) = m.coeffRef(1,0) + m.coeffRef(0,1);
    std::cout << m << std::endl;
    m=m;//in common sense this makes no sense, but ...
    for(int k=0; k<m.outerSize(); k++)
    {
        for(Eigen::SparseMatrix<double>::InnerIterator it(m,k); it; ++it) //this loop is skipped
        {
            std::cout<<it.row();
            std::cout<<"\t";
            std::cout<<it.col()<<"\t";
            std::cout<<it.value()<<std::endl;
        }
    }
}

Nothing is printed in the for loop. If m=m is commented out, column, row and value is printed. Can someone tell my why? Thanks a lot.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I think you discovered a bug in Eigen. Fill free to fill a bug report there eigen.tuxfamily.org/bz/ to make sure we do not forget about it. The proper fiw would be to detect this in SparseMatrix::operator=(const SparseMatrix&) and directly return *this.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]