[eigen] const Static Vector/Matrix howto

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


I'd like to ask about a problem i often encounter. I need to allocate a static const Vector or matrix. That is, i already know the coefficients.

I currently do something like this:

	static double matrix_data[] = { 1., 2., 3. ,4. };
	static Eigen::Matrix< double, 2, 2 > m(matrix_data);

Which is far from perfect because i guess the data is copied, so we have both an allocation and a copy that are not really needed.

I thought about using ::map:

	Map<Eigen::Matrix< double, 2, 2 > > m(matrix_data);

but i'm not sure how efficient this is.. i guess in my first try the constructor of ::Matrix ensure alignement while in the second case, the data is where matrix_data is, which has no guaranty of being aligned, is it ? 

So  what would you suggest ? Should i ensure (how?) that matrix_data is aligned and use the Map stuff ? Any other idea?

Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>

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