Skip to content

perf(numba): one-bincount label prep for colocalization#61

Merged
timtreis merged 1 commit into
feat/numba-colocfrom
feat/numba-coloc-bincount
Jun 3, 2026
Merged

perf(numba): one-bincount label prep for colocalization#61
timtreis merged 1 commit into
feat/numba-colocfrom
feat/numba-coloc-bincount

Conversation

@timtreis

@timtreis timtreis commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #60. Coloc-only perf refinement — does NOT touch the intensity backend.

labels_to_offsets derives (lut, n, offsets) from a single np.bincount over the raster, replacing scipy.find_objects + the grouped flatten's separate count scan; flatten_pairs_grouped becomes a single scatter scan. Cuts the per-call prep shared by all four features from 3 full-image passes to 2 (~6.2→3.1 ms), bit-identical lut/offsets/values.

Speedups (1080², 144 obj, float): pearson 18.7→31.6×, manders 36.4→62.0×, overlap 39.8→67.7×; rwc 5.3→5.6× (sort-bound — its per-object argsort dominates and is intrinsic to the rank metric; 3 exact alternatives measured slower or no-op).

Exactness held (golden tests rtol 1e-6) and bzyx unchanged. +1 test (labels_to_offsets vs label_to_idx_lut, incl. sparse labels). Full suite 114 green, lint clean.

…oor)

labels_to_offsets() derives (lut, n, offsets) from a single np.bincount over the
raster, replacing scipy find_objects + the grouped flatten's separate count scan.
flatten_pairs_grouped now takes the precomputed offsets and does a single scatter
scan. Cuts the per-call prep shared by all four features from 3 full-image passes
to 2 (~6.2ms -> ~3.1ms here), bit-identical lut/offsets/values.

Speedups (1080^2, 144 obj, float): pearson 18.7->31.6x, manders 36.4->62.0x,
overlap 39.8->67.7x; rwc 5.3->5.6x (its per-object argsort dominates and is
intrinsic to the rank metric — a global lexsort alternative measured 2.3x slower).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@timtreis timtreis merged commit a953594 into feat/numba-coloc Jun 3, 2026
@timtreis timtreis deleted the feat/numba-coloc-bincount branch June 3, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant