Registered Member
|
Hello,
I am new to Eigen and trying to use the SparseMatrix class. If I set the value of a SparseMatrix entry in Eigen as follows:
Would this actually shrink the storage required by the matrix or would it try and store a 0 and use up 4 bytes there (assuming integer type)? If the answer is the latter, how can I set entries to 0, so that it does not use my extra space? Also, what about something like this:
Would explicit zeros be stored in this case? If I want to avoid that, what should I do. Thanks a lot, Luca |
Moderator
|
Doing: t.push_back(TripletType(i, j, 0)) will insert an explicit zero, so just do not insert it.
|
Registered Member
|
Thank your for the answer. However, if I have many entries to update, it seems that the Triplet way is the best way to do it in an efficient manner at least from the Eigen documentation that I have seen so far. In that case, can you suggest how to update the entries (in a batch) but not setting an explicit zero. So, the entries could or could not have an explicit value but I would like to reclaim it.
Do you mean, have something like:
instead of:
Also, any idea what can be done for individual updates like:
Thanks again, Luca |
Moderator
|
Your question is not clear, so let me try to reformulate. Are you saying that you already have a sparse matrix A that you already used for some purpose like solving Ax=b, and now you would like to change a *few* entries in A, and in particular to remove some? If that's so, then set them to 0 using A.coeffRef(i,j) = 0, and once you're done, you can remove them with A.prune().
|
Registered Member
|
Thanks for the answer. This is what I meant. So I guess the solution is to call prune regardless of whether I use coeffRef or use the Triplets to set the entries to zero.
|
Moderator
|
The triplet list cannot be used to partially modify a matrix. It can be used to set all coefficients at once. Implicitly, setFromTriplets does a global setZero().
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]