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

Eigen Vector from memory block

Tags: None
(comma "," separated)
tkno
Registered Member
Posts
3
Karma
0

Eigen Vector from memory block

Tue Nov 22, 2011 11:18 am
Hi,

I would like to know whether it is possible to initialize an Eigen Vector/Array from a continuous memory block without copying data. Something like:

Code: Select all
 
double * data = new double[10];
VectorXd vec(data, 10);


I have not found anything in the documentation about this.


Thank you for any answer,

Tobi
Manhigh
Registered Member
Posts
10
Karma
0
OS

Re: Eigen Vector from memory block

Tue Nov 22, 2011 12:29 pm
I believe you want:

Code: Select all
double * data = new double[10];
Eigen::Map<Eigen::VectorXd> vec(data, 10);
tkno
Registered Member
Posts
3
Karma
0

Re: Eigen Vector from memory block

Tue Nov 22, 2011 12:51 pm
Thanks for the answer. This seems to be what I am looking for. But can I compute with the map as it would be a VectorXd? Or are there restrictions. For instance can I add a VectorXd and a Map yielding a VectorXd?

Tobi
Manhigh
Registered Member
Posts
10
Karma
0
OS

Re: Eigen Vector from memory block

Tue Nov 22, 2011 1:21 pm
I'm fairly new to Eigen, but I believe that is the purpose of Maps.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen Vector from memory block

Tue Nov 22, 2011 7:56 pm
Manhigh is right. The only practical difference is that you cannot resize a Map object since it does not hold the underlying memory.
tkno
Registered Member
Posts
3
Karma
0

Re: Eigen Vector from memory block

Tue Nov 22, 2011 9:40 pm
Thanks a lot for your answers. This is exactly what I was looking for. By the way, I am quite impressed by Eigen. Great work


Bookmarks



Who is online

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