linalg: add matrix_rank, cond, and polar decomposition - #258
Closed
axiom-of-choice wants to merge 1 commit into
Closed
linalg: add matrix_rank, cond, and polar decomposition#258axiom-of-choice wants to merge 1 commit into
axiom-of-choice wants to merge 1 commit into
Conversation
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
force-pushed
the
feat/matrix-rank-cond
branch
from
August 31, 2026 20:44
4d9a318 to
6a6e9e6
Compare
Contributor
Author
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.
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 abovetol. Default follows numpy:max(m, n) * eps(fp32) * sigma_max.cond(A)— 2-norm condition numbersigma_max / sigma_min. Returnsinffor singular matrices. Works for rectangular A.polar(A)— polar decompositionA = U @ Pvia randomized SVD. U has orthonormal columns, P is symmetric positive-semidefinite. Oracle:scipy.linalg.polar.Checks
ruff check— cleanpylint 2-space— 10.00/10pyright— 0 errorscompileall— cleanpytest -m "not requires_ane"— all pass (off-device)Notes
condreturnsinfwhen the condition number exceeds ~1e2 (sigma_min underflows to 0 in fp16). Tests use cond ≤ 5 for oracle comparisons.polaruses randomized SVD (not full SVD), so P has ~1e-4 asymmetry from the approximation. Symmetrized in the implementation.