#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
namespace py = pybind11;
// a struct with one enum and a double
struct StructType1 {
const double x;
StructType1(const double x_) : x(x_) {};
};
// a struct with one enum and two doubles
struct StructType2 {
const double x;
const double y;
StructType2(const double x_,
const double y_) : x(x_), y(y_) {};
};
PYBIND11_MODULE(mystruct, m) {
// wrap our class with one double
py::class_<StructType1>(m, "StructType1")
.def(py::init<const double>());
// and wrap our class with two doubles
py::class_<StructType2>(m, "StructType2")
.def(py::init<const double, const double>());
// this line is fine
PYBIND11_NUMPY_DTYPE(StructType1, x);
// including the below line gives a
// ImportError: NumPy: invalid buffer descriptor!
// PYBIND11_NUMPY_DTYPE(StructType2, x, y);
}
Issue description
Attempting to
PYBIND11_NUMPY_DTYPEon a struct containing more than oneconst doublegives aImportError: NumPy: invalid buffer descriptor!error on import. A class containing a singleconst doubleruns correctly. If you change the struct to contain twoconst double's or aconst doubleand a regulardouble, it fails on import.Reproducible example code