Registered Member
|
Hi,
I use two sparsematrices and two dense vectors that have to be updated frequently during an iterative solving process. The matrices are very sparse, it exists indeed only one Element != 0 per column, wich position stays the same, but the value has to be updated. Currently I use the CoeffRef method to search for the specific Element position, give the References to a method of my own and assign a new value to the element. Three values at once are calculated by a relativ complicated (big therms, exp functions...) mathematical function and then assigned to the references taken as parameter. Looks like this (eg in a for-loop):
But coeffRef method is usually not a fast way to fill a sparsematrix . Is it ok for filling the dense vectros? . Can you imaging a faster way to do the same? I see 2 more possibilities: 1) Create a new matrix in every iteration-step and fill them with a triplet list wich has been updated. 2) Somehow iterate over the inner vectors of the sm in order to put new values to the entries. Some suggestions? greetings medic |
Moderator
|
For dense objects, using coeffRef is perfectly fine. For sparse matrices, if there is only 1 non zero per inner vector, and that the sparcity pattern does not change, coeffRef is a O(1) operation, so very fast!
Note that you should bench in release mode only, i.e., with optimizations enabled, and with -DNDEBUG. |
Registered Member
|
Thank you for your expert-knowledge, nice to know that I must not do something fancy and eigen is just fast.
I want to leave this topic open until I tested the whole algorithm within this this week, just in case... I will post if everything worked fine and the thread is solved. Greeting, medic |
Registered Member
|
Works fine and is as fast as manually iterating over the inner vectors. Solved...
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]