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

Question about Reductions (EIGEN 3)

Tags: None
(comma "," separated)
lamtung
Registered Member
Posts
28
Karma
0

Question about Reductions (EIGEN 3)

Mon Oct 25, 2010 3:23 pm
Hi,

I have a sample matrix A(6,4), which looks like following:

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

I would like to reduce it into a B(3,4) matrix by summing up 2 consecutive elements (could be 3 or 4, ... consecutive elements) in every column, the new matrix should then looks like this:

2 2 2 2
2 2 2 2
2 2 2 2

In math notation: B(i,j) = A(i*2,j) + A(i*2+1,j)

How do I do this in an efficient way ? This reduction operation is part of an expression in my program

Thanks !
User avatar
bjacob
Registered Member
Posts
658
Karma
3
If your matrix is stored in row-major order, that's not too hard: something like

for(result_row)
result.row(result_row) = src.row(2*result_row) + src.row(2*result_row+1);

If your matrix is column major, that's trickier, I think you would really need to code your own expression class.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
lamtung
Registered Member
Posts
28
Karma
0
Thanks for the quick answer !
Row-major or Column-Major is actually not really a problem for me, since I can have my matrix stored in either way.

This is my situation: I have 3 arrays (since I only do coefficient-wise operations) and have to compute the following expression:

A(n,m) *= (B(n*4,m) * C(n*4,m)).reduce() * A(n,m)
(*)

n,m is the dimension of the array and reduce() is the reduction operation that I just mentioned above. 4 is the number of consecutive elements that need to be summed up

Of course I can use a temporary matrix and for loop (like what you have suggested above) to do the reduction but I think it is inefficient, isn't it ? My matrice are very big and (*) is carried out thousands times ...


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient