Re: [eigen] Best way of initializing a matrix of fixed size
• To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
• Subject: Re: [eigen] Best way of initializing a matrix of fixed size
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Wed, 8 Mar 2017 14:56:59 +0100
• Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=A+Nm6KkIiyrJowW/o4/upmyKx6Qfk+G+xBbERXzrVN8=; b=gdEgov4L9Hc4bKa70vWltMFb9LtRUqulRadfUGxwzyzamLPJgqH0crhDPiz3tfnOdK d4fKEB4unnfPh8ps5cSSPxcvXqiwxlWpSMN0jd30/2EW7RKpA79tVreY2oGyXkD775s+ y/KpPyBdw3MA4YLcNBi4TdoFEn4YMYFvgoc89GxqjB6tbuAgqSErFGy/VDMLd5R8IjwM EK24clGOXWDblryVLoVrumtPlOdAxCoTpZt3XEcfikxvC0B8HTBSq5NwwGrznpV/e50H UlT7uTGxGeAfYeC+dWyYeyZNoYRwitsoJ7gbr7TAiCEfhezdKxRLhuvPsdvsA5Sxdtd6 OAfw==

Strange, it usually compiles to trivial code, e.g.:

void foo(Matrix4f &m)
{
m <<  1,  2,  3,  4,
5,  6,  7,  8,
9, 10, 11, 12,
13, 14, 15, 16;
}

compiles to:

movaps LCPI0_0(%rip), %xmm0    ## xmm0 = [1065353216,1084227584,1091567616,1095761920]
movups %xmm0, (%rdi)
movaps LCPI0_1(%rip), %xmm0    ## xmm0 = [1073741824,1086324736,1092616192,1096810496]
movups %xmm0, 16(%rdi)
movaps LCPI0_2(%rip), %xmm0    ## xmm0 = [1077936128,1088421888,1093664768,1097859072]
movups %xmm0, 32(%rdi)
movaps LCPI0_3(%rip), %xmm0    ## xmm0 = [1082130432,1090519040,1094713344,1098907648]
movups %xmm0, 48(%rdi)
popq %rbp
retq

make sure you compiled with full optimization. If so, check the respective assembly.

gael

On Tue, Mar 7, 2017 at 1:57 PM, Matthieu Brucher wrote:
Hi,

I'm wondering what is the best way of initializing a 4x4 matrix. I'm currently using the comma initializer, but it shows up quite high on a valgrind profile compared to taking the inverse of the same matrix or preprocessing the coeffs (pow, ln...).
I'm using Eigen 3.2.4, but I can upgrade.

Cheers,

Matthieu
--
Information System Engineer, Ph.D.
Blog: http://blog.audio-tk.com/