-
Notifications
You must be signed in to change notification settings - Fork 68
Description
Is your feature request related to a problem? Please describe.
bin_mean_3d currently builds sub-stacks in Python and calls binned_mean_2d
repeatedly. This introduces Python-loop overhead and slows down kernel
generation (used by ball filtering) for large inputs.
Describe the solution you'd like
Replace the nested loops with a vectorized reshape + mean:
arr.reshape(w//bw, bw, h//bh, bh, d//bd, bd).mean(axis=(1,3,5))
This computes all bin means in a single NumPy operation.
Describe alternatives you've considered
Leaving the loops as-is, or using numba/Cython. Vectorized NumPy is simpler and
keeps dependencies unchanged.
Additional context
The function lives in cellfinder/core/tools/array_operations.py and is used
to build the ball kernel in cellfinder/core/detect/filters/volume/ball_filter.py.