include/vecmat/lanczos.h file

Real-symmetric Lanczos eigensolver with full reorthogonalization.

Enums

enum vm_lanczos_which { VM_LANCZOS_LARGEST = 0, VM_LANCZOS_SMALLEST = 1 }
Which end of the projected spectrum to return.

Functions

auto vm_lanczos(int n, int k, void(*)(vm_float_t*y, const vm_float_t*x, void*ctx) matvec, void* ctx, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info) -> bool
Implicitly restarted Lanczos for a real symmetric operator.
auto vm_lanczos_dense(const vm_mat* A, int k, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info) -> bool
Lanczos on a dense symmetric matrix.
auto vm_lanczos_sparse(const vm_spmat* A, int k, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info) -> bool
Lanczos on a square CSR matrix.

Enum documentation

enum vm_lanczos_which

Which end of the projected spectrum to return.

vm_syev orders eigenvalues descending. Largest keeps that leading end. Smallest keeps the trailing end, still descending, so the smallest value is last.

Enumerators
VM_LANCZOS_LARGEST

Largest algebraic eigenvalues.

VM_LANCZOS_SMALLEST

Smallest algebraic eigenvalues.

Function documentation

bool vm_lanczos(int n, int k, void(*)(vm_float_t*y, const vm_float_t*x, void*ctx) matvec, void* ctx, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info)

Implicitly restarted Lanczos for a real symmetric operator.

Parameters
n
k Number of eigenpairs. 1 <= k <= m.
matvec Applies the symmetric operator. y and x have length n.
ctx Passed through to matvec. May be NULL.
which Largest or smallest end of the projected spectrum.
m Krylov length. k <= m <= n.
tol Relative residual tolerance. Must be finite and positive.
max_restarts Restart cap. Zero is a single build. Negative is an error.
eigenvalues Output eigenvalues, length k.
eigenvectors Optional n × k eigenvectors (columns). NULL skips them.
info Optional iteration stats. May be NULL.
Returns true when the worst returned residual is within tol.

Builds a Krylov subspace of length m with full reorthogonalization, solves the projected tridiagonal with vm_syev, and keeps the k eigenvalues at the end selected by which. Unwanted Ritz values are implicit shifts. The start vector is deterministic.

k <= m <= n. tol is the relative residual ||A u − λ u|| / max(|λ|, ||T||, ε), where ||T|| is the max absolute row sum of the projected tridiagonal and u is a unit Ritz vector. max_restarts < 0 is rejected. Zero restarts is one Krylov build.

On success the k eigenvalues are descending within the selected end. Eigenvector columns, when requested, are unit length with a positive entry of largest magnitude. eigenvectors NULL skips the vectors. info may be NULL. iters is the number of restarts performed (zero when the first build is enough), rel_res is the worst residual of the returned pairs, and ok matches the bool result.

A bad k, m, or tol (tol <= 0 or NaN), a null matvec or eigenvalues, or an eigenvectors matrix that is not n × k returns false and does not write the eigenvalues. If the iteration stops without meeting tol and at least k steps exist, the best pairs are written and the return is false.

Real symmetric only. No shift-invert, no block Lanczos, no complex Hermitian path, and no device path.

bool vm_lanczos_dense(const vm_mat* A, int k, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info)

Lanczos on a dense symmetric matrix.

Parameters
A Symmetric matrix. Lower triangle only.
k Number of eigenpairs.
which Largest or smallest end.
m Krylov length. k <= m <= n.
tol Relative residual tolerance.
max_restarts Restart cap.
eigenvalues Output eigenvalues, length k.
eigenvectors Optional n × k eigenvectors. NULL skips them.
info Optional iteration stats. May be NULL.
Returns true when the worst returned residual is within tol.

Calls vm_symv, so only the lower triangle of A is read. A is not modified. A must be square. The remaining arguments match vm_lanczos.

bool vm_lanczos_sparse(const vm_spmat* A, int k, vm_lanczos_which which, int m, vm_float_t tol, int max_restarts, vm_float_t* eigenvalues, vm_mat* eigenvectors, vm_ksp_info* info)

Lanczos on a square CSR matrix.

Parameters
A CSR operator.
k Number of eigenpairs.
which Largest or smallest end.
m Krylov length. k <= m <= n.
tol Relative residual tolerance.
max_restarts Restart cap.
eigenvalues Output eigenvalues, length k.
eigenvectors Optional n × k eigenvectors. NULL skips them.
info Optional iteration stats. May be NULL.
Returns true when the worst returned residual is within tol.

Calls vm_spmv. The matrix must already store the operator the product should apply. A nonsymmetric CSR is applied as stored; the eigenvalues are meaningful when that operator is symmetric.