-
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
[QUESTION] How to bind NumPy scalar? #3093
Comments
Here you go, little tricky but should do the work: #include <iostream>
#include "pybind11/pybind11.h"
void print_type(const pybind11::buffer &num)
{
auto a = num.request().format;
if (a == "i")
{
std::cout << "32-bit" << std::endl;
// do something for int...
}
else if (a == "l")
{
std::cout << "64-bit" << std::endl;
// do something for std::int64_t...
}
}
PYBIND11_MODULE(mymodule, m)
{
m.def("print_type", &print_type);
} Where to get values for each format? Here: https://docs.python.org/3/library/array.html The |
Using your method can indeed solve the problem, thanks. Finally, I hope that pybind can develop functions like this. #2060 (comment) Although your method solves the problem, the type annotation shows |
@sun1638650145 would be nice if that PR was master. Very convenient approach and will resolve your issue with type annotations. Sadly it looks like it is stale or dropped completely... |
I hope to implement something like this on the Python side.
This way of writing pybind is bound to pure Python int.
The text was updated successfully, but these errors were encountered: