Re: [eigen] bug in data() on col/row

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi

Well, I know that this was my expectation - and I'm fully aware that this code is kinda bogus. But on the other hand, writing

somematrix.row(2).data() does give the expectation that you get that row data (as this is what the code is trying to tell me). That's why I wrote that mail - I think that code is unsafe and can lead to "unexpected" behaviour and if there is something Eigen can do about this, it should be done

Cheers
Benjamin

Benoit Jacob wrote:
Hi,

Matrices can be stored in either row-major or column-major order.
Eigen defaults to column-major and you were apparently expecting it to
be row-major, that's all :)

If you want row-major, do:

typedef Matrix<float,3,3,RowMajor> RowMajorMatrix3f;

and henceforth use this typedef instead of Matrix3f.

Cheers,
Benoit

2009/8/27 Benjamin Schindler <bschindler@xxxxxxxxxxx>:
Hi

I just discovered a nasty "bug" - depending on how you look at it -  in
Eigen, see the following program:

#include <eigen2/Eigen/Core>

using namespace Eigen;
using namespace std;

void copy(const float *from, float *to)
{
   for(int i=0;i<3;i++)
       to[i] = from[i];
}

int main(int argc, char** argv)
{
   Matrix3f m;
   m << 1,2,3,4,5,6,7,8,9;
   cout << m << endl << endl;
   float var[3];
   copy(m.row(0).data(), var);
   Map<Vector3f> map(var);
   cout << map.transpose() << endl;
}

bschindl@hundertwasser ~ $ ./test
1 2 3
4 5 6
7 8 9

1 4 7

When I save m.row(0) in a Vector3f and output it, I of course get this:


bschindl@hundertwasser ~ $ ./test
1 2 3
4 5 6
7 8 9

1 2 3

That's a nasty thing - and can cause lots of pain...
Is there something we can do about it?

Cheers
Benjamin










Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/