Re: [eigen] A vector indexed by another vector

[ Thread Index | Date Index | More Archives ]

On 24.08.2012 16:04, Matthieu Brucher wrote:

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

   Vector vector;

   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

This has been requested several times, essentially this is directly what bug 329 wants to have:
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:


Dipl.-Inf. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252

Mail converted by MHonArc 2.6.19+