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

wrapping VectorXf around native array?

Tags: None
(comma "," separated)
paleozogt
Registered Member
Posts
2
Karma
0
OS
I have some legacy code that I would like to speed up/simplify using Eigen. However, I'm not sure how native C arrays should interact with Eigen's vector classes.

For example, if I have a function where the native C arrays are passed in I have to memcpy the arrays into the Eigen objects:
Code: Select all
   void somecalc(float vec1[], float vec2[], size_t len) {
      VectorXf evec1(len), evec2(len);
      memcpy(evec1.data(), vec1, sizeof(float)*len);
      memcpy(evec2.data(), vec2, sizeof(float)*len);

      VectorXf answer(len);
      answer= evec1 - evec2;
      ...
   }


The memcpy's are killing any performance gain I'm getting out of Eigen-- and the legacy code is to big to rip out all of the C arrays. Is it possible to simply wrap a VectorXf around a pre-existing C array without having to memcpy it?


Thanks,
aaron
User avatar
bjacob
Registered Member
Posts
658
Karma
3


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
paleozogt
Registered Member
Posts
2
Karma
0
OS
Ah, that does it-- thanks. RTFM I guess-- though 'map' is not the name I would have guessed. (I was looking for a special constructor.)

By the way, it seems that "USING_PART_OF_NAMESPACE_EIGEN" is not enough for Map-- "using namespace Eigen" must be used in order for it to work.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
yes, i know thats confusing, that's why we're removing "USING_PART_OF_NAMESPACE_EIGEN" .


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]