perf(base): speed up isR/ishom/ishom2 orthogonality checks - #213
Open
petercorke wants to merge 1 commit into
Open
perf(base): speed up isR/ishom/ishom2 orthogonality checks#213petercorke wants to merge 1 commit into
petercorke wants to merge 1 commit into
Conversation
np.linalg.det/norm and np.eye carry large dispatch overhead relative to the actual work for 2x2/3x3 matrices, dominating SE3/SO3 constructor cost when check=True. Replace with explicit cofactor- expansion determinants and a squared Frobenius residual for the 2x2 and 3x3 cases (falling back to the generic path otherwise), and replace the bottom-row `all(... == np.array(...))` checks in ishom/ishom2 with direct scalar comparisons. ~2x faster isR, ~30-40% faster SE3(T, check=True) construction. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 21, 2026
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.
Summary
isR(SO(2)/SO(3) orthogonality test used bySE3/SO3/SE2/SO2construction withcheck=True) previously went throughnp.linalg.det/np.linalg.norm/np.eye, whose generic dispatch overhead dominates cost for such small (2x2/3x3) matrices. Added explicit fast paths for the 3x3 and 2x2 cases using a hand-written cofactor-expansion determinant and a squared-residual orthogonality check, falling back to the original generic implementation for any other size.ishom/ishom2bottom-row validity checks replacedall(T[-1,:] == np.array([...]))(array allocation + Python-levelall()over a NumPy bool array) with direct scalar comparisons.isRis roughly 2x faster standalone, andSE3(T, check=True)construction is roughly 30-40% faster end to end.Test plan
pytest tests/— 343 passeddtype=object) matrices withcheck=Trueis unchanged (was already unsupported before this change, for unrelated reasons -np.linalg.det/normdon't supportdtype=objecteither)🤖 Generated with Claude Code