Skip to content

[Optimsation] Vectorised binning #584

@HARSHDIPSAHA

Description

@HARSHDIPSAHA

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions