Registered Member
|
Good day,
I currently have code that uses std::vectors and am new to Eigen. Could you please inform me on how to typecast these std::vectors to Eigen::VectorXd? I don't want a copy of the data in the std::vector to be made. So far, I've only seen the 'Map' function but that maps arrays and not vectors. Thank You |
Registered Member
|
You can use Map for any kind of dense objects, like vectors.
VectorXf::Map(pointer, size)
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Thanks. I figured it out. I was supposed to create a pointer to the vector as follows.
std::vector<double> v(4, 100.0); double* ptr = &v[0]; Eigen::Map<Eigen::VectorXd> my_vect(ptr, 4); |
Registered Member
|
Is their a way to get to Eigen::VectorXd to std::vector<double> ? I searched the internet but all in vain till now. May be its something very basic.
|
Moderator
|
I guess this is a cross-post, so for the record: http://stackoverflow.com/questions/2609 ... -stdvector
|
Registered Member
|
Hi,
Sorry to dredge up an old post but my issue is related. I am trying to convert a std::vector of complex doubles to a VectorXcd but am getting the error: "YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY" As far as I can tell the scalar type should both be complex doubles? Here is my code: VectorXcd v3 = VectorXcd::Map(&v2[10], v2.size()); I also tried Map<VectorXcd>v3(&v2[0], v2.size()); Thanks, Kris |
Moderator
|
Your problem is probably somewhere else. Here is a self-contained working example:
|
Registered Member
|
Thanks for this! I got it sorted, you were right it was related to an issue elsewhere in my code. |
Registered users: abc72656, Bing [Bot], Google [Bot], lockheed, Sogou [Bot], Yahoo [Bot]