6

I am trying to wrap up a c++ function that takes in Eigen::Quaternion as the argument for python usage. The function is defined as something like:

void func(const Eigen::Quaternion<double> &rotation) {...}

I am using pybind11 to wrap it for python and in my pybind11 I have:

#include <pybind11/eigen.h> // I have this included

PYBIND11_MODULE(example, m)
{
    m.def("func", &func, "example function");
}

Everything looks good, it compiles, but when I call it by:

func(np.array([0, 0, 0, 1]))

I got error:

func(): incompatible function arguments. The following argument types are supported: 1. (arg0: Eigen::Quaternion<double,0>) -> None

Did some googling and could not find an answer regarding if Eigen::Quaternion can be casted to/from numpy array and what shape of the array should be used? I thought Quaternion can be just casted from a 4 element numpy ndarray but seem it is not, any one knows how to do that?

shelper
  • 10,053
  • 8
  • 41
  • 67

1 Answers1

-2

I think the issue is that eigen quat needs doubles and you have constructed your np.array with ints.

func(np.array([0.0, 0.0, 0.0, 1.0]))

will probably work?

Munkybutt
  • 16
  • 2