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

Incorrect matrix multiplication result

Tags: None
(comma "," separated)
louchen
Registered Member
Posts
2
Karma
0
int nCol = 300;
int nRow = 126;
Eigen::MatrixXf spectrals(nRow, nCol);
spectrals.setOnes();
Eigen::MatrixXf spectrals2(nCol,nRow);
spectrals2.setOnes();
Eigen::MatrixXf mmm = spectrals*spectrals2;
saveMat(mmm, "D:\\mmm.txt");

Environment: VS2012
In the result 'mmm', there are nearly half of the columns are zeros. Is this a bug or something wrong with my code?
User avatar
benoitsteiner
Registered Member
Posts
13
Karma
0
Have you double checked the implementation of the saveMat() function? If I replace it by the following code:
Code: Select all
 std::cout << "num of coeffs equal to 300: " << (mmm.array() == 300.0f).count() << std::endl;

I get the expected result:
num of coeffs equal to 300: 15876


louchen
Registered Member
Posts
2
Karma
0
benoitsteiner wrote:Have you double checked the implementation of the saveMat() function? If I replace it by the following code:
Code: Select all
 std::cout << "num of coeffs equal to 300: " << (mmm.array() == 300.0f).count() << std::endl;

I get the expected result:
num of coeffs equal to 300: 15876


Thanks for your answer.
I find when I set Eigen::setNbThreads(1); or disable the OpenMP ,the result turned out correct.
As I enabled the OpenMP for my solution, I wonder the parallel multiplication may affect the result.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Which Eigen version are you using? (3.2 or devel branch?)


Bookmarks



Who is online

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