I have this piece of code form the Eigen documentation site about slicing and indexing:
#include <iostream> #include <Eigen/Dense> #include <vector> using namespace std; using namespace Eigen; int main() { std::vector<int> ind{4,2,5,5,3}; MatrixXi A = MatrixXi::Random(4,6); cout << "Initial matrix A:\n" << A << "\n\n"; cout << "A(all,ind):\n" << A(all,ind) << "\n\n"; return 0; } When I try to compile, I get multiple errors, for example:
allis not a member ofEigenallwas not declared in this scopelastwas not declared in this scopeseqis not a member ofEigen- Function
seqcould not be resolved MatrixXi::Randominvalid arguments
How can I fix these errors?
It looks as if I had the wrong version of Eigen (it worked here), however, according to this answer I have: EIGEN_WORLD_VERSION 3 EIGEN_MAJOR_VERSION 3 EIGEN_MINOR_VERSION 7, which I believe is the latest.
As far as installation is concerned, I copied the Eigen folder to the project location and supplied a path (-I flag) to one folder above it for a g++ compiler. The library itself seems to work well; for example, this code (from supplied examples) works fine:
#include <iostream> #include <Eigen/Dense> using namespace Eigen; using namespace std; int main() { Matrix3d m = Matrix3d::Random(); m = (m + Matrix3d::Constant(1.2)) * 50; cout << "m =" << endl << m << endl; Vector3d v(1,2,3); cout << "m * v =" << endl << m * v << endl; }
QuickStart_example2_fixed.cpp, but thanks for the good advice.