Registered Member
|
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 |
Registered Member
|
Try Eigen::Map<VectorXd> v (p, 4); instead of VectorXd v = Eigen::Map<VectorXd>(p, 4); maybe
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell