Skip to content

Latest commit

 

History

History
151 lines (113 loc) · 5.53 KB

File metadata and controls

151 lines (113 loc) · 5.53 KB

Decompositions Module

Linear algebra decompositions for both fixed-size and dynamic-size matrices.

Fixed-Size Decompositions

LU Decomposition

LU(T, n) — LU factorization with partial pivoting.

const lu = try Zigen.LU(f64, 3).compute(A);

lu.L                        // Lower triangular
lu.U                        // Upper triangular
lu.P                        // Permutation matrix
lu.determinant()            // det(A)
lu.solve(b)                 // Solve Ax = b

QR Decomposition

QR(T, rows, cols) — Householder QR.

const qr = Zigen.QR(f64, 3, 3).compute(A);

qr.Q                        // Orthogonal matrix
qr.R                        // Upper triangular
qr.solve(b)                 // Solve via QR

Cholesky Decomposition

Cholesky(T, n) — LLᵀ for symmetric positive definite matrices.

const chol = try Zigen.Cholesky(f64, 3).compute(A);

chol.L                       // Lower Cholesky factor
chol.solve(b)                // Solve Ax = b

SVD

SVD(T, rows, cols) — Singular Value Decomposition.

const svd = Zigen.SVD(f64, 3, 3).compute(A);

svd.U                        // Left singular vectors
svd.S                        // Singular values (vector)
svd.V                        // Right singular vectors

Other Fixed-Size

Type Description
LDLT(T, n) LDLᵀ for symmetric matrices
FullPivLU(T, rows, cols) Full-pivoting LU
JacobiSVD(T, rows, cols) Jacobi SVD
BDCSVD(T, rows, cols) Bidiagonal Divide & Conquer SVD
ColPivHouseholderQR(T, rows, cols) Column-pivoting QR
CompleteOrthogonalDecomp(T, rows, cols) Rank-revealing decomposition
SelfAdjointEigenSolver(T, n) Symmetric eigenvalue solver
EigenSolver(T, n) Non-symmetric eigenvalue solver
GeneralizedEigenSolver(T, n) Generalized eigenvalue solver
Tridiagonalization(T, n) Tridiagonal reduction
HessenbergDecomp(T, n) Upper Hessenberg form
RealSchur(T, n) Real Schur decomposition
RealQZ(T, n) Generalized Schur (QZ)
ComplexSchur(T, n) Complex Schur decomposition

Dynamic-Size Decompositions

All dynamic decompositions support two usage patterns:

Pattern 1: One-Shot (Allocating)

var lu = try Zigen.LUDynamic(f64).compute(allocator, A);
defer lu.deinit();
var x = try lu.solve(b);
defer x.deinit();

Pattern 2: Workspace Reuse (Zero-Allocation)

// Allocate once
var lu = try Zigen.LUDynamic(f64).init(allocator, n);
defer lu.deinit();

// Reuse many times — zero allocation in the loop
for (matrices) |A| {
    lu.computeFrom(A);                    // Reuse workspace
    lu.solveInto(b, x_buf, pb_buf, y_buf); // Write into buffers
}

LUDynamic(T)

Method Description
compute(allocator, A) One-shot decompose (allocating)
init(allocator, n) Allocate workspace
computeFrom(A) Decompose into existing workspace
solve(b) Solve, returning new vector
solveInto(b, x_buf, pb_buf, y_buf) Solve into pre-allocated buffers
inverse() Compute inverse (allocating)
inverseInto(result, e_buf, x_buf, pb_buf, y_buf) Inverse into buffers
determinant() Compute determinant

CholeskyDynamic(T)

Method Description
compute(allocator, A) One-shot (allocating)
init(allocator, n) Allocate workspace
computeFrom(A) Decompose into workspace
solve(b) Solve (allocating)
solveInto(b, x_buf, y_buf) Solve into buffers

QRDynamic(T)

Method Description
compute(allocator, A) One-shot (allocating)
init(allocator, m, n) Allocate workspace
computeFrom(A) Decompose into workspace
solve(b) Solve (allocating)
solveInto(b, x_buf, qtb_buf) Solve into buffers

SVDDynamic(T)

Method Description
compute(allocator, A) One-shot (allocating)
init(allocator, m, n) Allocate workspace
computeFrom(A) Decompose into workspace

SelfAdjointEigenSolverDynamic(T)

Method Description
compute(allocator, A) One-shot (allocating)
init(allocator, n) Allocate workspace
computeFrom(A) Decompose into workspace