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_ 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_, 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_, so only the lower triangle of A is read. A is not modified. A must be square. The remaining arguments match vm_.
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_. 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.