10 #ifndef EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
11 #define EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
13 #include "../../../../Eigen/Dense"
21 template <
typename Scalar,
typename RealScalar>
22 struct arpack_wrapper;
23 template <
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
27 template <
typename MatrixType,
typename MatrixSolver = SimplicialLLT<MatrixType>,
bool BisSPD = false>
96 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
129 compute(
A, nbrEigenvalues, eigs_sigma, options, tol);
302 template <
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
305 Index nbrEigenvalues,
309 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
314 template <
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
318 Index nbrEigenvalues,
325 "invalid option parameter");
327 bool isBempty = (
B.rows() == 0) || (
B.cols() == 0);
345 if (eigs_sigma.length() >= 2 && isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) {
346 eigs_sigma[0] = toupper(eigs_sigma[0]);
347 eigs_sigma[1] = toupper(eigs_sigma[1]);
353 if (eigs_sigma.substr(0, 2) !=
"SM") {
354 whch[0] = eigs_sigma[0];
355 whch[1] = eigs_sigma[1];
358 eigen_assert(
false &&
"Specifying clustered eigenvalues is not yet supported!");
363 sigma = atof(eigs_sigma.c_str());
372 if (eigs_sigma.substr(0, 2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) || (!isBempty && !BisSPD))
377 int mode = (bmat[0] ==
'G') + 1;
378 if (eigs_sigma.substr(0, 2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1]))) {
387 int nev = (
int)nbrEigenvalues;
407 int lworkl = ncv * ncv + 8 * ncv;
410 int *iparam =
new int[11];
417 int *ipntr =
new int[11];
437 if (mode == 1 || mode == 2) {
438 if (!isBempty)
OP.compute(
B);
439 }
else if (mode == 3) {
449 OP.compute(AminusSigmaB);
452 OP.compute(AminusSigmaB);
457 if (!(mode == 1 && isBempty) && !(mode == 2 && isBempty) &&
OP.info() !=
Success)
458 std::cout <<
"Error factoring matrix" << std::endl;
461 internal::arpack_wrapper<Scalar, RealScalar>::saupd(&ido, bmat, &
n, whch, &nev, &tol, resid, &ncv,
v, &ldv, iparam,
462 ipntr, workd, workl, &lworkl, &
info);
464 if (ido == -1 || ido == 1) {
465 Scalar *in = workd + ipntr[0] - 1;
468 if (ido == 1 && mode != 2) {
469 Scalar *out2 = workd + ipntr[2] - 1;
470 if (isBempty || mode == 1)
475 in = workd + ipntr[2] - 1;
488 }
else if (mode == 2) {
494 }
else if (mode == 3) {
498 if (ido == 1 || isBempty)
503 }
else if (ido == 2) {
504 Scalar *in = workd + ipntr[0] - 1;
507 if (isBempty || mode == 1)
529 char howmny[2] =
"A";
533 int *select =
new int[ncv];
537 m_eivalues.resize(nev, 1);
540 &
n, whch, &nev, &tol, resid, &ncv,
v, &ldv, iparam, ipntr,
541 workd, workl, &lworkl, &
info);
549 m_eivec.resize(
A.
rows(), nev);
550 for (
int i = 0;
i < nev;
i++)
551 for (
int j = 0;
j <
n;
j++) m_eivec(
j,
i) =
v[
i *
n +
j] / scale;
553 if (mode == 1 && !isBempty && BisSPD)
556 m_eigenvectorsOk =
true;
559 m_nbrIterations = iparam[2];
560 m_nbrConverged = iparam[4];
575 m_isInitialized =
true;
582 extern "C" void ssaupd_(
int *ido,
char *bmat,
int *
n,
char *which,
int *nev,
float *tol,
float *resid,
int *ncv,
583 float *
v,
int *ldv,
int *iparam,
int *ipntr,
float *workd,
float *workl,
int *lworkl,
586 extern "C" void sseupd_(
int *rvec,
char *All,
int *select,
float *d,
float *z,
int *ldz,
float *
sigma,
char *bmat,
587 int *
n,
char *which,
int *nev,
float *tol,
float *resid,
int *ncv,
float *
v,
int *ldv,
588 int *iparam,
int *ipntr,
float *workd,
float *workl,
int *lworkl,
int *ierr);
592 extern "C" void dsaupd_(
int *ido,
char *bmat,
int *
n,
char *which,
int *nev,
double *tol,
double *resid,
int *ncv,
593 double *
v,
int *ldv,
int *iparam,
int *ipntr,
double *workd,
double *workl,
int *lworkl,
596 extern "C" void dseupd_(
int *rvec,
char *All,
int *select,
double *d,
double *z,
int *ldz,
double *
sigma,
char *bmat,
597 int *
n,
char *which,
int *nev,
double *tol,
double *resid,
int *ncv,
double *
v,
int *ldv,
598 int *iparam,
int *ipntr,
double *workd,
double *workl,
int *lworkl,
int *ierr);
602 template <
typename Scalar,
typename RealScalar>
606 int *lworkl,
int *
info) {
611 char *bmat,
int *
n,
char *which,
int *nev,
RealScalar *tol,
Scalar *resid,
int *ncv,
620 static inline void saupd(
int *ido,
char *bmat,
int *
n,
char *which,
int *nev,
float *tol,
float *resid,
int *ncv,
621 float *
v,
int *ldv,
int *iparam,
int *ipntr,
float *workd,
float *workl,
int *lworkl,
623 ssaupd_(ido, bmat,
n, which, nev, tol, resid, ncv,
v, ldv, iparam, ipntr, workd, workl, lworkl,
info);
626 static inline void seupd(
int *rvec,
char *All,
int *select,
float *d,
float *z,
int *ldz,
float *
sigma,
char *bmat,
627 int *
n,
char *which,
int *nev,
float *tol,
float *resid,
int *ncv,
float *
v,
int *ldv,
628 int *iparam,
int *ipntr,
float *workd,
float *workl,
int *lworkl,
int *ierr) {
629 sseupd_(rvec, All, select, d, z, ldz,
sigma, bmat,
n, which, nev, tol, resid, ncv,
v, ldv, iparam, ipntr, workd,
630 workl, lworkl, ierr);
636 static inline void saupd(
int *ido,
char *bmat,
int *
n,
char *which,
int *nev,
double *tol,
double *resid,
int *ncv,
637 double *
v,
int *ldv,
int *iparam,
int *ipntr,
double *workd,
double *workl,
int *lworkl,
639 dsaupd_(ido, bmat,
n, which, nev, tol, resid, ncv,
v, ldv, iparam, ipntr, workd, workl, lworkl,
info);
642 static inline void seupd(
int *rvec,
char *All,
int *select,
double *d,
double *z,
int *ldz,
double *
sigma,
char *bmat,
643 int *
n,
char *which,
int *nev,
double *tol,
double *resid,
int *ncv,
double *
v,
int *ldv,
644 int *iparam,
int *ipntr,
double *workd,
double *workl,
int *lworkl,
int *ierr) {
645 dseupd_(rvec, All, select, d,
v, ldv,
sigma, bmat,
n, which, nev, tol, resid, ncv,
v, ldv, iparam, ipntr, workd,
646 workl, lworkl, ierr);
650 template <
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
656 template <
typename MatrixSolver,
typename MatrixType,
typename Scalar>
686 template <
typename MatrixSolver,
typename MatrixType,
typename Scalar>
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Definition: ArpackSelfAdjointEigenSolver.h:28
const Matrix< Scalar, Dynamic, Dynamic > & eigenvectors() const
Returns the eigenvectors of given matrix.
Definition: ArpackSelfAdjointEigenSolver.h:204
ArpackGeneralizedSelfAdjointEigenSolver & compute(const MatrixType &A, const MatrixType &B, Index nbrEigenvalues, std::string eigs_sigma="LM", int options=ComputeEigenvectors, RealScalar tol=0.0)
Computes generalized eigenvalues / eigenvectors of given matrix using the external ARPACK library.
Definition: ArpackSelfAdjointEigenSolver.h:316
NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType.
Definition: ArpackSelfAdjointEigenSolver.h:42
MatrixType::Index Index
Definition: ArpackSelfAdjointEigenSolver.h:34
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
Type for vector of eigenvalues as returned by eigenvalues().
Definition: ArpackSelfAdjointEigenSolver.h:49
ComputationInfo m_info
Definition: ArpackSelfAdjointEigenSolver.h:294
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: ArpackSelfAdjointEigenSolver.h:282
Matrix< Scalar, Dynamic, Dynamic > operatorSqrt() const
Computes the positive-definite square root of the matrix.
Definition: ArpackSelfAdjointEigenSolver.h:248
size_t m_nbrIterations
Definition: ArpackSelfAdjointEigenSolver.h:299
ArpackGeneralizedSelfAdjointEigenSolver(const MatrixType &A, Index nbrEigenvalues, std::string eigs_sigma="LM", int options=ComputeEigenvectors, RealScalar tol=0.0)
Constructor; computes eigenvalues of given matrix.
Definition: ArpackSelfAdjointEigenSolver.h:121
size_t getNbrConvergedEigenValues() const
Definition: ArpackSelfAdjointEigenSolver.h:287
bool m_eigenvectorsOk
Definition: ArpackSelfAdjointEigenSolver.h:296
Matrix< Scalar, Dynamic, Dynamic > m_eivec
Definition: ArpackSelfAdjointEigenSolver.h:292
ArpackGeneralizedSelfAdjointEigenSolver()
Default constructor.
Definition: ArpackSelfAdjointEigenSolver.h:57
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition: ArpackSelfAdjointEigenSolver.h:33
const Matrix< Scalar, Dynamic, 1 > & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition: ArpackSelfAdjointEigenSolver.h:225
bool m_isInitialized
Definition: ArpackSelfAdjointEigenSolver.h:295
ArpackGeneralizedSelfAdjointEigenSolver(const MatrixType &A, const MatrixType &B, Index nbrEigenvalues, std::string eigs_sigma="LM", int options=ComputeEigenvectors, RealScalar tol=0.0)
Constructor; computes generalized eigenvalues of given matrix with respect to another matrix.
Definition: ArpackSelfAdjointEigenSolver.h:87
Matrix< Scalar, Dynamic, Dynamic > operatorInverseSqrt() const
Computes the inverse square root of the matrix.
Definition: ArpackSelfAdjointEigenSolver.h:272
Matrix< Scalar, Dynamic, 1 > m_eivalues
Definition: ArpackSelfAdjointEigenSolver.h:293
size_t m_nbrConverged
Definition: ArpackSelfAdjointEigenSolver.h:298
size_t getNbrIterations() const
Definition: ArpackSelfAdjointEigenSolver.h:289
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
static ConstMapType Map(const Scalar *data)
Definition: PlainObjectBase.h:595
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
Definition: matrices.h:74
#define OP(X)
Definition: common.h:54
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Definition: dense_solvers.cpp:23
ComputationInfo
Definition: Constants.h:438
@ NumericalIssue
Definition: Constants.h:442
@ InvalidInput
Definition: Constants.h:447
@ Success
Definition: Constants.h:440
@ NoConvergence
Definition: Constants.h:444
@ GenEigMask
Definition: Constants.h:414
@ EigVecMask
Definition: Constants.h:403
@ ComputeEigenvectors
Definition: Constants.h:401
int info
Definition: level2_cplx_impl.h:39
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 ceil(const bfloat16 &a)
Definition: BFloat16.h:644
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
void dseupd_(int *rvec, char *All, int *select, double *d, double *z, int *ldz, double *sigma, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *ldv, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *ierr)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void sseupd_(int *rvec, char *All, int *select, float *d, float *z, int *ldz, float *sigma, char *bmat, int *n, char *which, int *nev, float *tol, float *resid, int *ncv, float *v, int *ldv, int *iparam, int *ipntr, float *workd, float *workl, int *lworkl, int *ierr)
void ssaupd_(int *ido, char *bmat, int *n, char *which, int *nev, float *tol, float *resid, int *ncv, float *v, int *ldv, int *iparam, int *ipntr, float *workd, float *workl, int *lworkl, int *info)
void dsaupd_(int *ido, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *ldv, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
int sigma
Definition: calibrate.py:179
Definition: Eigen_Colamd.h:49
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
static void project(MatrixSolver &OP, int n, int k, Scalar *vecs)
Definition: ArpackSelfAdjointEigenSolver.h:692
static void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out)
Definition: ArpackSelfAdjointEigenSolver.h:688
static void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out)
Definition: ArpackSelfAdjointEigenSolver.h:658
static void project(MatrixSolver &OP, int n, int k, Scalar *vecs)
Definition: ArpackSelfAdjointEigenSolver.h:676
Definition: ArpackSelfAdjointEigenSolver.h:651
static void project(MatrixSolver &OP, int n, int k, Scalar *vecs)
static void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out)
static void seupd(int *rvec, char *All, int *select, double *d, double *z, int *ldz, double *sigma, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *ldv, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *ierr)
Definition: ArpackSelfAdjointEigenSolver.h:642
static void saupd(int *ido, char *bmat, int *n, char *which, int *nev, double *tol, double *resid, int *ncv, double *v, int *ldv, int *iparam, int *ipntr, double *workd, double *workl, int *lworkl, int *info)
Definition: ArpackSelfAdjointEigenSolver.h:636
static void saupd(int *ido, char *bmat, int *n, char *which, int *nev, float *tol, float *resid, int *ncv, float *v, int *ldv, int *iparam, int *ipntr, float *workd, float *workl, int *lworkl, int *info)
Definition: ArpackSelfAdjointEigenSolver.h:620
static void seupd(int *rvec, char *All, int *select, float *d, float *z, int *ldz, float *sigma, char *bmat, int *n, char *which, int *nev, float *tol, float *resid, int *ncv, float *v, int *ldv, int *iparam, int *ipntr, float *workd, float *workl, int *lworkl, int *ierr)
Definition: ArpackSelfAdjointEigenSolver.h:626
Definition: ArpackSelfAdjointEigenSolver.h:603
static void saupd(int *ido, char *bmat, int *n, char *which, int *nev, RealScalar *tol, Scalar *resid, int *ncv, Scalar *v, int *ldv, int *iparam, int *ipntr, Scalar *workd, Scalar *workl, int *lworkl, int *info)
Definition: ArpackSelfAdjointEigenSolver.h:604
static void seupd(int *rvec, char *All, int *select, Scalar *d, Scalar *z, int *ldz, RealScalar *sigma, char *bmat, int *n, char *which, int *nev, RealScalar *tol, Scalar *resid, int *ncv, Scalar *v, int *ldv, int *iparam, int *ipntr, Scalar *workd, Scalar *workl, int *lworkl, int *ierr)
Definition: ArpackSelfAdjointEigenSolver.h:610
std::conditional_t< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixColType, ArrayColType > type
Definition: XprHelper.h:782
std::ofstream out("Result.txt")
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2