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

How does Map work?

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

How does Map work?

Tue Jun 05, 2012 2:04 pm
Hi,

I only recently started using Eigen. It's a great library and I would also like to use with python/numpy. I tried Map for this as shown in the code:
void test_map()
{
double * p = new double[4];
for(int i=0; i < 4; ++i) p[i] = i;

VectorXd v = Eigen::Map<VectorXd>(p, 4);
std::cout << p << " " << v.data() << std::endl;

for(int i=0; i < 4; ++i) std::cout << i << " " << v[i] << std::endl;
for(int i=0; i < 4; ++i) v[i] = -i;
for(int i=0; i < 4; ++i) std::cout << i << " " << v[i] << std::endl;
for(int i=0; i < 4; ++i) std::cout << i << " " << p[i] << std::endl;
}
The output is:
0xc3f830 0x994030
0 0
1 1
2 2
3 3
0 0
1 -1
2 -2
3 -3
0 0
1 1
2 2
3 3

I expected the data array of VectorXd v to be equal to p but it seems that a new data array is allocated and the date are copied.
What did I do wrong? I would be very appreciative for any help.

Regards
Rolf
trrrigo
Registered Member
Posts
13
Karma
0

Re: How does Map work?  Topic is solved

Tue Jun 05, 2012 2:29 pm
Try Eigen::Map<VectorXd> v (p, 4); instead of VectorXd v = Eigen::Map<VectorXd>(p, 4); maybe


Bookmarks



Who is online

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