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

Iterate over elements in a row or col in a sparse matrix?

Tags: None
(comma "," separated)
eigenlearner
Registered Member
Posts
17
Karma
0
The 3.1 version sparse matrix tutorial gives an example of iterating ALL elements over a sparse matrix using outersize and innterIterator methods. However, I just want to iterate over (non zero) elements in a SPECIFIC row (col major) or column (row major). I cannot figure it out from the documentation.

Anyone here know what is the fastest and easiest way to do that?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This cannot be done efficiently. You should find a way to avoid having doing this. For instance, if you have a m x m column major matrix, and n nonzero per column, and want to loop through a given row, then this would be a log_2(n)*m operation!!!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
In other words there is no more efficient algorithm than doing:

for(int j=0; j<m; ++j)
mat(i,j);


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]