Repository navigation
Conversation
Use one aminmax() pass for the [0, 1] range check of non-empty float images instead of separate min() and max() passes. Other inputs and failing images still go through the original assert, so error messages and NaN rejection are unchanged. The range check alone is about 2.2x faster (28 us saved per 256x256 image, about 0.7 ms at 1080p). Model time dominates for real matchers. Co-Authored-By: Aiden <aiden@weco.ai>
Owner
|
Closing: an overall speedup of less than 1% doesn't justify the extra code |
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
to_tensor_imageinvismatch/utils.pyfaster.BaseMatcher.forwardcalls it for each image.aminmax()pass instead of separatemin()andmax()passes.forwardcalls with the stub matcher fromtest_forward_matcher_confidences(no model): 65.3 ms -> 37.9 ms.pytest tests/test_import_sandbox.py vismatch_test.py tests/test_matchers.py tests/test_viz.py: no new failures.What & Why
Before, the
[0, 1]range check read the full image twice. It used one pass forimg.min()and one pass forimg.max(). Then it compared the two 0-dim tensors with Python floats.Now, for non-empty float images, the code gets the min and the max in one
aminmax()pass. It converts both to Python floats and compares them. If the check passes, the function returns the image.If the check fails, or the image is not a float image, the code runs the original
assertline. So error messages, NaN rejection and results for other dtypes stay the same. The function returns the same tensor object as before.For real matchers the model time dominates. So the gain matters most for large images and cheap matchers.
Results
Time per
to_tensor_imagecall, one CPU thread, best of 7 runs:Why this is safe and easy to maintain
The change adds four lines and keeps the original check as the fallback. Output is unchanged for valid images. Invalid images still raise the same
AssertionErrortext.tests/test_matchers.pycoversforward, and these tests pass.Validation
tests/test_matchers.py::test_forward_matcher_confidences[None-None](120forwardcalls, stub matcher with no model): 65.3 ms -> 37.9 ms (median ratio 0.58, measured 3 times).pytest tests/test_import_sandbox.py vismatch_test.py tests/test_matchers.py tests/test_viz.py: 53 passed, 276 skipped, 4 failed. The 4tests/test_viz.pyfailures areModuleNotFoundError: No module named 'lightglue'(submodule not checked out). They fail the same way without this change.AI assistance
Codex (gpt-6.1-sol) generated the code change as candidates. Weco Observe tracked them and an automated benchmark harness scored them. A Claude agent picked the smallest and most readable candidate.
Weco share link: https://dashboard.weco.ai/share/OGv03jR2EH1TQkjrBSCm189ldvIhMwJW