I have this piece of code form the Eigen documentation site about slicing and inexing:
#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:
all
is not a member ofEigen
all
was not declared in this scopelast
was not declared in this scopeseq
is not a member ofEigen
- Function
seq
could not be resolved MatrixXi::Random
invalid 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;
}