-
Notifications
You must be signed in to change notification settings - Fork 160
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
fix algorithm method binding #405
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: koubaa <[email protected]>
((double*)specInfo.ptr) + | ||
specInfo.size); | ||
if (spec_consts.dtype().is(py::dtype::of<std::float_t>())) { | ||
std::vector<float> pushconstsvec((float*)pushInfo.ptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see for example here. We use spec_consts.dtype().is(py::dtype::of<std::float_t>()
to choose the type for the pushconstvec to be std::vector<float>
In this case, we should be checking for push_consts.dtype().is(py::dtype::of<std::float_t>()
.
Thanks for the contribution. Before review just to make sure I understand, could you provide some examples for 1. and 2. where you saw these limitations and issues? Namely to make sure I understand what were the issues you were seeing, and also to validate whether/what tests we should add to avoid regression |
1I show an example of a problem in the code in my comment on Suppose you have the following python code:
The declaration of the generic algorithm call is:
In case 1, Fundamentally, it is because the np.array dtype for push_const was never read, the dtype for spec_type was always used to define both arrays. This actually causes memory errors, since the pointer arithmetic done by, for example the old code would do this for case 2:
which leads to out-of-bounds memory access since the underlying type of 2The pybind11 overloads defined were one of these two: A:
B:
I didn't look into the pybind11 overload set resolution rules in detail, but I observed at runtime when I did this in python:
It ended up picking overload B. I added the flexibility to the overload set to allow a mix of Test recommendationI think we should have tests that exercise all 4 of these overloads, as well as tests that mix dtypes between spec and push consts to fully cover this. |
The original overload resolution fix wasn't bulletproof here. I found an issue just now where it was picking the wrong constructor. After reading the overload resolution rules for pybind11, I fixed it. We have to use |
Signed-off-by: koubaa <[email protected]>
This fixes two issues in the python binding for the
mgr.algorithm
method:As part of the change, I refactored how the arguments were dispatched. It isn't perfectly generic, but is more concise and less error-prone than before