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

Zero-dimension matrix multiplication

Tags: None
(comma "," separated)
kerryloux
Registered Member
Posts
6
Karma
0
Hello all,

I am working on a project that requires that zero-size matrix multiplications are allowed (i.e. an mx0 matrix times a 0xn matrix should result in an mxn matrix of zeros).

I swear that I had attempted something similar using Eigen a few months back, but I seem unable to get it to work now. I am getting "you are using a non-initialized matrix" assertions when executing my application. A simple example is:

Code: Select all
// Expect 6x1 vector of zeros, instead get assertion failure
MatrixXd m = Matrix<double, 6, 0>::Zero() * Matrix<double, 0, 1>::Zero();


Does Eigen support (or can it be made to support, through the use of a certain flag?) operations on matrices with a zero-dimension? Searches on the topic don't turn anything up. It seems that while Dynamic is defined to be -1, after a dynamically sized matrix is created, the size of the dimension is 0, and there's nothing to distinguish an uninitialized matrix with dynamic size from one that has a dimension set to 0?

Thanks,

Kerry
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It does work with the devel branch or when using Dynamic instead of "6" & "1".
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
kerryloux
Registered Member
Posts
6
Karma
0
Excellent!

Thanks for the help.

-Kerry
kerryloux
Registered Member
Posts
6
Karma
0
Hello Gael,

I have one follow up question - consider the following example:
Code: Select all
   // Case 1
   MatrixXd m1 = Matrix<double, 6, 0>::Zero();
   VectorXd v1 = Matrix<double, 0, 1>::Zero();
   MatrixXd r1 = m1 * v1;

   // Case 2
   Matrix<double, 6, Eigen::Dynamic> m2 = Matrix<double, 6, 0>::Zero();
   VectorXd v2 = Matrix<double, 0, 1>::Zero();
   MatrixXd r2 = m2 * v2;// Assertion failure under Linux


In both cases, I expected to see a 6x1 matrix of zeros. Under MSW (MSVC 2010) this works just fine. Under GTK (Ubuntu 13.10, g++ 4.8.1) only the first case works - for the second case, where the size of m2 is not explicitly specified, I still get the same assertion failure on the last line.

Should I expect both cases to work, or is the behavior under Linux proper?

Thanks,

Kerry


Bookmarks



Who is online

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