Registered Member
|
Hi,
I'd like to sum many sparse matrix. I studied the tutorial about sparse matrix and i have seen that it is possible to use the + operator. But the += ? My code is:
this code doesn't work in runtime. if i changed it with, (for example to sum only the first two) :
it works. So could you tell me the right but also the more efficient way to sum sparse matrices? Thanks |
Moderator
|
you can do:
while(...) K = (K + **iter).eval(); however, summing up sparse matrices is not an efficient operations. Do you really need to compute the individual sparse matrices? cannot you directly assemble their sum? How many sparse matrices do you have to sum up? |
Registered Member
|
It's a finite element procedure. To take my "code" more general as possible, it's better to sum up at the end of the procedure when the matrices are assembled and not before (when are small and dense). The number of the matrices is related to the user but usually we can speak about 6 sparse matrices. I will try if it's too slow |
Moderator
|
If you pick up a snapshot of the last devel branch you can also simply do something like:
The duplicates will be summed up by the setFromTriplets function in O(tripletList.size()) time. |
Registered Member
|
Thank you P.S. In the third line, triplets should be tripletList ? |
Moderator
|
right |
Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]