Repository navigation
Commit 2829ced
perf(base): speed up isR/ishom/ishom2 orthogonality checks (#213)
## Summary
- `isR` (SO(2)/SO(3) orthogonality test used by `SE3`/`SO3`/`SE2`/`SO2`
construction with `check=True`) previously went through
`np.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`/`ishom2` bottom-row validity checks replaced `all(T[-1,:] ==
np.array([...]))` (array allocation + Python-level `all()` over a NumPy
bool array) with direct scalar comparisons.
- Net effect: `isR` is roughly 2x faster standalone, and `SE3(T,
check=True)` construction is roughly 30-40% faster end to end.
## Test plan
- [x] `pytest tests/` — 343 passed
- [x] Verified pre-existing behaviour for symbolic (SymPy
`dtype=object`) matrices with `check=True` is unchanged (was already
unsupported before this change, for unrelated reasons -
`np.linalg.det`/`norm` don't support `dtype=object` either)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 8455bd9 commit 2829ced
3 files changed
Lines changed: 41 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
395 | 401 | | |
396 | 402 | | |
397 | 403 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
385 | 409 | | |
386 | 410 | | |
387 | 411 | | |
| |||
0 commit comments