spectral.h file
Dense spectral primitives: matvec, symmetric eigensolve, graph Laplacian.
Functions
-
void vm_matvec(vm_
float_ t* y, const vm_ mat* A, const vm_ float_ t* x) - Dense matrix-vector product
y = A x. -
void vm_symv(vm_
float_ t* y, const vm_ mat* A, const vm_ float_ t* x) - Symmetric matrix-vector product.
-
auto vm_syev(vm_
mat* A, vm_ float_ t* eigenvalues, vm_ mat* V) -> bool - Symmetric real eigenvalue decomposition (Jacobi).
-
auto vm_laplacian(vm_
mat* L, const vm_ mat* A) -> bool - Unnormalized graph Laplacian
L = D − A. -
auto vm_syev_topk(const vm_
mat* A, int k, vm_ float_ t* eigenvalues, vm_ mat* eigenvectors) -> bool - Top-k eigenvectors of a symmetric matrix.
Function documentation
void vm_matvec(vm_ float_ t* y,
const vm_ mat* A,
const vm_ float_ t* x)
Dense matrix-vector product y = A x.
| Parameters | |
|---|---|
| y | Output vector. |
| A | Input matrix. |
| x | Input vector. |
A is rows × cols. x has length cols, y has length rows.
void vm_symv(vm_ float_ t* y,
const vm_ mat* A,
const vm_ float_ t* x)
Symmetric matrix-vector product.
| Parameters | |
|---|---|
| y | Output vector. |
| A | Symmetric matrix (lower triangle used). |
| x | Input vector. |
Only the lower triangle of A is read. A must be square.
bool vm_syev(vm_ mat* A,
vm_ float_ t* eigenvalues,
vm_ mat* V)
Symmetric real eigenvalue decomposition (Jacobi).
| Parameters | |
|---|---|
| A | Symmetric matrix, overwritten on success. |
| eigenvalues | Output eigenvalues (length n), descending. |
| V | Optional n × n eigenvector matrix (columns). |
| Returns | true on success. |
On success, eigenvalues are written in descending order. Eigenvector columns are written to V if non-NULL (V must be n × n). A is overwritten. Returns false on non-square, bad sizes, or numerical failure.
bool vm_laplacian(vm_ mat* L,
const vm_ mat* A)
Unnormalized graph Laplacian L = D − A.
| Parameters | |
|---|---|
| L | Output Laplacian. |
| A | Symmetric adjacency (non-negative entries expected). |
| Returns | true on success. |
From a dense symmetric adjacency matrix A. L is allocated or resized as needed.
bool vm_syev_topk(const vm_ mat* A,
int k,
vm_ float_ t* eigenvalues,
vm_ mat* eigenvectors)
Top-k eigenvectors of a symmetric matrix.
| Parameters | |
|---|---|
| A | Symmetric matrix (not overwritten). |
| k | Number of leading eigenpairs (1 ≤ k ≤ n). |
| eigenvalues | Output eigenvalues (length k). |
| eigenvectors | Output n × k eigenvectors (columns). |
| Returns | true on success. |
Thin wrapper around vm_. Eigenvalues descending. eigenvectors is n × k on success.