Re: [eigen] const Static Vector/Matrix howto |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] const Static Vector/Matrix howto
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 4 Feb 2010 23:55:02 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=3GAw9gFhF1F94pGwoECwIBJ9iTS0nnsuI65BvLHEkc4=; b=g17hyj0Y63yVjDO53pcL/3N6e6aAIGs0JgQkcO8T+huaz1ncccQNS4hoBPutW8GRt0 4s4QBnkJFBJYCaexnTmiDyEVzXwnTyu4ycJeDMsaqaFDFTgFzRSw5Q+YQXrR9LjIODhz 7gGPnGXoZISpDLJkR8TWK2/gNxk8CVoTt906c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=gjdRDPUm88kFFpEAPg8VeO7uGZaNhIUKZkbHkhsZ7J90H0xIaqPIniyFNlW3qG2hpC 9u9veCV14pQtskn+to7zscPriglQ4+2rtpP7huzL39MR8OA1En+9rq1qhWTZr0tp0t4F TJaFhVc7ipN3WS83PcgXzHZp3ZInI+snCLxWk=
On Thu, Feb 4, 2010 at 11:32 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 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.
I was going to propose the same :) However, note that the order of the
coefficients should be row major:
mat(1,2,
3,4);
like the coma initializer. So we cannot simply call coeffRef(int index).
gael
>
> 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
>>>
>>>
>>>
>>
>>
>>
>
>
>