Skip to content

Add Tier-1 linear-algebra APIs: inv, lstsq, norm (v0.7.0) - #6

Merged
Efithor merged 1 commit into
mainfrom
feat/tier1-inv-lstsq-norm
Jun 23, 2026
Merged

Add Tier-1 linear-algebra APIs: inv, lstsq, norm (v0.7.0)#6
Efithor merged 1 commit into
mainfrom
feat/tier1-inv-lstsq-norm

Conversation

@Efithor

@Efithor Efithor commented Jun 23, 2026

Copy link
Copy Markdown
Owner

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-refinement solve(A, I).
  • lstsq(A, b) — least squares for full-rank overdetermined/square A, using a
    one-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 FP64
    reductions; the matrix spectral norm (ord=2) uses sqrt(lambda_max(A^T A)) from the
    accurate Gram matrix.

Validation

CPU (benchmarks/ci_tier1_validate.py) and on-device TPU v6e (v6e-1):

  • inv: 8.3e-15
  • lstsq: 1.4e-14 (refinement 3.4e-6 -> 1.4e-14)
  • standard / spectral norms: ~1e-15
  • existing ci_cpu / ci_gram / ci_solve suites: no regressions

Known limitation

A general p-norm (p not in {1, 2, inf}) is computed as (sum |x|^p)^(1/p); on TPU the
x**p / **(1/p) transcendentals run at ~fp32 precision under emulated fp64 (~1e-8).
Standard orders are unaffected. Documented in norm() and the README.

- 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
@Efithor
Efithor merged commit c69fdd2 into main Jun 23, 2026
1 check passed
@Efithor
Efithor deleted the feat/tier1-inv-lstsq-norm branch June 23, 2026 19:33
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.

1 participant