Registered Member
|
I've just started using Eigen and stumbled upon another little problem, which I guess must have an easy solution but I'm probably not yet thinking in the "Eigen way-of-things".
Say I have to matrices A and B, and I'm looping through both like this:
It's obvious that calling A.row(i) in every inner iteration is unnecessary, so you could either use a temporary which is created in the outer loop, or you'd use a pointer or something like a row-iterator. I've read through the forum and already saw that you don't have iterators, so I'm wondering how I would solve this. I know there is rowwise(), and I can probably extend that somehow with a functor, but I guess there must be something easier? The only solution I could come up with was using 'Map' like this:
but this looks like overkill to me. |
Moderator
|
Note that .row()/.col() return a lightweight view on a row or column, and so it has zero overhead. You can also name a row:
YourMatrixType::RowXpr row_of_A(A.row(i)); that is equivalent but more elegant than your Map<> trick. If you really want/need an iterator, there is a start here: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=231 |
Registered Member
|
Thanks Gael. Row- and ColXpr were exactly what I was looking for. You're also right of course that .col(i) does not induce any overhead. In fact, I saw some improvements when introducing a temporary, but it seems this was only because of some serious slowdown(!) when using SSE2. I will open a new thread for this soon with some testcode to demonstrate this.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]