Update ShonanAveraging.cpp to use Spectra v1.1.0

release/4.3a0
Martin Valgur 2024-12-09 17:12:49 +02:00
parent c99a8e1c1d
commit 274acb9e82
1 changed files with 12 additions and 11 deletions

View File

@ -570,6 +570,8 @@ static bool PowerMinimumEigenValue(
* nontrivial function, perform_op(x,y), that computes and returns the product
* y = (A + sigma*I) x */
struct MatrixProdFunctor {
using Scalar = double;
// Const reference to an externally-held matrix whose minimum-eigenvalue we
// want to compute
const Sparse &A_;
@ -630,13 +632,13 @@ static bool SparseMinimumEigenValue(
Eigen::Index numLanczosVectors = 20) {
// a. Estimate the largest-magnitude eigenvalue of this matrix using Lanczos
MatrixProdFunctor lmOperator(A);
Spectra::SymEigsSolver<double, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN,
MatrixProdFunctor>
lmEigenValueSolver(&lmOperator, 1, std::min(numLanczosVectors, A.rows()));
Spectra::SymEigsSolver lmEigenValueSolver(
lmOperator, 1, std::min(numLanczosVectors, A.rows()));
lmEigenValueSolver.init();
const int lmConverged = lmEigenValueSolver.compute(
maxIterations, 1e-4, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN);
const int lmConverged =
lmEigenValueSolver.compute(Spectra::SortRule::LargestMagn, maxIterations,
1e-4, Spectra::SortRule::LargestMagn);
// Check convergence and bail out if necessary
if (lmConverged != 1) return false;
@ -664,10 +666,8 @@ static bool SparseMinimumEigenValue(
MatrixProdFunctor minShiftedOperator(A, -2 * lmEigenValue);
Spectra::SymEigsSolver<double, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN,
MatrixProdFunctor>
minEigenValueSolver(&minShiftedOperator, 1,
std::min(numLanczosVectors, A.rows()));
Spectra::SymEigsSolver minEigenValueSolver(
minShiftedOperator, 1, std::min(numLanczosVectors, A.rows()));
// If S is a critical point of F, then S^T is also in the null space of S -
// Lambda(S) (cf. Lemma 6 of the tech report), and therefore its rows are
@ -695,8 +695,9 @@ static bool SparseMinimumEigenValue(
// order to be able to estimate the smallest eigenvalue within an *absolute*
// tolerance of 'minEigenvalueNonnegativityTolerance'
const int minConverged = minEigenValueSolver.compute(
maxIterations, minEigenvalueNonnegativityTolerance / lmEigenValue,
Spectra::SELECT_EIGENVALUE::LARGEST_MAGN);
Spectra::SortRule::LargestMagn, maxIterations,
minEigenvalueNonnegativityTolerance / lmEigenValue,
Spectra::SortRule::LargestMagn);
if (minConverged != 1) return false;