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: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Thu, 4 Feb 2010 15:55:15 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.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=sllnINPc6O9JzjPfb1w/gzy1phCtuyjGFteIv0nrMFQ=; b=YeRuKqgeKhWynFNa4Ks3QJSb5ZUV/pOc0ZOso2D29f75uDhvMtLfvVpgr0v+Hd+S3M K1vgSRUzVoPDsaHMNUS6G6xxXiJpNUkxHC+8NwLxOULbq+EbnQYFtNinPzP1MQztqwsA o+Zwkb1TOdfgvFMJYjoJungmPFdOb7VX1oq9g=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=im1ctvzHrAOC4hp4c379PaQ9FQ5ImoCsCxCUNb66wrVfH1lLLSDvQvSRefW2sYGHqL tvpV6sMDCGsj7gwumgm1U7bsKZ8cPPZbQRIpYZqsSMrZhUcG5Z5g1Cyi+3OckRnejvYb TXrIEOTd4gbn12T3uZ4D1v32hl8UZ06qtADns=
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
>
>
>