You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use PYBIND11_NUMPY_DTYPE to wrap a structure which has a std::complex<float> member. I get the error
.../env/include/site/python3.5/pybind11/numpy.h: In instantiation of ‘struct pybind11::detail::npy_format_descriptor<foo>’:
pybind11-array.cpp:19:5: required from here
.../env/include/site/python3.5/pybind11/numpy.h:985:5: error: static assertion failed: Attempt to use a non-POD or unimplemented POD type as a numpy dtype
static_assert(is_pod_struct<T>::value, "Attempt to use a non-POD or unimplemented POD type as a numpy dtype");
I'm not sure if this is completely fixable, because std::complex has a non-trivial default constructor (initialising to 0+0i), meaning that it can never be trivial and hence not POD.
Possibly it can be addressed by weakening the static_assert so that it allows through cases like this, and trusting the user not to do something silly. For example, it might be weakened to only require that the type is standard-layout and trivially copyable rather than POD (I couldn't find a guarantee in N4296 that std::complex is standard-layout, only that it is literal, but I can't imagine an implementation that isn't standard-layout yet adheres the layout compatibility with T[2]).
Any such implementation would break anyway: we explicitly allow single std::complex<T> values (for T in double, float, long double) which numpy is going to read/write to directly as a T[2]. The issue is mainly how to allow them when they are in a struct.
Issue description
I'd like to use PYBIND11_NUMPY_DTYPE to wrap a structure which has a
std::complex<float>
member. I get the errorI'm not sure if this is completely fixable, because std::complex has a non-trivial default constructor (initialising to 0+0i), meaning that it can never be trivial and hence not POD.
Possibly it can be addressed by weakening the static_assert so that it allows through cases like this, and trusting the user not to do something silly. For example, it might be weakened to only require that the type is standard-layout and trivially copyable rather than POD (I couldn't find a guarantee in N4296 that std::complex is standard-layout, only that it is literal, but I can't imagine an implementation that isn't standard-layout yet adheres the layout compatibility with
T[2]
).Reproducible example code
Compiled with
g++ -std=c++14 -c pybind11-array.cpp
plus-I
options for my installation of Python and pybind11.The text was updated successfully, but these errors were encountered: