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

Eigen types in structs

Tags: None
(comma "," separated)
dberg
Registered Member
Posts
1
Karma
0

Eigen types in structs

Mon Jul 24, 2017 4:09 pm
I am trying to use Eigen matrices and arrays as fields in struct and running into trouble.
I have a type def statement in a header file:

typedef struct {
MatrixXd M;
} MyStruct

In the main program I have the following lines.

MyStruct *S;

S = (MyStruct*)malloc(sizeof(MyStruct));

If the field were a pointer to an array I'd know what to do next. I am having trouble setting the values to M via a move like S->M = ...
To allocate memory I've tried S->M.resize(n,n). I've also tried initializing M in the typedef. Thank you for your help.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen types in structs

Thu Jul 27, 2017 10:18 am
in C++ you should write:

struct MyStruct {
MatrixXd M;
};

and use operator new:

S = new MyStruct;

and then initialize S->M as usual:

S->M = MatrixXd::Random(10,10);


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]