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

matrix multiplication performances

Tags: None
(comma "," separated)
simoneceriani
Registered Member
Posts
2
Karma
0

matrix multiplication performances

Wed Jun 24, 2015 9:54 am
Hello

I want to premultiply 3xN matrices by a 3x3 matrix, i.e., to transform 3D points, like
Code: Select all
p_dest = T * p_source


after initializing the matrices:
Code: Select all
  Eigen::Matrix<double, 3, Eigen::Dynamic> points = Eigen::Matrix<double, 3, Eigen::Dynamic>::Random(3, NUMCOLS);
  Eigen::Matrix<double, 3, Eigen::Dynamic> dest = Eigen::Matrix<double, 3, Eigen::Dynamic>(3, NUMCOLS);
  int NT = 100;


I have evaluated this two versions
Code: Select all
  // eigen direct multiplication
  for (int i = 0; i < NT; i++){
    Eigen::Matrix3d T = Eigen::Matrix3d::Random();
    dest.noalias() = T * points;
  }

and
Code: Select all
  // col multiplication
  for (int i = 0; i < NT; i++){
    Eigen::Matrix3d T = Eigen::Matrix3d::Random();
    for (int c = 0; c < points.cols(); c++){
      dest.col(c) = T * points.col(c);
    }
  }


the NT repetition are done just to compute average time

I am surprised the the column by column multiplication is about 4/5 time faster than the direct multiplication
(and the direct multiplication is even slower if I do not use the .noalias(), but this is fine since it is doing a temporary copy)
I'have tried to change NUMCOLS from 0 to 1000000 and the relation is linear

I'm using VS2013 and compiling in release

The next figure shows on X the number of columns of the matrix and in Y the avg time for a single operation, in blue the col by col multiplication, in red the matrix multiplication

Image

Any suggestion why this happens?


Bookmarks



Who is online

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