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 * nontrivial function, perform_op(x,y), that computes and returns the product
* y = (A + sigma*I) x */ * y = (A + sigma*I) x */
struct MatrixProdFunctor { struct MatrixProdFunctor {
using Scalar = double;
// Const reference to an externally-held matrix whose minimum-eigenvalue we // Const reference to an externally-held matrix whose minimum-eigenvalue we
// want to compute // want to compute
const Sparse &A_; const Sparse &A_;
@ -630,13 +632,13 @@ static bool SparseMinimumEigenValue(
Eigen::Index numLanczosVectors = 20) { Eigen::Index numLanczosVectors = 20) {
// a. Estimate the largest-magnitude eigenvalue of this matrix using Lanczos // a. Estimate the largest-magnitude eigenvalue of this matrix using Lanczos
MatrixProdFunctor lmOperator(A); MatrixProdFunctor lmOperator(A);
Spectra::SymEigsSolver<double, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN, Spectra::SymEigsSolver lmEigenValueSolver(
MatrixProdFunctor> lmOperator, 1, std::min(numLanczosVectors, A.rows()));
lmEigenValueSolver(&lmOperator, 1, std::min(numLanczosVectors, A.rows()));
lmEigenValueSolver.init(); lmEigenValueSolver.init();
const int lmConverged = lmEigenValueSolver.compute( const int lmConverged =
maxIterations, 1e-4, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN); lmEigenValueSolver.compute(Spectra::SortRule::LargestMagn, maxIterations,
1e-4, Spectra::SortRule::LargestMagn);
// Check convergence and bail out if necessary // Check convergence and bail out if necessary
if (lmConverged != 1) return false; if (lmConverged != 1) return false;
@ -664,10 +666,8 @@ static bool SparseMinimumEigenValue(
MatrixProdFunctor minShiftedOperator(A, -2 * lmEigenValue); MatrixProdFunctor minShiftedOperator(A, -2 * lmEigenValue);
Spectra::SymEigsSolver<double, Spectra::SELECT_EIGENVALUE::LARGEST_MAGN, Spectra::SymEigsSolver minEigenValueSolver(
MatrixProdFunctor> minShiftedOperator, 1, std::min(numLanczosVectors, A.rows()));
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 - // 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 // 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* // order to be able to estimate the smallest eigenvalue within an *absolute*
// tolerance of 'minEigenvalueNonnegativityTolerance' // tolerance of 'minEigenvalueNonnegativityTolerance'
const int minConverged = minEigenValueSolver.compute( const int minConverged = minEigenValueSolver.compute(
maxIterations, minEigenvalueNonnegativityTolerance / lmEigenValue, Spectra::SortRule::LargestMagn, maxIterations,
Spectra::SELECT_EIGENVALUE::LARGEST_MAGN); minEigenvalueNonnegativityTolerance / lmEigenValue,
Spectra::SortRule::LargestMagn);
if (minConverged != 1) return false; if (minConverged != 1) return false;