This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to create a const Matrix?

Tags: None
(comma "," separated)
n2k
Registered Member
Posts
41
Karma
0

How to create a const Matrix?

Thu Aug 19, 2010 9:06 pm
Hi,

I was wondering if there is a way to initialize a const Matrix, something like the following:

Code: Select all
class MyClass{

public:

const Eigen::Matrix<double,2,2> M;

MyClass() : M(1,2,3,4) {}

};


Thanks for your help.
Hauke
Registered Member
Posts
109
Karma
3
OS

Re: How to create a const Matrix?

Fri Aug 20, 2010 10:29 am
n2k wrote:I was wondering if there is a way to initialize a const Matrix ...


There is, through the comma initializer.

Code: Select all
const Matrix2d tmp( (Matrix2d() << 1, 2, 3, 4).finished() );


HTH,
Hauke
hazelnusse
Registered Member
Posts
5
Karma
0
OS

Re: How to create a const Matrix?

Mon Aug 20, 2012 7:59 pm
Does this approach incur a runtime cost or will this initialization be done statically?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: How to create a const Matrix?

Mon Aug 27, 2012 11:21 am
that depends on the complexity of the initialization and on the ability of the compiler to optimize the underlying code. In my experience, the compiler always did a pretty good job to eliminate all runtime code.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]