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

[SOLVED] Is this a bug of the row operator ?

Tags: None
(comma "," separated)
myguel
Registered Member
Posts
14
Karma
0
I have a strange behaviour in the example below:

the output is
4 5 6
7
5

it should be
4 5 6
5
5

doesn't it ?

The version of eigen I use is the 2.0



#include
#include

using namespace Eigen;
using namespace std;


int main()
{

Matrix3d C;
C << 1, 2, 3,
4, 5, 6,
7, 8, 9;
cout << C.row(1) << endl;
cout << C.row(1)[1] << endl;
Vector3d tmp = C.row(1);
cout << tmp[1] << endl;
}
User avatar
bjacob
Registered Member
Posts
658
Karma
3
OK, you found a bug, and it's really embarrassing that something of that order of magnitude stayed unnoticed until now. However it's not in the row expression, it's in the MatrixBase::operator[].

I modified your testcase as follows:
Code: Select all
#include
#include

using namespace Eigen;
using namespace std;


int main()
{

Matrix3d C;
C << 1, 2, 3,
4, 5, 6,
7, 8, 9;
cout << "C.row(1)[1]: " << C.row(1)[1] << endl;
cout << "C.row(1)(1): " << C.row(1)(1) << endl;
cout << "C.row(1).nestByValue()[1]: " << C.row(1).nestByValue()[1] << endl;
cout << "C.row(1).coeff(1): " << C.row(1).coeff(1) << endl;
Vector3d tmp = C.row(1);
cout << tmp[1] << endl;
}


And I get this output:
Code: Select all
C.row(1)[1]: 7
C.row(1)(1): 7
C.row(1).nestByValue()[1]: 5
C.row(1).coeff(1): 5
5


Inside the MatrixBase::operator[], the only potentially evil thing we do is derived() which is just a static_cast. Replacing that call by the static_cast makes no difference, so I am really puzzled. Gael to the rescue?


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
ggael
Moderator
Posts
3447
Karma
19
OS
bug fixed,

the problem was in MapBase where the coeff(int) method was correct but not the coeffRef(int) one called by default by operator[int] and operator(int)
myguel
Registered Member
Posts
14
Karma
0
Hi,
don't be ashamed, it is very normal to find bugs, that is why you made the lib public, isn't it?
And by the way, you have the fastest response time I ever see.
Thanks for the support and again, for the lib, I really love it.


Manuel


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell