src/features/spectral.c file

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.
static void syev_jacobi_rotate(vm_mat* A, vm_mat* V, const int p, const int q, const vm_float_t tol)
One Jacobi rotation for dense syev.
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.

static void syev_jacobi_rotate(vm_mat* A, vm_mat* V, const int p, const int q, const vm_float_t tol)

One Jacobi rotation for dense syev.

Rotates columns p,q of A and of V.

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_syev. Eigenvalues descending. eigenvectors is n × k on success.