perf(numba): one-bincount label prep for colocalization#61
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #60. Coloc-only perf refinement — does NOT touch the intensity backend.
labels_to_offsetsderives(lut, n, offsets)from a singlenp.bincountover the raster, replacingscipy.find_objects+ the grouped flatten's separate count scan;flatten_pairs_groupedbecomes 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_offsetsvslabel_to_idx_lut, incl. sparse labels). Full suite 114 green, lint clean.