Can we create a vector of Eigen Matrix?
Asked Answered
V

3

5

Is it possible to create a vector of Eigen Matrix?

For example, I run the following line,

vector<Matrix<double,4,1>> vector_of_matrix;

but I receive the following error,

error: template argument 3 is invalid
error: template argument 4 is invalid
error: template argument 6 is invalid
error: template argument 1 is invalid

Anyone care to enlighten me as to how we would properly initialise a vector of eigen matrices? Note, I have considered the Eigen dynamic sized matrix as an alternative, but I do not want this.

Veljkov answered 1/7, 2015 at 10:50 Comment(5)
Did you #include <Eigen/StdVector>?Argol
I haven't. I am attempting to add it now. But when I do "#include <eigen3/Eigen/StdVector>" I get the following error: /usr/include/eigen3/Eigen/src/StlSupport/StdVector.h:14:42: fatal error: Eigen/src/StlSupport/details.h: No such file or directory #include "Eigen/src/StlSupport/details.h"Veljkov
You should set include path to .../eigen3, so the #include's in the header files could get the internal header files.Argol
fyi, apparently changing it to "#include "eigen3/Eigen/src/StlSupport/details.h"" within the StdVector.h file fixed it.Veljkov
I would not recommend editing the Eigen library files yourself to fix this include error. Although you can see and edit the source code for this library you should treat it like any other third party library and only edit it if you really know what you are doing otherwise you are setting yourself up for surprises when random things stop working in the future. In this case you just need to add /usr/include/eigen3 to the include path for your project to fix the problem.Contrive
A
8

According to documentation, you must

#include <Eigen/StdVector>

and use

std::vector<Matrix<double,4,1>, Eigen::aligned_allocator<Matrix<double,4,1> > >
Argol answered 1/7, 2015 at 10:55 Comment(0)
T
0

Always use space while you specify template structures. Else c++ wont be able to parse it.

vector<Matrix<double,4,1> > vector_of_matrix;
Toughie answered 1/7, 2015 at 10:58 Comment(1)
unless you are use c++11Davit
F
0

It is necessary to #include required headers <Eigen/Core> and (C++ standard) <vector>.

Depending on age of your compiler, it is necessary to have spaces between greater than and less than signs (e.g. > > rather than >> to avoid compiler confusion). Older standards require this.

Futurity answered 1/7, 2015 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.