Add Tier-1 linear-algebra APIs: inv, lstsq, norm (v0.7.0) - #6
Merged
Conversation
- inv(A): matrix inverse via iterative-refinement solve(A, I) - lstsq(A, b): least squares via FP32 QR + augmented-system (Bjorck) refinement - norm(x, ord): vector/matrix norms; spectral norm via accurate Gram matrix - Wire exports, bump version to 0.7.0, add benchmarks/ci_tier1_validate.py - Validated on TPU v6e (inv/lstsq/norms ~1e-15); documented general-p norm TPU pow precision (~fp32) and set CI threshold accordingly
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
Adds three composable linear-algebra routines on top of the accurate matmul/solve
core, completing the Tier-1 API surface and bumping the package to v0.7.0.
New APIs
inv(A)— matrix inverse via iterative-refinementsolve(A, I).lstsq(A, b)— least squares for full-rank overdetermined/squareA, using aone-time FP32 QR with augmented-system (Björck) iterative refinement. Refining the
residual alongside the solution reaches ~FP64 accuracy even when the least-squares
residual is large (plain residual refinement of the solution alone stalls near FP32 there).
norm(x, ord=...)— vector and matrix norms. Standard orders are exact FP64reductions; the matrix spectral norm (
ord=2) usessqrt(lambda_max(A^T A))from theaccurate Gram matrix.
Validation
CPU (
benchmarks/ci_tier1_validate.py) and on-device TPU v6e (v6e-1):inv: 8.3e-15lstsq: 1.4e-14 (refinement 3.4e-6 -> 1.4e-14)ci_cpu/ci_gram/ci_solvesuites: no regressionsKnown limitation
A general p-norm (p not in {1, 2, inf}) is computed as
(sum |x|^p)^(1/p); on TPU thex**p/**(1/p)transcendentals run at ~fp32 precision under emulated fp64 (~1e-8).Standard orders are unaffected. Documented in
norm()and the README.