-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numpy arrays scalar #1224
Comments
I'm not an expert but can you do:
|
This doesn't work because this prototype only accepts array, not scalar.
|
I was just doing a similar thing. It m.def("overloaded", [](py::buffer a)
{
auto buf = a.request();
if (buf.ndim == 0)
{
return "scaler of type " + buf.format;
}
else
{
return "ndarray of type " + buf.format;
}
}); Numpy < 1.15.0 >>> import np_scalar
>>> np_scalar.overloaded(numpy.array([1], dtype="int32"))
'ndarray of type i'
>>> np_scalar.overloaded(numpy.int32(1))
'ndarray of type B' Numpy >= 1.15.0 >>> import np_scalar
>>> np_scalar.overloaded(numpy.array([1], dtype="int32"))
'ndarray of type i'
>>> np_scalar.overloaded(numpy.int32(1))
'scaler of type i' As a workaround you could use ctypes to specify scalers >>> import ctypes
>>> np_scalar.overloaded(ctypes.c_int32(1))
'scaler of type <i' edited for numpy 1.15 release |
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
`set_attribute` requires numpy 1.15.0+ in order to handle scalars properly. Refs: numpy/numpy#10265 pybind/pybind11#1224 (comment)
@fbriol If you're still monitoring this issue, can you take a gander at the solutions (/ workarounds) in these two issues? Both were for leveraging NumPy to gain access to "off the beaten path" floats, like |
Hello I need different functions taking as arguments a value of « numpy arrays scalar » type.
It is possible to write prototypes like this:
However, this method does not allow to intercept scalars, for example:
How do we intercept numpy arrays scalar?
Thank you very much for your help.
The text was updated successfully, but these errors were encountered: