Skip to content

linalg: add matrix_rank, cond, and polar decomposition - #258

Closed
axiom-of-choice wants to merge 1 commit into
sbryngelson:mainfrom
axiom-of-choice:feat/matrix-rank-cond
Closed

linalg: add matrix_rank, cond, and polar decomposition#258
axiom-of-choice wants to merge 1 commit into
sbryngelson:mainfrom
axiom-of-choice:feat/matrix-rank-cond

Conversation

@axiom-of-choice

Copy link
Copy Markdown
Contributor

Closes #125. Closes #168.

What

Three new functions in aneforge/linalg.py, all composed from the existing on-ANE SVD:

  • matrix_rank(A, tol=None) — numerical rank by counting singular values above tol. Default follows numpy: max(m, n) * eps(fp32) * sigma_max.
  • cond(A) — 2-norm condition number sigma_max / sigma_min. Returns inf for singular matrices. Works for rectangular A.
  • polar(A) — polar decomposition A = U @ P via randomized SVD. U has orthonormal columns, P is symmetric positive-semidefinite. Oracle: scipy.linalg.polar.

Checks

  • ruff check — clean
  • pylint 2-space — 10.00/10
  • pyright — 0 errors
  • compileall — clean
  • pytest -m "not requires_ane" — all pass (off-device)
  • On-device: 19 new tests pass on M2 Pro / macOS 26.5.2

Notes

  • fp16 SVD floor: cond returns inf when the condition number exceeds ~1e2 (sigma_min underflows to 0 in fp16). Tests use cond ≤ 5 for oracle comparisons.
  • polar uses randomized SVD (not full SVD), so P has ~1e-4 asymmetry from the approximation. Symmetrized in the implementation.

matrix_rank(A, tol=None): count of singular values above tol,
default max(m,n) * eps * sigma_max (numpy convention).

cond(A): 2-norm condition number sigma_max / sigma_min via SVD.
Returns inf for singular matrices. Works for rectangular A.

Closes sbryngelson#125.
@axiom-of-choice

Copy link
Copy Markdown
Contributor Author

Superseded by #259 (polar) and the updated branch for #125 (matrix_rank + cond). Split into separate PRs per issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linalg: polar decomposition (A = U P via the existing SVD) linalg: matrix_rank and cond

1 participant