Linear Algebra (122)

Operates on DenseMatrix (and SparseMatrix where applicable). Heavy operations are eligible for WASM/GPU acceleration via the matrix package.

bicgstab
General nonsymmetric
Syntax
bicgstab(A, b[, opts])
blockDiag
Block-diagonal matrix from possibly rectangular blocks
Syntax
blockDiag(...blocks)
care
Continuous algebraic Riccati equation, for LQR design (see below)
Syntax
care(A, B, Q, R)
cg
Symmetric positive-definite
Syntax
cg(A, b[, opts])
characteristicPolynomial
Characteristic polynomial
Syntax
characteristicPolynomial(A)
cholesky
Cholesky decomposition
Syntax
cholesky(A)
choleskyDowndate
Rank-1 update / downdate of a lower Cholesky factor: factor of L·Lᵀ + x·xᵀ / L·Lᵀ − x·xᵀ; downdate throws RangeError if the result is not positive definite
Syntax
choleskyDowndate(L, x)
Typesnumber[][], number[]
choleskyUpdate
Rank-1 update / downdate of a lower Cholesky factor: factor of L·Lᵀ + x·xᵀ / L·Lᵀ − x·xᵀ; downdate throws RangeError if the result is not positive definite
Syntax
choleskyUpdate(L, x)
Typesnumber[][], number[]
circulant
Circulant matrix; each row is the previous one rotated right by one (connects to the FFT)
Syntax
circulant(c)
companion
Companion matrix of the polynomial [a₀, …, aₙ] (highest degree first, numpy np.companion convention); its eigenvalues are the polynomial's roots
Syntax
companion(coeffs)
cond
Condition number (SVD ratio, JS)
Syntax
cond(A)
condest
Hager/Higham estimate of the 1-norm condition number ‖A‖₁·‖A⁻¹‖₁ without forming A⁻¹ (a close lower bound; exact cond uses a full SVD); square input, only p = 1 is implemented
Syntax
condest(A[, p])
TypesDenseMatrix
cosm
Matrix cosine cos(A) via funm, valid for any real spectrum (unlike matrixSqrtm/matrixLogm, which require positive/real spectra)
Syntax
cosm(A)
cross
Vector cross product
Syntax
cross(a, b)
csAmd
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csAmd(…)
csChol
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csChol(…)
csCounts
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csCounts(…)
csLu
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csLu(…)
csSpsolve
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csSpsolve(…)
csSqr
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csSqr(…)
csSymperm
csChol, csLu, csSpsolve, csSqr, csCounts, csSymperm, csAmd.
Syntax
csSymperm(…)
ctranspose
Conjugate (Hermitian) transpose
Syntax
ctranspose(A)
dare
Discrete algebraic Riccati equation, for LQR design (see below)
Syntax
dare(A, B, Q, R)
det
Determinant
Syntax
det(A)
dftMatrix
DFT matrix F_jk = exp(−2πi·jk/n) as Complex[][], scale 'none' (default), 'sqrtn' (unitary) or 'n'
Syntax
dftMatrix(n[, { scale }])
diag
Diagonal matrix or diagonal extraction
Syntax
diag(v)
disableGpu
Opting in is required because the GPU computes in 32-bit float (WGSL has no f64); silently routing an f64 API onto the GPU would change precision without the caller asking. enableGpu() / disableGpu() / isGpuEnabled() control it.
Syntax
disableGpu(…)
dlyap
Discrete Lyapunov A X Aᵀ − X + Q = 0 (see below)
Syntax
dlyap(A, Q)
eigs
Eigenvalues and eigenvectors
Syntax
eigs(A)
eigsh
Iterative Lanczos eigensolver — k largest/smallest eigenpairs of a symmetric A (see below)
Syntax
eigsh(A, k[, opts])
eigvals
Eigenvalues only, as { re, im } pairs (skips the eigenvector computation)
Syntax
eigvals(A[, opts])
Typesnumber[][]
elementwiseChainGpuDispatch
> WebGPU coverage at the typed-dispatch layer is deliberately SMALL — 2 of 219. The > generated report webgpu-pairing.md (not committed; bun run docs:deps writes it) lists 9 standalone > functions that route to the GPU (fuseUnaryChainAsync, fuseUnaryChainReduceAsync, > elementwiseChainGpuDispatch,…
Syntax
elementwiseChainGpuDispatch(…)
elementwiseChainReduceGpuDispatch
> WebGPU coverage at the typed-dispatch layer is deliberately SMALL — 2 of 219. The > generated report webgpu-pairing.md (not committed; bun run docs:deps writes it) lists 9 standalone > functions that route to the GPU (fuseUnaryChainAsync, fuseUnaryChainReduceAsync, > elementwiseChainGpuDispatch,…
Syntax
elementwiseChainReduceGpuDispatch(…)
enableGpu
parallel — ComputePool may dispatch to worker threads when the typed path passes an op name and length meets that op's DEFAULT_THRESHOLD_BY_OP entry (for example matmul at 4,096 via poolOptions(..., 'matmul')). When the path calls shouldParallelize(n) without an op name, only the…
Syntax
enableGpu(…)
expm
Matrix exponential
Syntax
expm(A)
fftGpuDispatch
parallel — ComputePool may dispatch to worker threads when the typed path passes an op name and length meets that op's DEFAULT_THRESHOLD_BY_OP entry (for example matmul at 4,096 via poolOptions(..., 'matmul')). When the path calls shouldParallelize(n) without an op name, only the…
Syntax
fftGpuDispatch(…)
fiedlerMatrix
Fiedler matrix F_ij = |a_i − a_j|
Syntax
fiedlerMatrix(a)
fractionalMatrixPower
A^t = expm(t·logm(A)) for real t (principal logarithm required); integer t is exact repeated multiplication
Syntax
fractionalMatrixPower(A, t)
Typesnumber[][]
funm
General matrix function f(A) returning a complex-valued matrix { re, im } — diagonal fast path, Lagrange-Sylvester interpolation for distinct eigenvalues, and confluent Hermite interpolation (Newton divided differences over repeated nodes) for defective/repeated-eigenvalue matrices. Defective matrices need derivatives of f: supply them analytically via optional fDerivs (fDerivs[k] = f^(k+1), machine precision) or they are approximated numerically (~1e-6). Throws only when f/a derivative is singular at a repeated eigenvalue (e.g. sqrt/log at 0)
Syntax
funm(A, f, fDerivs?)
fuseUnaryChainAsync
parallel — ComputePool may dispatch to worker threads when the typed path passes an op name and length meets that op's DEFAULT_THRESHOLD_BY_OP entry (for example matmul at 4,096 via poolOptions(..., 'matmul')). When the path calls shouldParallelize(n) without an op name, only the…
Syntax
fuseUnaryChainAsync(…)
fuseUnaryChainReduceAsync
parallel — ComputePool may dispatch to worker threads when the typed path passes an op name and length meets that op's DEFAULT_THRESHOLD_BY_OP entry (for example matmul at 4,096 via poolOptions(..., 'matmul')). When the path calls shouldParallelize(n) without an op name, only the…
Syntax
fuseUnaryChainReduceAsync(…)
generalizedEig
Generalized eigenvalues of the pencil A x = λ B x (B nonsingular) via the eigendecomposition of B⁻¹A; eigenvalues match scipy.linalg.eig(A, B)
Syntax
generalizedEig(A, B)
gmres
General nonsymmetric (restarted)
Syntax
gmres(A, b[, opts])
gpuAdd
Matrix addition
Syntax
gpuAdd(a, b)
AccelWebGPU
gpuMatmul
Matrix multiplication
Syntax
gpuMatmul(a, b)
AccelWebGPU
gpuScale
Scalar multiplication
Syntax
gpuScale(a, s)
AccelWebGPU
gpuTranspose
Matrix transpose
Syntax
gpuTranspose(a)
AccelWebGPU
hadamardMatrix
Sylvester Hadamard matrix of ±1 entries; n must be a power of 2 (H·Hᵀ = n·I), else RangeError
Syntax
hadamardMatrix(n)
hankelMatrix
Hankel matrix with first column c and optional last row r (r[0] ignored; default zeros)
Syntax
hankelMatrix(c[, r])
helmertMatrix
Helmert matrix: the (n−1) × n orthonormal contrast rows, or the full n × n orthogonal matrix (first row 1/√n) when full is true
Syntax
helmertMatrix(n[, full])
hessenbergForm
Hessenberg reduction
Syntax
hessenbergForm(A)
hilbertMatrix
Hilbert matrix 1/(i+j+1) and its inverse from the exact integer closed form
Syntax
hilbertMatrix(n)
incompleteCholesky
Listed in the export index; see the source for details.
Syntax
incompleteCholesky(…)
incompleteLU
Listed in the export index; see the source for details.
Syntax
incompleteLU(…)
inv
Matrix inverse
Syntax
inv(A)
invHilbertMatrix
Hilbert matrix 1/(i+j+1) and its inverse from the exact integer closed form
Syntax
invHilbertMatrix(n)
isGpuEnabled
Opting in is required because the GPU computes in 32-bit float (WGSL has no f64); silently routing an f64 API onto the GPU would change precision without the caller asking. enableGpu() / disableGpu() / isGpuEnabled() control it.
Syntax
isGpuEnabled(…)
jordanForm
Jordan normal form
Syntax
jordanForm(A)
khatriRao
Column-wise Kronecker (Khatri–Rao) product; both inputs need the same column count
Syntax
khatriRao(A, B)
kron
Kronecker product
Syntax
kron(A, B)
laplacianMatrix
Graph Laplacian of an adjacency matrix; combinatorial L = D − A by default, or the symmetric normalized L_sym = I − D^(−1/2) A D^(−1/2) with { normalized: true }
Syntax
laplacianMatrix(adjacency[, opts])
ldl
Symmetric indefinite A — Bunch–Kaufman-pivoted LDLᵀ
Syntax
ldl(A)
leslieMatrix
Leslie population matrix: fecundities f in the first row, survival rates s on the subdiagonal (s.length = f.length − 1)
Syntax
leslieMatrix(f, s)
linsolve
Solve a linear system Ax = b
Syntax
linsolve(A, b)
logdet
Natural log of the absolute determinant via LU (the logabsdet part of numpy slogdet), stable where log(det(A)) overflows; returns { sign, value } with det = sign · exp(value)
Syntax
logdet(A)
lowRankApprox
Best rank-k approximation in the Frobenius-norm sense via truncated SVD: A_k = U[:, :k] · diag(S[:k]) · V[:, :k]ᵀ
Syntax
lowRankApprox(A, k)
lq
QR-family variants built from reduced QR: A = L·Q (L lower, Q has orthonormal rows), A = R·Q (R upper, orthonormal rows), A = Q·L (orthonormal columns, L lower)
Syntax
lq(A)
TypesDenseMatrix
lsolve
Forward substitution (lower-triangular)
Syntax
lsolve(A, b)
lsolveAll
Forward substitution (lower-triangular)
Syntax
lsolveAll(A, b)
lup
LU decomposition with partial pivoting
Syntax
lup(A)
lusolve
Solve Ax = b via LU
Syntax
lusolve(A, b)
lyap
Solve the Lyapunov equation
Syntax
lyap(A, Q)
matrixExpm
Matrix exponential via Padé-13 scaling-and-squaring (Higham 2005)
Syntax
matrixExpm(A)
matrixLog
Matrix logarithm
Syntax
matrixLog(A)
matrixLogm
Principal matrix logarithm via inverse scaling-and-squaring with Gauss–Legendre quadrature; throws for non-positive real eigenvalues; a complex-conjugate pair gives the real logarithm
Syntax
matrixLogm(A)
matrixPinv
Moore–Penrose pseudoinverse via SVD with rcond·max(S) thresholding; the matrix package's routine under a non-colliding name (the typed pinv also accepts nested arrays)
Syntax
matrixPinv(A[, { rcond }])
TypesDenseMatrix
matrixRank
Rank
Syntax
matrixRank(A)
matrixSqrtm
Principal matrix square root via Newton iteration (eigendecomposition fallback); throws for negative/complex eigenvalues
Syntax
matrixSqrtm(A)
minres
Symmetric, possibly indefinite
Syntax
minres(A, b[, opts])
norm2
Spectral norm (2-norm) of a matrix — the largest singular value
Syntax
norm2(A)
normFro
Frobenius norm of a matrix — sqrt(sum(A_ij²))
Syntax
normFro(A)
orth
Orthonormal basis for the column space of A — the leading columns of svd(A).U above a rank tolerance (default max(m, n) · S[0] · 2.22e-16)
Syntax
orth(A[, opts])
parallelFFT
FFT → { real, imag, originalLength }
Syntax
parallelFFT(x)
Accelparallel†, GPU‡
parallelIFFT
Inverse FFT → { real, imag }
Syntax
parallelIFFT(X)
Accelparallel†, GPU‡
pascalMatrix
Pascal matrix, kind 'symmetric' (default), 'lower' or 'upper'; determinant 1
Syntax
pascalMatrix(n[, kind])
pinv
Moore–Penrose pseudoinverse
Syntax
pinv(A)
polarDecomposition
Polar decomposition
Syntax
polarDecomposition(A)
powerIteration
Dominant eigenpair { value, vector } (defaults 1000 iterations, 1e-12)
Syntax
powerIteration(A[, { maxIterations, tolerance }])
Typesnumber[][]
ql
QR-family variants built from reduced QR: A = L·Q (L lower, Q has orthonormal rows), A = R·Q (R upper, orthonormal rows), A = Q·L (orthonormal columns, L lower)
Syntax
ql(A)
TypesDenseMatrix
qr
QR decomposition
Syntax
qr(A)
qrPivoted
Column-pivoted rank-revealing QR: { Q, R, P, rank } with A[:, P] = Q·R; rank counts |R_ii| > tolerance·|R_00| (default 1e-10)
Syntax
qrPivoted(A[, { tolerance }])
TypesDenseMatrix
qz
Generalized (QZ) Schur decomposition of (A, B); returns orthogonal Q, Z and upper-(quasi-)triangular AA, BB with A = Q·AA·Zᵀ, B = Q·BB·Zᵀ (matches scipy.linalg.qz; factors not unique)
Syntax
qz(A, B)
rank
Numerical rank (Gaussian elimination, JS)
Syntax
rank(A)
rationalNullspace
Listed in the export index; see the source for details.
Syntax
rationalNullspace(…)
reduce
Reduce an expression
Syntax
reduce(expr)
resetGpuElementwise
Per-call override. enableGpu() is process-global state — any dependency could flip it. Pass { gpu: true | false } as the last argument — third for fuseUnaryChainAsync / elementwiseChainGpuDispatch, fourth for fuseUnaryChainReduceAsync / elementwiseChainReduceGpuDispatch (or to…
Syntax
resetGpuElementwise(…)
resetGpuFft
Also exported: resetGpuFft(), GpuFftOptions, GpuFftResult.
Syntax
resetGpuFft(…)
rotate
Rotate a vector
Syntax
rotate(v, angle[, axis])
rotationMatrix
Rotation matrix
Syntax
rotationMatrix(angle[, axis])
rowReduce
Reduced row echelon form
Syntax
rowReduce(A)
rq
QR-family variants built from reduced QR: A = L·Q (L lower, Q has orthonormal rows), A = R·Q (R upper, orthonormal rows), A = Q·L (orthonormal columns, L lower)
Syntax
rq(A)
TypesDenseMatrix
schur
Schur decomposition
Syntax
schur(A)
signm
Matrix sign function by determinant-scaled Newton iteration X ← (μX + (μX)⁻¹)/2
Syntax
signm(A[, { tol, maxIter }])
Typesnumber[][]
singularValues
Singular values in descending order (length min(m, n), all non-negative)
Syntax
singularValues(A)
sinm
Matrix sine sin(A) via funm, valid for any real spectrum
Syntax
sinm(A)
slu
Sparse LU decomposition
Syntax
slu(A)
solveBanded
Banded Ax = b (l lower / u upper diagonals) — band-limited Gaussian elimination
Syntax
solveBanded(l, u, A, b)
sqrtm
Matrix square root
Syntax
sqrtm(A)
subspaceAngles
Principal angles between the column spaces of A and B in radians, descending like scipy.linalg.subspace_angles; small angles keep full relative accuracy
Syntax
subspaceAngles(A, B)
Typesnumber[][]
svd
Full singular value decomposition — { U, S, V, rank }, S descending
Syntax
svd(A)
svds
svds(A, k = 1, opts?) — the k largest singular triplets of a dense m × n matrix A, for large/sparse problems where a full svd (which factors the whole matrix) is wasteful. It runs the Lanczos iteration on the smaller of the two normal operators (AᵀA when m ≥ n, else A Aᵀ) — never forming that…
Syntax
svds(…)
sylvester
Solve AX + XB = C
Syntax
sylvester(A, B, C)
thomasSolve
Tridiagonal Ax = d — the Thomas algorithm, O(n)
Syntax
thomasSolve(sub, diag, sup, d)
toeplitz
Toeplitz matrix with first column c and first row r (defaults to c); constant along each diagonal
Syntax
toeplitz(c[, r])
toeplitzSolve
Toeplitz Tx = b (first column c, first row r) — Levinson–Durbin, O(n²)
Syntax
toeplitzSolve(c, r, b)
trace
Trace (sum of the diagonal)
Syntax
trace(A)
transpose
Transpose
Syntax
transpose(A)
tril
Lower-triangular part of A, zeroing entries above the k-th diagonal (default k = 0)
Syntax
tril(A[, k])
triu
Upper-triangular part of A, zeroing entries below the k-th diagonal (default k = 0)
Syntax
triu(A[, k])
usolve
Back substitution (upper-triangular)
Syntax
usolve(A, b)
usolveAll
Back substitution (upper-triangular)
Syntax
usolveAll(A, b)
vander
Vandermonde matrix of x; column j is xᵢ^(N-1-j) (numpy np.vander convention, N defaults to x.length), or xᵢ^j when increasing is true
Syntax
vander(x[, n][, increasing])