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

copying eigen VectorXf objects

Tags: None
(comma "," separated)
pamparana
Registered Member
Posts
18
Karma
0

copying eigen VectorXf objects

Tue Nov 25, 2014 2:32 pm
Hello,

I wanted to do something like:

Code: Select all

class StoreVec
{

private:
    std::vector<Eigen::VectorXF> m_vec;

public:
    void some_method()
    {
       for (int i = 0; i < 10; ++i) {
          Eigen::VectorXf vec(100);
          m_vec.push_back(vec);
      }
    }
};


My question is that whether it is safe to push an Eigen VectorXf into an STL container? Will it make a deep copy or is it efficient to do as I have described?

Alternatively, is it possible to take a Eigen Sparse Matrix object and multiply it with an STL vector?

Thanks,
Luca
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That will do a deep copy. As a workaround you can push back an empty vector and then swap them:
Code: Select all
m_vec.push_back(VectorXf());
m_vec.back().swap(vec);

This will only exchange the pointer and no extra memory allocation :)


Bookmarks



Who is online

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