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

Pairwise computation on rows of two arrays

Tags: None
(comma "," separated)
di4jc8732
Registered Member
Posts
11
Karma
0
I need to compute element-wise products of all pairwise combinations of rows of two arrays (one row from each array). There are two problems:

1. The matrices are generated by R, which is column-major always (I think), so I am taking big hits on memory access. It isn't obvious to me how best to convert. Making a copy in row-major fashion is the apparent choice.

2. I also would like to parallelize this operation and want to optimize for cache by using chunking. Since this is a ubiquitous technique, I am sure Eigen uses it, so I would like to know whether there is generic code in Eigen I can use for chunking.

Thanks a lot.

Last edited by di4jc8732 on Wed Sep 28, 2011 10:24 pm, edited 1 time in total.
mattd
Registered Member
Posts
28
Karma
0
As for 1: "If the storage order is not specified, then Eigen normally defaults to storing the entry in column-major order."
// http://eigen.tuxfamily.org/dox-devel/To ... rders.html
di4jc8732
Registered Member
Posts
11
Karma
0
Thanks for the reply.

Like I said, the two arrays are passed in from R, another program, which isn't as flexible in storage order as Eigen.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
you can keep your column major storage and do scalar * vector products,

for(int k=0; k<mat.rows();++k)
#pragma omp parallel for
for(int j=0; j<mat.cols();++j)
res[k].col(j) = mat(k,j) * mat.col(j);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]