[eigen] static initialization of a const Eigen::Matrix |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] static initialization of a const Eigen::Matrix
- From: Dale Lukas Peterson <hazelnusse@xxxxxxxxx>
- Date: Wed, 22 Aug 2012 11:27:57 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0Aq/xnZLrastvIVQrbgstdMR2bGeXDozfnpxaTcp8eU=; b=CGHyLah/emWdvKx978tAO0WJxTpTGpyvSlF4QAIIm8MQf/U5WGOB5FtJ1jF+mdI3t9 LgCByGCYzq2iimwpdNAztOZPwMH4gkc3AnVrjdrMLpqniS0jsUdRO/01+HstLwnhhOjC 9F8Cq1WwyigFEOSzG9zLMiGEYVJ3TkRGHUDvjj1/QxvpPTLnCsC72iXXfV7C7HCwtspK JH9wNC/bYEMKDqFAXJl78+SofledghwzQLdcYpSQueJkoSTPl2rb7B0uuAQ1Ki9oa+YP PhQWymoBD1mHdn4b2zhfkI84nZY+aUrHfMIQOY8pip6UPS4Ha1FV16yyVcJ6GeDAMFLl HGSw==
Is it possible to statically initialize a const Eigen::Matrix whose
size and entries are known at compile time? I.e, something like:
const Eigen::Matrix<float, 2, 2> A = {1.0f, 2.0f, 3.0f, 4.0f};
I wrote on the forum and there was no response, and I searched the
mailing list archives but didn't find anything. I tried variations on
the above syntax but wasn't able to get anything to work.
On the #eigen IRC channel, one user suggested:
EIGEN_ALIGN16 static const double data[]= {1.0f, 2.0f, 3.0f, 4.0f};
static const Eigen::Matrix<float, 2, 2>::ConstAlignedMapType xx(data);
In the development branch Doxygen, it looks like the Map class offers
the functionality that I'm looking for:
static const float A_[4] = {1.0f, 2.0f, 3.0f, 4.0f};
Map< const Matrix<float, 2, 2> > A(A_);
std::cout << "sizeof(A_) = " << sizeof(A_) << std::endl;
std::cout << "sizeof(A) = " << sizeof(A) << std::endl;
std::cout << A << std::endl;
which gives the output:
sizeof(A_) = 16
sizeof(A) = 16
1 3
2 4
Can I safely assume that Map is not a copy but instead just a
convenient wrapper to the C-array and that the matrix elements are not
being copied?
I tried debugging this program and depending on the optimization
settings (g++ -O0 or -O2), it seems like the Map of the float array
may or may not result in instructions being generated. I'm looking
for a solution that generates little to no overhead as I am on an
embedded environment where space is tight, so ideally static
initialization of the Map or Matrix instance would be performed. I
presume there are some other member variables besides the matrix
elements that need to be initialized before it can be used, which is
fine, I just want to avoid copies of large matrices occuring, both
for space and for cpu usage considerations.
Are there a set of best practices established for accomplishing what I
am trying to acheive?
Thanks,
Luke