Repository navigation
Conversation
Compute the three trimer edge distances together and reuse the squared-distance array. Preserve edge order and coordinate arithmetic. Co-Authored-By: Aiden <aiden@weco.ai>
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.
TL;DR
_trimer_funduring constrained particle refinement.Refs #814
What & Why
The old code divided, squared, and summed each edge separately. The new code builds one array and runs those operations together.
It keeps the same edge order and arithmetic for every coordinate. This reduces repeated NumPy calls while keeping the fitted results identical.
Validation
Measurements used Python 3.12.13, NumPy 1.26.4, SciPy 1.14.1, and pandas 2.2.3 on Linux, with numerical libraries limited to one thread.
The 2D refinement results use 27 measurements of each version across three runs. The additional cases use median pytest durations from five runs per version, alternating versions on the same isolated CPU. Those native test durations include image preparation and assertions. Dimers do not call the changed function.
Statistics for the 2D trimer refinement are:
The elapsed-time medians and median time ratio are calculated separately, so their percentages differ slightly.
Run the representative native benchmarks on each version:
Full native validation command:
Additional comparisons checked 144 combinations of cluster count, dimensions, distance values, numeric types, and reversed arrays. All values, shapes, and types matched exactly, and inputs stayed unchanged. Complete fitting outputs also matched exactly in all three performance runs.
Why this is safe and easy to maintain
The change stays within one small function and uses one shared distance formula. It preserves coordinate arithmetic and the output order. Existing constrained-refinement tests cover 2D and 3D clusters, including anisotropic images.
AI assistance
This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.
Weco share link: https://dashboard.weco.ai/share/Jb_NT8gNgQk1Pm-gQqVvtzJJ3sj20fOy