-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Maybe get rid of Cython #741
Comments
Here is the best I can do with pure NumPy: def query_integral_image_np(integral_image, size_x, size_y, random_state):
area = integral_image[:-size_x, :-size_y]
area += integral_image[size_x:,size_y:]
area -= integral_image[size_x:, :-size_y]
area -= integral_image[:-size_x, size_y:]
flat_area_zero = np.flatnonzero(area == 0)
hits = flat_area_zero.shape[0]
if hits == 0:
# no room left
return None
goal = random_state.randint(0, hits)
flat_idx = flat_area_zero[goal]
w, h = integral_image.shape
row = flat_idx // w
col = flat_idx - row * w
return row, col The Cython code still is ~ 2.6 times faster than this. |
@thomasjpfan I kept getting an IndexError: flat_idx = flat_area_zero[goal] IndexError: index 635 is out of bounds for axis 0 with size 600 |
@thomasjpfan hm if there's now a way to do version-independent binary wheels maybe that's the better way forward? Also clearly your numpy skills are better than GPT4 ;) |
@amueller I tried using ABI3 with Although even with 3.11 as minimum version, Cython still uses non-stable CAPI calls. I suspect Cython's limited ABI support is not mature enough yet.
I cannot tell without running benchmarks to see how much slower |
It would be really nice to get rid of the Cython code. The equivalent in numpy is
however, that seems to be much slower.
Not sure if there's a faster way to do it. cc @thomasjpfan
The text was updated successfully, but these errors were encountered: