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
BUG: Clipping code assumes alignment % itemsize == 0
#26341
Comments
My understanding of the code in question is that it is only assuming that items are spaced in multiples of the itemsize. i.e. Does NumPy not provide those guarantees on entry to the clip function? |
No, it guarantees alignment, which is good enough for that. But alignment can be smaller than itemsize. |
So the above code would also fail for I agree we should avoid the pattern altogether, especially since for most other ufuncs, we explicitly keep the pointers and just add the step to it. |
itemsize == alignment
alignment % itemsize == 0
Closing, the speedup PR included the fix. |
The clipping code contains lines like:
NumPy guarantees that ufunc data is aligned, but NumPy does not guarantee that alignment is equal to the itemsize. (in particularly, that is clearly not true for complex numbers)
As the quick fix: The code shouldn't use this pattern at all, I think.
But even if we ignore complex (because clipping and complex are weird), do platforms even guarantee that for the basic numerical types? Should code at least have a
static_assert()
or so if using such a pattern?(xref gh-26280 because that is why I noticed)
The text was updated successfully, but these errors were encountered: