Reputation: 11
I am building a c++ program linked to python code, using pybind11.
I use Eigen for the matrix operations.
I am having issues with the slicing of an Eigen array.
According to Eigen documentation, it is possible to slice an array using Eigen::placeholders::all
-
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(Eigen::placeholders::all,ind) << "\n\n";
However, when I try to use this syntax in my code, I get the following error:
error: ‘Eigen::indexing’ has not been declared
I found an explanation for this - The Eigen header I used is of pybind11, not the original Eigen
header.
This explains the issue, but not helping with a solution.
I tried including the original Eigen headers, but it won't include the indexing
or placeholders
namespaces.
Thank for your assistance!
edit: Here is the code I tried to compile:
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <pybind11/iostream.h>
#include <iostream>
#include <valarray>
#include <Eigen/Core>
namespace py = pybind11;
void example()
{
std::vector<int> ind{4,2,5,5,3};
Eigen::MatrixXi A = Eigen::MatrixXi::Random(4,6);
std::cout << "Initial matrix A:\n" << A << "\n\n";
std::cout << "A(all,ind):\n" << A(Eigen::placeholders::all,ind) << "\n\n";
}
For which I got the following error:
error: ‘Eigen::placeholders’ has not been declared
Upvotes: 0
Views: 558
Reputation: 11
Eventually I was able to solve the issue - it was an issue with the cmake files, and specifically, the FindEigen3.cmake
was missing under the cmake folder.
Somehow, (probably because of pybind11/Eigen
header) the program was able to compile, but could not find all the relevant headers.
After adding the FindEigen3.cmake
under the cmake folder, all included folders were correct, and I could use Eigen::placeholders::all
.
Thanks @Homer512 for the assistance!
Upvotes: 1