Re: [eigen] Expression templates |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Expression templates
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 30 Jul 2010 11:04:27 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=SNtmRFQf+UfDVYskvePi3BsN2RZyrPMs6M4YgGdZIJ8=; b=pgSaKRLLlkOmTfMwNEa+ihMxcmfURFzVhzIYHG/9QEBcD+EdrziGMdc9d10hnw9/fC JE/C8KT1yHw5iTG3DbbBKYeQUobfDUoAsqzdjeVHOUUeoZ9Nv5eN8LqbNLJNBKjVT5LT cE0V6tCwLmMfynf7EJ7FZepJ5BXx8r08wynro=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Y1b2h36bTgBsxoIOxPeEPJqE+NW/RU9ryRpC4cJ0OHdqeKpMhT/+ZR/8ctpR/8UPIB vZ2dcxuQT+lCoVtCdk7eAvq0DalywIiDfjl/7iD7LZCxcZgwBlb6+1GNkuL41qm0AtEA 7wGO5ik+jpaT1iprVBLikfeNWFA7ew3g33W3E=
2010/7/30 Carlos Becker <carlosbecker@xxxxxxxxx>:
> Hi all again,
> I am doing some audio processing and I am working with a set of N arrays
> (ArrayXf in this case). At a certain point, I am doing something like this:
> ArrayXf eachArray[N]; // this is pre-loaded before
> ArrayXf arrayMult[N]; // this is also pre-loaded
> ArrayXf result;
> result = eachArray[0] * arrayMult[0] + eachArray[1] + arrayMult[1] + .....
> + eachArray[N-1] * arrayMult[N-1];
>
> This operation is performed on a templated class that takes N as a template
> parameter. I made some tests and, as expected, doing something like
> result.setZero();
> for (int i=0; i < N; i++)
> result += eachArray[i] * arrayMult[i];
> is not the best option, and neither is
> result = eachArray[0] * arrayMult[0];;
> for (int i=1; i < N; i++)
> result += eachArray[i] * arrayMult[i];
>
> This is probably because of memory accessing speed, so I was looking for a
> way to 'unroll' this loop properly. Is there any template/class in Eigen
> that would allow me to do this easily?
Why don't you store your array-of-arrays as 2-dimensional Eigen arrays
to start with. Then you can do a partial reduction like rowwise sum.
typedef Array<float,Dynamic,N> ArrayOfNArrays;
ArrayOfNArrays eachArray;
ArrayOfNArrays arrayMult;
ArrayXf result = (eachArray * arrayMult).rowwise().sum();
This should be perfectly unrolled and vectorized by Eigen; if it's
not, please file a bug.
Benoit
> Thanks!
> Carlos