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
Hello, I'm just trying to make sure I am not doing something really dumb here.
I basically want to have a function that uses std::variant types to handle the dispatching on the c++ backend but as an entry point use numpy arrays. In that sense every single pybind function will start with casting a numpy array to a c++ variant of typed numpy arrays from pybind11. In some cases I do not want to support all types for the variants, in which case I need to throw an error if the incorrect type is passed in. One problem I am having now is that on certain platforms I am getting an unhandled c++ exception when in principle it should throw a c++ exception and pybind11 should dispatch that exception to a python error. I have a minimal example of where this happens and I want to make sure it is not something dumb that I am doing:
in the extension I have the following simple function:
#include<pybind11/pybind11.h>namespacepy= pybind11;
py::array_t<int8_t> test (py::array arr){
constint type_num = arr.dtype().num();
switch (type_num) {
case py::detail::npy_api::NPY_INT8_:
return py::array_t<int8_t>(arr);
default:
throwpy::value_error("test");
}
}
PYBIND11_MODULE(ext, m) {
m.def("test", &test);
}
In this case ext.test(np.zeros(...,dtype=np.int8)) should be (and is) fine while any other type array should fail. This will give me a zsh: trace trap error when I run this with a bad argument while in principle it should just throw a Python error.
So the weird thing is that this only happens on my macbook m1 while on my other computers or in a linux/windows platform it works just fine.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I'm just trying to make sure I am not doing something really dumb here.
I basically want to have a function that uses std::variant types to handle the dispatching on the c++ backend but as an entry point use numpy arrays. In that sense every single pybind function will start with casting a numpy array to a c++ variant of typed numpy arrays from pybind11. In some cases I do not want to support all types for the variants, in which case I need to throw an error if the incorrect type is passed in. One problem I am having now is that on certain platforms I am getting an unhandled c++ exception when in principle it should throw a c++ exception and pybind11 should dispatch that exception to a python error. I have a minimal example of where this happens and I want to make sure it is not something dumb that I am doing:
in the extension I have the following simple function:
In this case
ext.test(np.zeros(...,dtype=np.int8))
should be (and is) fine while any other type array should fail. This will give me azsh: trace trap
error when I run this with a bad argument while in principle it should just throw a Python error.So the weird thing is that this only happens on my macbook m1 while on my other computers or in a linux/windows platform it works just fine.
Beta Was this translation helpful? Give feedback.
All reactions