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

Triplets question

Tags: None
(comma "," separated)
surle
Registered Member
Posts
7
Karma
0

Triplets question

Wed Dec 03, 2014 10:26 am
Can triplets be used for acculumation purposes?

For example, I want to replace this line:

Code: Select all
A.coeffRef(i, j) += value;


with a triplet, however, I need to acculumate the values first, since I don't know all the final values beforehand.

coeffRef is very slow for me, even when I try to reserve space.
eigenUser123
Registered Member
Posts
10
Karma
0

Re: Triplets question  Topic is solved

Wed Dec 03, 2014 11:57 am
If you create a Sparse matrix, create a list of triplet and in this list you have 2 triplets pointing at the same coefficient, the two values will add when you use the setFromTriplet method.

Hope this help
surle
Registered Member
Posts
7
Karma
0

Re: Triplets question

Wed Dec 03, 2014 8:47 pm
eigenUser123 wrote:If you create a Sparse matrix, create a list of triplet and in this list you have 2 triplets pointing at the same coefficient, the two values will add when you use the setFromTriplet method.

Hope this help


Thanks!
You're right, I now see a function called sumupDuplicates. Why isn't this acculumation feature documentated?
Very useful.

I have one more question. If I partially set some values in a sparse matrix, then later, need to set some more,
it seems I cannot use Triplets, because the call to setFromTriplets() destroys the matrix. It doesn't overwrite
or preserve the old values.

Is there a way to use Triplets and not destroy the old matrix values?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Triplets question

Wed Dec 03, 2014 9:35 pm
You can keep your triplet list and extend it or create a new triplet list from the current matrix, append them, and call setFromTriplet. Perhaps we could add an addFromTripplets() members doing exactly this. Feel free to propose a patch (ideally with respective unit test).
surle
Registered Member
Posts
7
Karma
0

Re: Triplets question

Wed Dec 03, 2014 11:12 pm
Thanks, those are great suggestions. How does one fill a triplet list from a sparse matrix?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Triplets question

Thu Dec 04, 2014 9:20 am
You iterate manually over the non zeros and push_back them to the container. See http://eigen.tuxfamily.org/dox-devel/gr ... tml#title2 for a code-snippet.


Bookmarks



Who is online

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