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

Element access of sparse symmetric matrix

Tags: None
(comma "," separated)
senorbabun
Registered Member
Posts
1
Karma
0
Hi, could someone help me understand why this does not compile and what the correct way would be to access elements in a symmetric sparse matrix. In my real code the matrix is created once and I would like to write to the matrix elements without having to explicitly check which index is greater.

Eigen::SparseMatrix<double> sm(3,3);
sm.selfadjointView<Eigen::Lower>.coeffRef(1,2)+=1.0;

Thanks,
Staffan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
The best is that you check the indices yourself:

if(i>=j) sm.coeffRef(i,j) += 1;

Otherwise, in typical assembly code we would have an ambiguity when doing:

sm.selfadjointView<Lower>().coeffRef(i,j) += 1;
sm.selfadjointView<Lower>().coeffRef(j,i) += 3;

-> shall we ignore the second call to coeffRef or add 3 to the symmetric coefficient i,j ???


Bookmarks



Who is online

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