10 #ifndef EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
11 #define EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
13 #include "../../../../Eigen/Dense"
20 template<
typename Scalar,
typename RealScalar>
struct arpack_wrapper;
21 template<
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
struct OP;
26 template<
typename MatrixType,
typename MatrixSolver=SimplicialLLT<MatrixType>,
bool BisSPD=false>
33 typedef typename MatrixType::Scalar
Scalar;
34 typedef typename MatrixType::Index
Index;
49 typedef typename internal::plain_col_type<MatrixType, RealScalar>::type
RealVectorType;
89 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
98 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
124 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
133 compute(
A, nbrEigenvalues, eigs_sigma, options, tol);
161 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
187 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
319 template<
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
323 std::string eigs_sigma,
int options,
RealScalar tol)
326 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
332 template<
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
336 std::string eigs_sigma,
int options,
RealScalar tol)
343 &&
"invalid option parameter");
345 bool isBempty = (
B.
rows() == 0) || (
B.
cols() == 0);
363 if (eigs_sigma.length() >= 2 && isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1]))
365 eigs_sigma[0] = toupper(eigs_sigma[0]);
366 eigs_sigma[1] = toupper(eigs_sigma[1]);
372 if (eigs_sigma.substr(0,2) !=
"SM")
374 whch[0] = eigs_sigma[0];
375 whch[1] = eigs_sigma[1];
380 eigen_assert(
false &&
"Specifying clustered eigenvalues is not yet supported!");
385 sigma = atof(eigs_sigma.c_str());
394 if (eigs_sigma.substr(0,2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) || (!isBempty && !BisSPD))
399 int mode = (bmat[0] ==
'G') + 1;
400 if (eigs_sigma.substr(0,2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])))
410 int nev = (int)nbrEigenvalues;
430 int lworkl = ncv*ncv+8*ncv;
433 int *iparam=
new int[11];
440 int *ipntr =
new int[11];
460 if (mode == 1 || mode == 2)
479 AminusSigmaB.coeffRef(
i,
i) -= sigma;
481 OP.compute(AminusSigmaB);
486 OP.compute(AminusSigmaB);
491 if (!(mode == 1 && isBempty) && !(mode == 2 && isBempty) && OP.info() !=
Success)
492 std::cout <<
"Error factoring matrix" << std::endl;
496 internal::arpack_wrapper<Scalar, RealScalar>::saupd(&ido, bmat, &
n, whch, &nev, &tol, resid,
497 &ncv,
v, &ldv, iparam, ipntr, workd, workl,
500 if (ido == -1 || ido == 1)
502 Scalar *in = workd + ipntr[0] - 1;
503 Scalar *out = workd + ipntr[1] - 1;
505 if (ido == 1 && mode != 2)
507 Scalar *out2 = workd + ipntr[2] - 1;
508 if (isBempty || mode == 1)
513 in = workd + ipntr[2] - 1;
528 internal::OP<MatrixSolver, MatrixType, Scalar, BisSPD>::applyOP(OP,
A,
n, in, out);
545 if (ido == 1 || isBempty)
553 Scalar *in = workd + ipntr[0] - 1;
554 Scalar *out = workd + ipntr[1] - 1;
556 if (isBempty || mode == 1)
579 char howmny[2] =
"A";
583 int *select =
new int[ncv];
587 m_eivalues.resize(nev, 1);
589 internal::arpack_wrapper<Scalar, RealScalar>::seupd(&rvec, howmny, select, m_eivalues.data(),
v, &ldv,
590 &sigma, bmat, &
n, whch, &nev, &tol, resid, &ncv,
591 v, &ldv, iparam, ipntr, workd, workl, &lworkl, &info);
601 m_eivec.resize(
A.
rows(), nev);
602 for (
int i=0;
i<nev;
i++)
603 for (
int j=0;
j<
n;
j++)
604 m_eivec(
j,
i) =
v[
i*
n+
j] / scale;
606 if (mode == 1 && !isBempty && BisSPD)
607 internal::OP<MatrixSolver, MatrixType, Scalar, BisSPD>::project(OP,
n, nev, m_eivec.data());
609 m_eigenvectorsOk =
true;
612 m_nbrIterations = iparam[2];
613 m_nbrConverged = iparam[4];
628 m_isInitialized =
true;
636 extern "C" void ssaupd_(
int *ido,
char *bmat,
int *n,
char *which,
637 int *nev,
float *tol,
float *resid,
int *ncv,
638 float *v,
int *ldv,
int *iparam,
int *ipntr,
639 float *workd,
float *workl,
int *lworkl,
642 extern "C" void sseupd_(
int *rvec,
char *All,
int *select,
float *d,
643 float *z,
int *ldz,
float *sigma,
644 char *bmat,
int *n,
char *which,
int *nev,
645 float *tol,
float *resid,
int *ncv,
float *v,
646 int *ldv,
int *iparam,
int *ipntr,
float *workd,
647 float *workl,
int *lworkl,
int *ierr);
651 extern "C" void dsaupd_(
int *ido,
char *bmat,
int *n,
char *which,
652 int *nev,
double *tol,
double *resid,
int *ncv,
653 double *v,
int *ldv,
int *iparam,
int *ipntr,
654 double *workd,
double *workl,
int *lworkl,
657 extern "C" void dseupd_(
int *rvec,
char *All,
int *select,
double *d,
658 double *z,
int *ldz,
double *sigma,
659 char *bmat,
int *n,
char *which,
int *nev,
660 double *tol,
double *resid,
int *ncv,
double *v,
661 int *ldv,
int *iparam,
int *ipntr,
double *workd,
662 double *workl,
int *lworkl,
int *ierr);
667 template<
typename Scalar,
typename RealScalar>
struct arpack_wrapper
669 static inline void saupd(
int *ido,
char *bmat,
int *n,
char *which,
670 int *nev, RealScalar *tol, Scalar *resid,
int *ncv,
671 Scalar *v,
int *ldv,
int *iparam,
int *ipntr,
672 Scalar *workd, Scalar *workl,
int *lworkl,
int *info)
677 static inline void seupd(
int *rvec,
char *All,
int *select, Scalar *d,
678 Scalar *z,
int *ldz, RealScalar *sigma,
679 char *bmat,
int *n,
char *which,
int *nev,
680 RealScalar *tol, Scalar *resid,
int *ncv, Scalar *v,
681 int *ldv,
int *iparam,
int *ipntr, Scalar *workd,
682 Scalar *workl,
int *lworkl,
int *ierr)
688 template <>
struct arpack_wrapper<float, float>
690 static inline void saupd(
int *ido,
char *bmat,
int *n,
char *which,
691 int *nev,
float *tol,
float *resid,
int *ncv,
692 float *v,
int *ldv,
int *iparam,
int *ipntr,
693 float *workd,
float *workl,
int *lworkl,
int *info)
695 ssaupd_(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info);
698 static inline void seupd(
int *rvec,
char *All,
int *select,
float *d,
699 float *z,
int *ldz,
float *sigma,
700 char *bmat,
int *n,
char *which,
int *nev,
701 float *tol,
float *resid,
int *ncv,
float *v,
702 int *ldv,
int *iparam,
int *ipntr,
float *workd,
703 float *workl,
int *lworkl,
int *ierr)
705 sseupd_(rvec, All, select, d, z, ldz, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr,
706 workd, workl, lworkl, ierr);
710 template <>
struct arpack_wrapper<double, double>
712 static inline void saupd(
int *ido,
char *bmat,
int *n,
char *which,
713 int *nev,
double *tol,
double *resid,
int *ncv,
714 double *v,
int *ldv,
int *iparam,
int *ipntr,
715 double *workd,
double *workl,
int *lworkl,
int *info)
717 dsaupd_(ido, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr, workd, workl, lworkl, info);
720 static inline void seupd(
int *rvec,
char *All,
int *select,
double *d,
721 double *z,
int *ldz,
double *sigma,
722 char *bmat,
int *n,
char *which,
int *nev,
723 double *tol,
double *resid,
int *ncv,
double *v,
724 int *ldv,
int *iparam,
int *ipntr,
double *workd,
725 double *workl,
int *lworkl,
int *ierr)
727 dseupd_(rvec, All, select, d, v, ldv, sigma, bmat, n, which, nev, tol, resid, ncv, v, ldv, iparam, ipntr,
728 workd, workl, lworkl, ierr);
733 template<
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
736 static inline void applyOP(MatrixSolver &OP,
const MatrixType &A,
int n, Scalar *in, Scalar *out);
737 static inline void project(MatrixSolver &OP,
int n,
int k, Scalar *vecs);
740 template<
typename MatrixSolver,
typename MatrixType,
typename Scalar>
741 struct OP<MatrixSolver,
MatrixType, Scalar, true>
743 static inline void applyOP(MatrixSolver &OP,
const MatrixType &A,
int n, Scalar *in, Scalar *out)
762 static inline void project(MatrixSolver &OP,
int n,
int k, Scalar *vecs)
772 template<
typename MatrixSolver,
typename MatrixType,
typename Scalar>
773 struct OP<MatrixSolver,
MatrixType, Scalar, false>
775 static inline void applyOP(MatrixSolver &OP,
const MatrixType &A,
int n, Scalar *in, Scalar *out)
780 static inline void project(MatrixSolver &OP,
int n,
int k, Scalar *vecs)
Array< int, Dynamic, 1 > v
SparseMatrix< double > A(n, n)
#define EIGEN_STATIC_ASSERT(X, MSG)
Matrix< float, 1, Dynamic > MatrixType
const Matrix< Scalar, Dynamic, Dynamic > & eigenvectors() const
Returns the eigenvectors of given matrix.
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.
NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType.
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
Type for vector of eigenvalues as returned by eigenvalues().
ComputationInfo info() const
Reports whether previous computation was successful.
Matrix< Scalar, Dynamic, Dynamic > operatorSqrt() const
Computes the positive-definite square root of the matrix.
ArpackGeneralizedSelfAdjointEigenSolver(const MatrixType &A, Index nbrEigenvalues, std::string eigs_sigma="LM", int options=ComputeEigenvectors, RealScalar tol=0.0)
Constructor; computes eigenvalues of given matrix.
size_t getNbrConvergedEigenValues() const
Matrix< Scalar, Dynamic, Dynamic > m_eivec
ArpackGeneralizedSelfAdjointEigenSolver()
Default constructor.
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
const Matrix< Scalar, Dynamic, 1 > & eigenvalues() const
Returns the eigenvalues of given matrix.
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.
Matrix< Scalar, Dynamic, Dynamic > operatorInverseSqrt() const
Computes the inverse square root of the matrix.
Matrix< Scalar, Dynamic, 1 > m_eivalues
size_t getNbrIterations() const
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
static ConstMapType Map(const Scalar *data)
EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
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
CleanedUpDerType< DerType >::type() min(const AutoDiffScalar< DerType > &x, const T &y)
CleanedUpDerType< DerType >::type() max(const AutoDiffScalar< DerType > &x, const T &y)
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)