Re: [eigen] A vector indexed by another vector |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 24.08.2012 16:04, Matthieu Brucher wrote:
Hi,
I'd like to replace some of my code that consits of a indexed for loop by a
pure Eigen statement.
In fact, I have several of these loops, but the most simple one is the
following:
Vector vector;
vector.resize(size);
for(long j = 0; j < size; ++j)
{
long i = offset[j];
float tmp = t02 + h2[i] * val[0];
vector[j] = tmp > 0.0f ? std::sqrt(tmp) + tsdiff[i] : -1000.f;
}
The issue is that h2 is not accessed in order, but with values from the
offset vector. Is there a way to efficiently write this kind of loop with
Eigen?
This has been requested several times, essentially this is directly what
bug 329 wants to have:
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=329
There is a prototype implementation, I'm not sure how well it
worked/works with the current Eigen version.
If, however, the offset array is a permutation, i.e. each index occurs
exactly once, you should be able to solve it using:
http://eigen.tuxfamily.org/dox-devel/classEigen_1_1PermutationMatrix.html
Christoph
--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------