Re: [eigen] const Static Vector/Matrix howto

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


If it makes your life easier to allow the Matrix contructor taking
x,y,z,w for 2x2 matrices, then I'm OK with that and that is a very
simple change in Matrix.h : remember that matrix.coeffRef(int index)
is allowed for all matrices, not just vectors.

Benoit

2010/2/4 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:
> I think you can do this:
>
> EIGEN_ALIGN16 double matrix_data[] = { 1., 2., 3. ,4. };
> Matrix2d::AlignedMapType m(matrix_data);
>
> There are no copies involved and the matrix m is aligned.
>
> - Hauke
>
> On Thu, Feb 4, 2010 at 3:40 PM, Thomas Capricelli <orzel@xxxxxxxxxxxxxxx> wrote:
>>
>> Hi,
>>
>> 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
>> --
>> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
>> http://www.freehackers.org/thomas
>>
>>
>>
>
>
>



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