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: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 5 Feb 2010 00:00:19 -0500
- 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 :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=w+SgSqn29F4YcQL2qmOIlhJN8M9MvPaY9TSjW3dg6Aw=; b=xqSrsfkxyUFyM8PejJd3qY5HSq7heltckh/OH7eAsdfe+QgpZC+5ShLdJ1ripPft6J BdyKDcwo74xGXcP4jmNEfIb5hGLP6KtRzLaaolh5zVH3Q3UtUYLbeZN5lQunT2Ew8our nnI3O+eB+ijCcAmSa/RDyLhwgAuo3HVr5PBCA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=sEm2uc+XnVYydAZRL99DPAsrG+vaLeG4D/LSS3w9kHpwrUyUhjec0UTE58dYuwnAvj JIYto3fYVGLrLaIc/wuruCXO70f/3XT+AZdJgIv0cQloVzrbVLgWLApelMxjlTcmHyCd MPSegE6XTBGaxTjCnqtn44Q/HHWdlNa7NQaDM=
2010/2/4 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:
> 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).
Ah yes, right. And it's pretty important too to keep the principle
that the storage order never matters unless you're using Map
explicitly.
Benoit
>
> 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
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>