lagrange.solver

Functions

eigsh(A[, k, M, which])

Find k eigenvalues and eigenvectors of the symmetric square matrix A.

Module Contents

lagrange.solver.eigsh(A, k=1, M=None, which='LM')

Find k eigenvalues and eigenvectors of the symmetric square matrix A.

Solves A @ x[i] = w[i] * x[i] for k eigenvalues w[i] and eigenvectors x[i] of a symmetric matrix A. Alternatively, for a generalized eigenvalue problem when M is provided, solves A @ x[i] = w[i] * M @ x[i].

This function is designed to mimic the API of scipy.sparse.linalg.eigsh and uses the Spectra library for sparse eigenvalue computation.

Parameters:
  • A (sparse matrix) – A symmetric square matrix with shape (n, n). Matrix A must be symmetric; this is not checked by the function.

  • k (int) – The number of eigenvalues and eigenvectors to compute. Must be 1 <= k < n. Default: 1.

  • M (sparse matrix or None) – A symmetric positive-definite matrix with the same shape as A for the generalized eigenvalue problem A @ x = w * M @ x. If None (default), the standard eigenvalue problem is solved. Default: None.

  • which (str) – Which k eigenvectors and eigenvalues to find: ‘LM’ for largest (in magnitude) eigenvalues, or ‘SM’ for smallest (in magnitude) eigenvalues. Default: ‘LM’.

Returns:

A tuple (w, v) where w is an array of k eigenvalues and v is an array of k eigenvectors with shape (n, k). The column v[:, i] is the eigenvector corresponding to the eigenvalue w[i].

Return type:

tuple[ndarray, ndarray]

Note

This implementation uses the Spectra library and currently supports only ‘LM’ and ‘SM’ options for the ‘which’ parameter. The eigenvalues are returned in descending order of magnitude for ‘LM’ and ascending order for ‘SM’.

For ‘SM’, this function uses shift-invert mode with shift=0, which may fail if the matrix A (or A - sigma*M for generalized problems) is singular or nearly singular.

See also

scipy.sparse.linalg.eigsh() - SciPy’s sparse symmetric eigenvalue solver