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

[SOLVED] peculiar bug - *Matrix Multiplication*

Tags: None
(comma "," separated)
User avatar
silicontoad
Registered Member
Posts
4
Karma
0
Hi

I may have stumbled across a peculiar bug - *Matrix Multiplication* I don't know if this is linked to the gcc compiler or is some initialisation issue in eigen or to do with the transpose function specifically, but: if,

MatrixXd res = mat1.transpose() * mat2.transpose();
//half of the matrix is empty with zeros and the columns and rows become jumbled up?
if I first declare:

MatrixXd res;
res = mat1.transpose() * mat2.transpose();

//then all is ok - can anyone confirm this?

also:
chain multiplication:
MatrixXd res;
res = mat1 * (mat1.transpose() * mat2.transpose());
//fails with similar issues as above, solved by:

MatrixXd res;
res = (mat1.transpose() * mat2.transpose());
res = mat1 * res;

Thanks

TOAD

Last edited by silicontoad on Mon Aug 24, 2009 1:07 pm, edited 1 time in total.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Is this Eigen 2.0 or the development branch?

Just to accomodate our laziness, could you post a compilable test case?


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
silicontoad
Registered Member
Posts
4
Karma
0
sorry - my fault - It's using Eigen 2.0.4 (Aug 1 release) - I can do a test case if that helps.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
OK here's a testcase:

Code: Select all
#include <Eigen/Array>
using namespace Eigen;
int main()
{
  int n = XXSIZE;
  MatrixXd mat1 = MatrixXd::Random(n,n);
  MatrixXd mat2 = MatrixXd::Random(n,n);
  MatrixXd res1 = mat1.transpose() * mat2.transpose();
  MatrixXd res2; res2 = mat1.transpose() * mat2.transpose();
  std::cout << res1.isApprox(res2,1e-3) << std::endl;
}


Testing against 2.0:
Code: Select all
=== 14:48:49 ~$ g++ n.cpp -o n -I eigen2.0 -DXXSIZE=10 && ./n
1
=== 14:48:57 ~$ g++ n.cpp -o n -I eigen2.0 -DXXSIZE=20 && ./n
0


So the bug is triggered when the size is large enough that the cache-friendly path is taken.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
The bug exists only in the 2.0 branch, not in the devel branch.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Bisected. The bug had always existed in both branches until it was fixed in the default branch by changeset bf5ef41ebba3 by Gael: "more refactoring in the level3 products"


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Good news, I just committed a fix to the 2.0 branch.

Can you please try the 2.0 branch and report? At least the above testcase works now.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
silicontoad
Registered Member
Posts
4
Karma
0
I can confirm that this now works, v. 2.0.5. Thanks


Bookmarks



Who is online

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