Commit af473db
perf(base): speed up trnorm and tr2adjoint
Both functions built small, fixed-size (3x3/4x4/6x6) results out of
generic NumPy helpers (np.cross/unitvec/np.stack in trnorm, np.block
in tr2adjoint) whose dispatch overhead - built for arbitrary shapes
and broadcasting - dominates cost at this size. Same pattern as the
isR/ishom speedup in #213. Replaced with explicit scalar arithmetic
(trnorm) and direct pre-allocated slice-assignment (tr2adjoint),
dtype preserved via np.zeros(..., dtype=T.dtype) so tr2adjoint's
documented SymPy support is unaffected.
~12x faster trnorm, ~2.7x faster tr2adjoint standalone. End to end:
SE3 @ SE3 (which normalizes via trnorm) drops from ~30us to ~4us.
Verified bit-for-bit numeric equivalence against the prior
implementation over 200 random SO(3)/SE(3) trials, plus symbolic
(SymPy dtype=object) equivalence for tr2adjoint.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent fff7009 commit af473db
1 file changed
Lines changed: 36 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1591 | 1591 | | |
1592 | 1592 | | |
1593 | 1593 | | |
1594 | | - | |
1595 | | - | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
1596 | 1599 | | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
1600 | 1604 | | |
1601 | | - | |
1602 | | - | |
1603 | | - | |
1604 | | - | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
1605 | 1624 | | |
1606 | 1625 | | |
1607 | 1626 | | |
| |||
2718 | 2737 | | |
2719 | 2738 | | |
2720 | 2739 | | |
2721 | | - | |
2722 | 2740 | | |
2723 | 2741 | | |
2724 | 2742 | | |
2725 | 2743 | | |
2726 | 2744 | | |
2727 | 2745 | | |
2728 | 2746 | | |
2729 | | - | |
2730 | | - | |
2731 | | - | |
2732 | | - | |
2733 | | - | |
2734 | | - | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
2735 | 2755 | | |
2736 | 2756 | | |
2737 | 2757 | | |
| |||
0 commit comments