-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Wrong buffer format returned for similar numpy arrays passed to pybind11 function #1806
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
Comments
1 task
It seems that it is not that simple. Basically, py_buffer format can have two characters (https://docs.python.org/3/library/struct.html#byte-order-size-and-alignment):
|
Related to the discussion on #1908: If there's something where pybind11 mismatches pure numpy, please do reopen! |
havogt
pushed a commit
to GridTools/gridtools
that referenced
this issue
Apr 12, 2021
Python integer format char is ambiguous and platform dependent. PyBind11 `format_descriptor<...>::format()` always returns "q" and "Q" for 64bit integers, independent of the platform. Compatible passed-in Python buffers on the other hand might also have the equivalent format "l" or "L" set. See pybind/pybind11#1806 and pybind/pybind11#1908 for details. This fix introduces a special case for integer format comparisons, just checking size and signedness.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue description
Function accepting
pybind11::buffer
reports different underlying type when provided with (at least at the first glance) numpy arrays. I can only guess it may be more related to numpy which somehow fails to comply with python's buffer protocol in some cases. But I want to make sure that pybind11 doesn't do anything that could affect this.Reproducible example code
a reports to have
q
format while bl
which is wrong in b case. Numpy claims dtype as int64 for both of them.Full repro attached, just issue
run.sh
(and make sure that pybind11 is present in the same dir asrun.sh
).The text was updated successfully, but these errors were encountered: