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

Matrix Matrix Multiplication

Tags: None
(comma "," separated)
ricardo_marques
Registered Member
Posts
1
Karma
0

Matrix Matrix Multiplication

Wed Aug 21, 2013 3:44 pm
Hi,

I have a piece of code which looks like this:
    MatrixXf res;
    MatrixXf Y(n2, 3);
    for(int i=0; i<n2; i++) {
    res = meanValue + k_invQ.at(i).transpose() * correction;
    Y(i,0) = res(0,0);
    Y(i,1) = res(0,1);
    Y(i,2) = res(0,2);
    }

where meanValue is a matrix of size (1, 3), k_invQ is a c std vector containing n2 eigen vectors of dynamic size (give by a variable n1) and correction is a matrix of dynamic size (n1, 3). I would like to accelerate this piece of code. For this, I have substituted the above code by:

    MatrixXf Y;
    VectorXf xx = VectorXf::Ones(n2);
    Y = xx * meanValue + k_invQ_Matrix * correction;

where k_invQ_Matrix is a matrix of dynamic size (n2, n1) containing the same information as the one in k_invQ, but in the form of an eigen library matrix. When I run the latter code, the execution time is much larger. Could you please help me with this?

Cheers,
Ricardo
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Matrix Matrix Multiplication

Thu Aug 22, 2013 11:21 am
The following should give you the best performance, but make sure you compiled with optimizations enabled (e.g., -O2 with gcc).
Code: Select all
RowVector3f meanValue(...);
MatrixXf Y = meanValue.replicate(n2,1);
Y.noalias() += k_invQ_Matrix * correction;


Bookmarks



Who is online

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