Repository navigation
Conversation
The per-frame cutoff was a Python loop, three np.quantile calls a frame (9.3 ms per 200 frames of 1500 maxima, 80 % of it numpy's dispatch). It needs three order statistics, not a sort: csrc/cutoff.hpp finds them with nth_element, frames over threads, in 1.1 ms; a split frame's find_candidates goes from 32 to 17 ms. A lexsort over the block, which NOTES suggested, is slower than the loop (52 ms). The quantiles are now SMAP's (myquantilefast: the ceil(n p)-th smallest) instead of np.quantile's linear interpolation, which was only numpy's default. The cutoff rises slightly and 0.01-0.14 % of the candidates are dropped, those at the threshold; DynamicCutoff.__call__ matches SMAP's getdynamiccutoff bit for bit, and the kernel matches __call__. The four Fit plugins' versions are bumped for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
What
Detection's dynamic cutoff (median + factor × the 20–80 % slope of each frame's local maxima) is now computed in C++, and takes its quantiles the way SMAP does.
Speed. The cutoff was a Python loop with three
np.quantilecalls per frame.csrc/cutoff.hppnow finds the three order statistics withnth_element, with frames split over threads (_fit3d.segment_cutoffs, called fromDynamicCutoff.thresholds):find_candidates, 200 pxfind_candidates, 200 px, split frameThe lexsort that NOTES.md suggested turns out to be slower than the loop (52 ms), and NOTES.md now says so.
SMAP's quantiles. A quantile is now the ⌈n·p⌉-th smallest maximum (SMAP's
myquantilefast), and the slope is divided by0.8 - 0.2, as in SMAP'sgetdynamiccutoff. smappy usednp.quantile's linear interpolation before, which is numpy's default; nothing records choosing it.Effect on results
Measured on 2000 simulated frames at 200 px and 64 px, with and without a split:
Checks
DynamicCutoff.__call__matches a line-by-line transcription of SMAP'sgetdynamiccutoffbit for bit (5,000 random frames).__call__bit for bit (55,196 segments: several factors, one or many threads, ties, negative values, frames with fewer than 10 maxima). The final multiply-add is kept from being fused into an FMA. Clang fuses by default, and that moved a threshold by one ulp during development.tests/test_detect_roi.py:find_candidateskeeps exactly what the per-frame loop keeps, with and without a split.pytest tests --slow -n auto: 1371 passed, 5 skipped (no GPU, Piper, calibration data or uiPSF on this machine).ci/smoke.pypasses.Not in this PR
The fit plugin's single-frame preview reports its cutoff from the top 1 % of all pixels in the filtered frame (
plugins/fit.py,preview), not from the local maxima that detection uses. The reported number is far off the real one: 322 against 8.23 on thetest_preview.pyfixture. The candidates it draws are correct. This will be a separate fix.🤖 Generated with Claude Code