Remove restriction on sigma for ArpackSelfAdjointEigenSolver

libeigen/eigen!3631

Co-authored-by: Cédric Hubert <chubert@MacBook-Pro-16.local>
Co-authored-by: Cédric Hubert <chubert@hubert-dock1.uphf.fr>
diff --git a/cmake/FindARPACK.cmake b/cmake/FindARPACK.cmake
new file mode 100644
index 0000000..6579f5b
--- /dev/null
+++ b/cmake/FindARPACK.cmake
@@ -0,0 +1,9 @@
+# SPDX-FileCopyrightText: The Eigen Authors
+# SPDX-License-Identifier: MPL-2.0
+
+find_library(ARPACK_LIBRARIES NAMES arpack PATHS $ENV{ARPACKDIR} ${LIB_INSTALL_DIR})
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(ARPACK DEFAULT_MSG ARPACK_LIBRARIES)
+
+mark_as_advanced(ARPACK_LIBRARIES)
diff --git a/contrib/Eigen/ArpackSupport b/contrib/Eigen/ArpackSupport
index ba981d2..b8bab81 100644
--- a/contrib/Eigen/ArpackSupport
+++ b/contrib/Eigen/ArpackSupport
@@ -11,6 +11,8 @@
 #ifndef EIGEN_ARPACKSUPPORT_MODULE_H
 #define EIGEN_ARPACKSUPPORT_MODULE_H
 
