Registered Member
|
Hi,
so I basicly want to create a Sparse Matrix, which Diagonal is saved in a VectorXd. This matrix is supposed to get added to another sparse matrix. In Matlab this would be M=spdiags(v); Being confused by the way the Diagonal, normal and Sparse Matrix interact in Eigen, I found this thread: https://forum.kde.org/viewtopic.php?f=74&t=128552#p342800
But this minimal example already gives me a compiler error:
These are my includes:
Thanks for your help! |
Moderator
|
You need the 3.3 branch.
|
Registered Member
|
Thanks for your reply, I will try and report back.
Edit: I tried it, and it compiled with the devel version, but as soon as I start putting numbers in things start to fall apart.
This crashes with an assertion error
|
Moderator
|
Indeed -= or += operators assumes that the diagonal elements exists. I admit that the error message is not very clear... On the other hand, doing:
sparse_mat1 = diag_C; or sparse_mat1 = -diag_C; will work as expected. Once the diagonal coefficients exists, you can modify them: sparse_mat1 += VectorXd::Ones(n).asDiagonal(); or: sparse_mat1.diagonal().array() += 1.0; etc. |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]