Skip to main content

Module linalg

Module linalg 

Source
Expand description

Small dense helpers on row-major f64 buffers.

Heavy products and symmetric eigendecompositions go through faer (Par::Seq). tang_la::gemm_* and tang_la::SymmetricEigen were the first choice; on the codec’s shapes (m ≈ 700, k ≈ 10⁴) the eigensolver took >95% of encode time and the GEMMs were the next bottleneck, so the hot paths moved to faer, which tang-la already bridges behind a feature. Truncated SVDs of the m × n TT unfoldings are computed from the Gram matrix of the smaller side (min(m,n) ≤ 2·r_max), which is what makes TT-SVD of a 2^24-entry tensor cheap: one-sided Jacobi (tang_la::Svd) on a 2 × 2^23 unfolding would be far slower. The Gram route squares the condition number; in f64 that leaves singular values down to ~1e-7·σ₁ resolved, well below any truncation tolerance the codec uses (see the crate docs).

Functions§

cholesky
Lower Cholesky factor of SPD a (n×n), or None if not positive definite.
gram_cols
Aᵀ·A for row-major a (m × n).
gram_rows
A·Aᵀ for row-major a (m × n).
kron_eye_apply
(H ⊗ I_n)·X for H r×r and X (r·n)×p, row-major — computed as H · X' with X' the free r×(n·p) reshape, n× cheaper than the dense Kronecker product.
matmul
C = A·B (A: m×k, B: k×n), row-major.
matmul_tn
C = Aᵀ·B (A: k×m, B: k×n), row-major.
orthonormalize_cols
Modified Gram–Schmidt (two passes) on the columns of row-major m×k u.
solve_lower
Solve L·X = B in place (L lower n×n, B n×m row-major).
solve_lower_t
Solve Lᵀ·X = B in place (L lower n×n, B n×m row-major).
svd_left
Truncated SVD of a row-major m×n matrix via the Gram matrix of the smaller side. Returns all singular values (descending, length min(m,n)) and a closure-free pair: u (m × k, row-major) for the leading k columns requested by pick (which sees the singular values).
sym_eig_desc
Eigenpairs of a symmetric matrix, descending: (values, vectors as row-major n×n with eigenvector j in column j).
transpose
Transpose a row-major m×n matrix.