+#include <sstream>
+#include <locale>
 #include "../../Eigen/Core"
 
 /** \defgroup ArpackSupport_Module Arpack support module
diff --git a/contrib/Eigen/src/ArpackSupport/ArpackSelfAdjointEigenSolver.h b/contrib/Eigen/src/ArpackSupport/ArpackSelfAdjointEigenSolver.h
index 7a39d74..534944e 100644
--- a/contrib/Eigen/src/ArpackSupport/ArpackSelfAdjointEigenSolver.h
+++ b/contrib/Eigen/src/ArpackSupport/ArpackSelfAdjointEigenSolver.h
@@ -78,12 +78,15 @@
    * \param[in] B Self-adjoint matrix for the generalized eigenvalue problem.
    * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute.
    *    Must be less than the size of the input matrix, or an error is returned.
-   * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with
-   *    respective meanings to find the largest magnitude, smallest magnitude,
-   *    largest algebraic, or smallest algebraic eigenvalues. Passing a floating
-   *    point value in string form, to find the eigenvalues closest to that value,
-   *    is not supported yet and triggers an assertion.
-   * \param[in]  options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+   * \param[in] eigs_sigma One of "LM", "SM", "LA", "SA" or "BE" (in upper or lower case), to find the
+   *    eigenvalues of largest magnitude, of smallest magnitude, the largest algebraic, the smallest
+   *    algebraic, or eigenvalues from both ends of the spectrum; or a finite floating point value in
+   *    string form, such as "1.5", to find the eigenvalues closest to that shift. For any other string
+   *    compute() returns with info() equal to #InvalidInput. For a shift inside or above the spectrum,
+   *    \p A - sigma * \p B is not positive definite, so the default \p SimplicialLLT solver returns
+   *    #NumericalIssue: use a solver for indefinite matrices (\p SimplicialLDLT, \p SparseLU). A shift
+   *    equal to an eigenvalue fails in the factorization.
+   * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
    * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which
    *    means machine precision.
    *
@@ -112,12 +115,15 @@
    *    through the template parameter.
    * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute.
    *    Must be less than the size of the input matrix, or an error is returned.
-   * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with
-   *    respective meanings to find the largest magnitude, smallest magnitude,
-   *    largest algebraic, or smallest algebraic eigenvalues. Passing a floating
-   *    point value in string form, to find the eigenvalues closest to that value,
-   *    is not supported yet and triggers an assertion.
-   * \param[in]  options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+   * \param[in] eigs_sigma One of "LM", "SM", "LA", "SA" or "BE" (in upper or lower case), to find the
+   *    eigenvalues of largest magnitude, of smallest magnitude, the largest algebraic, the smallest
+   *    algebraic, or eigenvalues from both ends of the spectrum; or a finite floating point value in
+   *    string form, such as "1.5", to find the eigenvalues closest to that shift. For any other string
+   *    compute() returns with info() equal to #InvalidInput. For a shift inside or above the spectrum,
+   *    \p A - sigma * \p B is not positive definite, so the default \p SimplicialLLT solver returns
+   *    #NumericalIssue: use a solver for indefinite matrices (\p SimplicialLDLT, \p SparseLU). A shift
+   *    equal to an eigenvalue fails in the factorization.
+   * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
    * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which
    *    means machine precision.
    *
@@ -141,16 +147,19 @@
 
   /** \brief Computes generalized eigenvalues / eigenvectors of given matrix using the external ARPACK library.
    *
-   * \param[in]  A  Selfadjoint matrix whose eigendecomposition is to be computed.
-   * \param[in]  B  Selfadjoint matrix for generalized eigenvalues.
+   * \param[in] A Selfadjoint matrix whose eigendecomposition is to be computed.
+   * \param[in] B Selfadjoint matrix for generalized eigenvalues.
    * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute.
    *    Must be less than the size of the input matrix, or an error is returned.
-   * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with
-   *    respective meanings to find the largest magnitude, smallest magnitude,
-   *    largest algebraic, or smallest algebraic eigenvalues. Passing a floating
-   *    point value in string form, to find the eigenvalues closest to that value,
-   *    is not supported yet and triggers an assertion.
-   * \param[in]  options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+   * \param[in] eigs_sigma One of "LM", "SM", "LA", "SA" or "BE" (in upper or lower case), to find the
+   *    eigenvalues of largest magnitude, of smallest magnitude, the largest algebraic, the smallest
+   *    algebraic, or eigenvalues from both ends of the spectrum; or a finite floating point value in
+   *    string form, such as "1.5", to find the eigenvalues closest to that shift. For any other string
+   *    compute() returns with info() equal to #InvalidInput. For a shift inside or above the spectrum,
+   *    \p A - sigma * \p B is not positive definite, so the default \p SimplicialLLT solver returns
+   *    #NumericalIssue: use a solver for indefinite matrices (\p SimplicialLDLT, \p SparseLU). A shift
+   *    equal to an eigenvalue fails in the factorization.
+   * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
    * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which
    *    means machine precision.
    *
@@ -172,15 +181,18 @@
 
   /** \brief Computes eigenvalues / eigenvectors of given matrix using the external ARPACK library.
    *
-   * \param[in]  A  Selfadjoint matrix whose eigendecomposition is to be computed.
+   * \param[in] A Selfadjoint matrix whose eigendecomposition is to be computed.
    * \param[in] nbrEigenvalues The number of eigenvalues / eigenvectors to compute.
    *    Must be less than the size of the input matrix, or an error is returned.
-   * \param[in] eigs_sigma String containing either "LM", "SM", "LA", or "SA", with
-   *    respective meanings to find the largest magnitude, smallest magnitude,
-   *    largest algebraic, or smallest algebraic eigenvalues. Passing a floating
-   *    point value in string form, to find the eigenvalues closest to that value,
-   *    is not supported yet and triggers an assertion.
-   * \param[in]  options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
+   * \param[in] eigs_sigma One of "LM", "SM", "LA", "SA" or "BE" (in upper or lower case), to find the
+   *    eigenvalues of largest magnitude, of smallest magnitude, the largest algebraic, the smallest
+   *    algebraic, or eigenvalues from both ends of the spectrum; or a finite floating point value in
+   *    string form, such as "1.5", to find the eigenvalues closest to that shift. For any other string
+   *    compute() returns with info() equal to #InvalidInput. For a shift inside or above the spectrum,
+   *    \p A - sigma * \p B is not positive definite, so the default \p SimplicialLLT solver returns
+   *    #NumericalIssue: use a solver for indefinite matrices (\p SimplicialLDLT, \p SparseLU). A shift
+   *    equal to an eigenvalue fails in the factorization.
+   * \param[in] options Can be #ComputeEigenvectors (default) or #EigenvaluesOnly.
    * \param[in] tol What tolerance to find the eigenvalues to. Default is 0, which
    *    means machine precision.
    *
@@ -369,28 +381,40 @@
   //
   RealScalar sigma = 0.0;
 
-  if (eigs_sigma.length() >= 2 && isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) {
-    eigs_sigma[0] = toupper(eigs_sigma[0]);
-    eigs_sigma[1] = toupper(eigs_sigma[1]);
+  if (eigs_sigma.length() == 2 && isalpha(static_cast<unsigned char>(eigs_sigma[0])) &&
+      isalpha(static_cast<unsigned char>(eigs_sigma[1]))) {
+    eigs_sigma[0] = toupper(static_cast<unsigned char>(eigs_sigma[0]));
+    eigs_sigma[1] = toupper(static_cast<unsigned char>(eigs_sigma[1]));
+
+    const std::string key = eigs_sigma.substr(0, 2);
+    if (key != "LA" && key != "SA" && key != "SM" && key != "LM" && key != "BE") {
+      // not a valid mode, and not a number either ("inf", "nan", typos...)
+      m_info = InvalidInput;
+      return *this;
+    }
 
     // In the following special case we're going to invert the problem, since solving
     // for larger magnitude is much much faster
     // i.e., if 'SM' is specified, we're going to really use 'LM', the default
-    //
-    if (eigs_sigma.substr(0, 2) != "SM") {
+    if (key != "SM") {
       whch[0] = eigs_sigma[0];
       whch[1] = eigs_sigma[1];
     }
   } else {
-    eigen_assert(false && "Specifying clustered eigenvalues is not yet supported!");
+    // Numeric shift: the whole string must be a finite number
+    std::istringstream iss(eigs_sigma);
+    iss.imbue(std::locale::classic());
+    double value;
+    iss >> std::noskipws >> value;
+    const bool parse_failed = iss.fail();  // no conversion, or out of range
+    const bool all_read = iss.eof();       // nothing else must remain
 
-    // If it's not scalar values, then the user may be explicitly
-    // specifying the sigma value to cluster the evs around
-    //
-    sigma = atof(eigs_sigma.c_str());
-
-    // If atof fails, it returns 0.0, which is a fine default
-    //
+    // convert to RealScalar and check
+    sigma = static_cast<RealScalar>(value);
+    if (parse_failed || !all_read || !(numext::isfinite)(sigma)) {
+      m_info = InvalidInput;
+      return *this;
+    }
   }
 
   // "I" means normal eigenvalue problem, "G" means generalized
@@ -459,11 +483,9 @@
   if (mode == 1 || mode == 2) {
     if (!isBempty) OP.compute(B);
   } else if (mode == 3) {
-    if (sigma == 0.0) {
+    if (sigma == static_cast<RealScalar>(0.0)) {
       OP.compute(A);
     } else {
-      // Note: We will never enter here because sigma must be 0.0
-      //
       if (isBempty) {
         MatrixType AminusSigmaB(A);
         for (Index i = 0; i < A.rows(); ++i) AminusSigmaB.coeffRef(i, i) -= sigma;
diff --git a/contrib/test/CMakeLists.txt b/contrib/test/CMakeLists.txt
index aa88c4d..82a2b8c 100644
--- a/contrib/test/CMakeLists.txt
+++ b/contrib/test/CMakeLists.txt
@@ -73,6 +73,14 @@
 ei_add_test(legacy_iterative_solvers)
 ei_add_test(arpack_stub)
 
+find_package(ARPACK)
+if(ARPACK_FOUND)
+  ei_add_property(EIGEN_TESTED_BACKENDS "arpack, ")
+  ei_add_test(arpack "" "${ARPACK_LIBRARIES}")
+else()
+  ei_add_property(EIGEN_MISSING_BACKENDS "arpack, ")
+endif()
+
 find_package(FFTW)
 if(FFTW_FOUND)
   ei_add_property(EIGEN_TESTED_BACKENDS "fftw, ")
diff --git a/contrib/test/arpack.cpp b/contrib/test/arpack.cpp
new file mode 100644
index 0000000..c8ad649
--- /dev/null
+++ b/contrib/test/arpack.cpp
@@ -0,0 +1,323 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2026 The Eigen Authors
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+// SPDX-License-Identifier: MPL-2.0
+
+// Tests the state handling of ArpackGeneralizedSelfAdjointEigenSolver, especially
+// the values supplied as shift when calling the  compute() method.
+
+#include "sparse.h"
+#include <Eigen/ArpackSupport>
+
+template <class Solver>
+struct handles_indefinite : std::false_type {};
+
+template <class M, int UpLo, class Ord>
+struct handles_indefinite<SimplicialLDLT<M, UpLo, Ord>> : std::true_type {};
+
+template <class M, class Ord>
+struct handles_indefinite<SparseLU<M, Ord>> : std::true_type {};
+
+template <class T>
+constexpr bool handles_indefinite_v = handles_indefinite<T>::value;
+
+// builds the 'stiffness' matrix for the 1D Laplacian equation with size n and grid spacing h
+static SparseMatrix<double> build_laplacian_1d_A_matrix(Index n, double h) {
+  SparseMatrix<double> A(n, n);
+  for (int i = 0; i < n; ++i) {
+    A.insert(i, i) = 2.0 / h;
+    if (i + 1 < n) {
+      A.insert(i, i + 1) = -1.0 / h;
+      A.insert(i + 1, i) = -1.0 / h;
+    }
+  }
+  return A;
+}
+
+// builds the 'mass' matrix for the 1D Laplacian equation with size n and grid spacing h
+static SparseMatrix<double> build_laplacian_1d_B_matrix(Index n, double h) {
+  SparseMatrix<double> B(n, n);
+  for (int i = 0; i < n; ++i) {
+    B.insert(i, i) = 4.0 * h / 6.0;
+    if (i + 1 < n) {
+      B.insert(i, i + 1) = h / 6.0;
+      B.insert(i + 1, i) = h / 6.0;
+    }
+  }
+  return B;
+}
+
+// returns the exact k-th eigenvalue for a given grid spacing h
+double lambda_exact(int k, double h) {
+  const double c = std::cos(k * EIGEN_PI * h);
+  return 6.0 * (1.0 - c) / (h * h * (2.0 + c));
+}
+
+// returns all eigenvalues for a given sigma and grid spacing h
+std::vector<double> reference(Index n, Index nev, double sigma, double h) {
+  std::vector<double> all(n);
+  for (int k = 1; k <= n; ++k) all[k - 1] = lambda_exact(k, h);
+  std::sort(all.begin(), all.end(), [&](double a, double b) { return std::abs(a - sigma) < std::abs(b - sigma); });
+
+  all.resize(nev);
+  std::sort(all.begin(), all.end());
+  return all;
+}
+
+// extraction of largest magnitude eigenvalues
+//  - LLT or LU matrix solvers work
+//  - checks whether the solver returns success
+//  - checks whether the extracted eigenvalues match w.r.t. theory
+template <class T>
+void test_arpack_sigma_LM() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  solver.compute(A, B, nev, "LM");
+
+  VERIFY(solver.info() == Success);
+
+  for (int i = 0; i < nev; ++i) {
+    VERIFY_IS_APPROX(solver.eigenvalues()[i], lambda_exact(n - nev + i + 1, h));
+  }
+}
+
+// extraction of smallest magnitude eigenvalues
+//  - LLT or LU matrix solvers work
+//  - checks whether the solver returns success
+//  - checks whether the extracted eigenvalues match w.r.t. theory
+template <class T>
+void test_arpack_sigma_SM() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  solver.compute(A, B, nev, "SM");
+
+  VERIFY(solver.info() == Success);
+
+  for (int i = 0; i < nev; ++i) {
+    VERIFY_IS_APPROX(solver.eigenvalues()[i], lambda_exact(i + 1, h));
+  }
+}
+
+// extraction of eigenvalues close to sigma, which is below the spectrum
+//  - LLT or LU matrix solvers work (A-sig*M is positive definite)
+//  - checks whether the solver returns success
+//  - checks whether the extracted eigenvalues match w.r.t. theory
+template <class T>
+void test_arpack_sigma_below() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  std::stringstream sig;
+  sig << std::setprecision(8) << lambda_exact(1, h) / 2.0;  // arbitrary sigma, as long as it is below the spectrum
+  solver.compute(A, B, nev, sig.str());
+
+  VERIFY(solver.info() == Success);
+
+  for (int i = 0; i < nev; ++i) {
+    VERIFY_IS_APPROX(solver.eigenvalues()[i], lambda_exact(i + 1, h));
+  }
+}
+
+// extraction of eigenvalues close to sigma, which is inside the spectrum
+//  - LLT matrix solvers fails because the A-sig*M is indefinite
+//  - LU matrix solvers works
+//  - checks whether the solver returns success
+//  - checks whether the extracted eigenvalues match w.r.t. theory
+template <class T>
+void test_arpack_sigma_inside() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  double sig_val =
+      (lambda_exact(1, h) + lambda_exact(n + 1, h)) / 2.0;  // arbitrary sigma, as long as it is inside the spectrum
+  std::stringstream sig;
+  sig << std::setprecision(8) << sig_val;  // string version
+  solver.compute(A, B, nev, sig.str());
+
+  EIGEN_IF_CONSTEXPR (handles_indefinite_v<T>) {
+    // works
+    VERIFY(solver.info() == Success);
+
+    std::vector<double> ref = reference(n, nev, sig_val, h);
+    for (int i = 0; i < nev; ++i) {
+      VERIFY_IS_APPROX(solver.eigenvalues()[i], ref[i]);
+    }
+  } else {
+    // A-sig*M is indefinite, the test should fail
+    VERIFY(solver.info() == NumericalIssue);
+  }
+}
+
+// extraction of eigenvalues close to sigma, which is above the spectrum
+//  - LLT matrix solvers fails because the A-sig*M is negative definite
+//  - LU matrix solvers works
+//  - checks whether the solver returns success
+//  - checks whether the extracted eigenvalues match w.r.t. theory
+template <class T>
+void test_arpack_sigma_above() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  double sig_val = lambda_exact(n + 1, h) * 1.5;  // arbitrary sigma, as long as it is above the spectrum
+  std::stringstream sig;
+  sig << std::setprecision(8) << sig_val;  // string version
+  solver.compute(A, B, nev, sig.str());
+
+  EIGEN_IF_CONSTEXPR (handles_indefinite_v<T>) {
+    // works
+    VERIFY(solver.info() == Success);
+
+    std::vector<double> ref = reference(n, nev, sig_val, h);
+    for (int i = 0; i < nev; ++i) {
+      VERIFY_IS_APPROX(solver.eigenvalues()[i], ref[i]);
+    }
+  } else {
+    // A-sig*M is indefinite, the test should fail
+    VERIFY(solver.info() == NumericalIssue);
+  }
+}
+
+// invalid values of sigma
+//  - a string that is neither a mode nor a finite number gives InvalidInput
+//  - a valid shift or mode afterwards succeeds
+template <class T>
+void test_arpack_bad_sigma() {
+  const Index n = 200;
+  static const double h = 1.0 / (n + 1);
+  const Index nev = 6;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, h);
+  const SparseMatrix<double> B = build_laplacian_1d_B_matrix(n, h);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  // test for empty space in sigma (should fail)
+  solver.compute(A, B, nev, "");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for single char in sigma (should fail)
+  solver.compute(A, B, nev, "x");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for non-supported string sigma (should fail)
+  solver.compute(A, B, nev, "AB");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for leading space in sigma (should fail)
+  solver.compute(A, B, nev, " LM");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for trailing space in sigma (should fail)
+  solver.compute(A, B, nev, "LM ");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for comma as decimal separator in sigma (should fail)
+  solver.compute(A, B, nev, "1,5");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for bad value in sigma (should fail)
+  solver.compute(A, B, nev, "nan");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for bad value in sigma (should fail)
+  solver.compute(A, B, nev, "inf");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for bad value in sigma (should fail)
+  solver.compute(A, B, nev, "1e999");
+  VERIFY(solver.info() == InvalidInput);
+
+  // test for good value in sigma (should work)
+  solver.compute(A, B, nev, "1.5");
+  VERIFY(solver.info() == Success);
+
+  // test for good value in sigma (should work)
+  solver.compute(A, B, nev, "lm");  // checks toupper
+  VERIFY(solver.info() == Success);
+}
+
+// a shift for the standard problem A x = lambda x, which factorizes A - sigma * I
+template <class T>
+void test_arpack_sigma_standard() {
+  const Index n = 200;
+  const Index nev = 6;
+  const double sig_val = 1.05;
+  const SparseMatrix<double> A = build_laplacian_1d_A_matrix(n, 1.0);
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<double>, T> solver;
+
+  solver.compute(A, nev, "1.05");
+  VERIFY(solver.info() == Success);
+
+  // the eigenvalues of tridiag(-1, 2, -1) are 2 - 2 cos(k pi / (n + 1))
+  std::vector<double> ref(n);
+  for (int k = 1; k <= n; ++k) ref[k - 1] = 2.0 - 2.0 * std::cos(k * EIGEN_PI / (n + 1));
+  std::sort(ref.begin(), ref.end(), [&](double a, double b) { return std::abs(a - sig_val) < std::abs(b - sig_val); });
+  ref.resize(nev);
+  std::sort(ref.begin(), ref.end());
+  for (int i = 0; i < nev; ++i) {
+    VERIFY_IS_APPROX(solver.eigenvalues()[i], ref[i]);
+  }
+}
+
+// a shift that is finite as a double but overflows the solver's float is rejected
+void test_arpack_sigma_overflows_float() {
+  const SparseMatrix<float> A = build_laplacian_1d_A_matrix(200, 1.0).cast<float>();
+  ArpackGeneralizedSelfAdjointEigenSolver<SparseMatrix<float>> solver;
+
+  solver.compute(A, 6, "1e39");
+  VERIFY(solver.info() == InvalidInput);
+}
+
+EIGEN_DECLARE_TEST(arpack) {
+  // largest magnitude, with SimplicialLLT matrix solver
+  CALL_SUBTEST_1(test_arpack_sigma_LM<SimplicialLLT<SparseMatrix<double>>>());
+
+  // smallest magnitude, with SimplicialLLT matrix solver
+  CALL_SUBTEST_1(test_arpack_sigma_SM<SimplicialLLT<SparseMatrix<double>>>());
+
+  // sigma below the spectrum, with SimplicialLLT matrix solver
+  CALL_SUBTEST_1(test_arpack_sigma_below<SimplicialLLT<SparseMatrix<double>>>());
+
+  // sigma inside the spectrum, with SimplicialLLT and SparseLU matrix solvers
+  CALL_SUBTEST_1(test_arpack_sigma_inside<SimplicialLLT<SparseMatrix<double>>>());
+  CALL_SUBTEST_1(test_arpack_sigma_inside<SparseLU<SparseMatrix<double>>>());
+
+  // sigma above the spectrum, with SimplicialLLT and SparseLU matrix solvers
+  CALL_SUBTEST_1(test_arpack_sigma_above<SimplicialLLT<SparseMatrix<double>>>());
+  CALL_SUBTEST_1(test_arpack_sigma_above<SparseLU<SparseMatrix<double>>>());
+
+  // testing for bad values
+  CALL_SUBTEST_1(test_arpack_bad_sigma<SimplicialLLT<SparseMatrix<double>>>());
+
+  // testing shift for standard problem A x = lambda x, with SimplicialLLT and SparseLU matrix solvers
+  CALL_SUBTEST_1(test_arpack_sigma_standard<SimplicialLDLT<SparseMatrix<double>>>());
+  CALL_SUBTEST_1(test_arpack_sigma_standard<SparseLU<SparseMatrix<double>>>());
+
+  // testing for sigma overflow with float
+  CALL_SUBTEST_1(test_arpack_sigma_overflows_float());
+}