Mark curation points with a single vstack instead of a loop#623
Open
aymuos15 wants to merge 1 commit into
Open
Mark curation points with a single vstack instead of a loop#623aymuos15 wants to merge 1 commit into
aymuos15 wants to merge 1 commit into
Conversation
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.
Description
What is this PR — [x] Bug fix
CurationWidget.mark_point_as_typeappended selected points one at a time, reassigning thePoints.dataproperty inside a loop overselected_data. Each assignment re-validates the whole array and emits change events, so marking N points is O(N²).This PR indexes all selected rows at once and does a single
vstack/.dataassignment. Same rows in the same order.Benchmark
Time — old loop vs. single vstack against a real
napari.layers.Pointslayer (destination layer = 500 points):Peak memory — numpy allocations (
tracemalloc). The single version also lowers peak memory ~2×, because the loop rebuilds the whole growing destination each iteration (holding two copies at its peak) while the single vstack touches it once:System: Intel i7-12800H (20 threads), 30 GiB RAM, Ubuntu 22.04 (kernel 6.8.0-111), Python 3.11.15, numpy 2.4.2, napari 0.6.6.
How has this PR been tested?
KERAS_BACKEND=torch pytest tests/napari/test_curation.pypasses (existing tests covermark_point_as_type; behaviour unchanged). Benchmark outputs verified identical (same shape and values).Is this a breaking change?
No.
Checklist
test_curation.py