10#ifndef EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
11#define EIGEN_ARPACKGENERALIZEDSELFADJOINTEIGENSOLVER_H
13#include "../../../../Eigen/Dense"
18 template<
typename Scalar,
typename RealScalar>
struct arpack_wrapper;
19 template<
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
struct OP;
24template<
typename MatrixType,
typename MatrixSolver=SimplicialLLT<MatrixType>,
bool BisSPD=false>
31 typedef typename MatrixType::Scalar
Scalar;
32 typedef typename MatrixType::Index
Index;
87 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
96 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
122 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
131 compute(
A, nbrEigenvalues, eigs_sigma, options, tol);
159 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
185 Index nbrEigenvalues, std::string eigs_sigma=
"LM",
317template<
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
321 std::string eigs_sigma,
int options,
RealScalar tol)
324 compute(
A,
B, nbrEigenvalues, eigs_sigma, options, tol);
330template<
typename MatrixType,
typename MatrixSolver,
bool BisSPD>
334 std::string eigs_sigma,
int options,
RealScalar tol)
341 &&
"invalid option parameter");
343 bool isBempty = (
B.
rows() == 0) || (
B.
cols() == 0);
361 if (eigs_sigma.length() >= 2 && isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1]))
363 eigs_sigma[0] = toupper(eigs_sigma[0]);
364 eigs_sigma[1] = toupper(eigs_sigma[1]);
370 if (eigs_sigma.substr(0,2) !=
"SM")
372 whch[0] = eigs_sigma[0];
373 whch[1] = eigs_sigma[1];
378 eigen_assert(
false &&
"Specifying clustered eigenvalues is not yet supported!");
383 sigma = atof(eigs_sigma.c_str());
392 if (eigs_sigma.substr(0,2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])) || (!isBempty && !BisSPD))
397 int mode = (bmat[0] ==
'G') + 1;
398 if (eigs_sigma.substr(0,2) ==
"SM" || !(isalpha(eigs_sigma[0]) && isalpha(eigs_sigma[1])))
408 int nev = (
int)nbrEigenvalues;
418 int ncv = std::min(std::max(2*nev, 20),
n);
428 int lworkl = ncv*ncv+8*ncv;
431 int *iparam=
new int[11];
433 iparam[2] = std::max(300, (
int)std::ceil(2*
n/std::max(ncv,1)));
438 int *ipntr =
new int[11];
458 if (mode == 1 || mode == 2)
477 AminusSigmaB.coeffRef(
i,
i) -= sigma;
479 OP.compute(AminusSigmaB);
484 OP.compute(AminusSigmaB);
489 if (!(mode == 1 && isBempty) && !(mode == 2 && isBempty) &&
OP.info() !=
Success)
490 std::cout <<
"Error factoring matrix" << std::endl;
495 &ncv,
v, &ldv, iparam, ipntr, workd, workl,
498 if (ido == -1 || ido == 1)
500 Scalar *in = workd + ipntr[0] - 1;
503 if (ido == 1 && mode != 2)
505 Scalar *out2 = workd + ipntr[2] - 1;
506 if (isBempty || mode == 1)
511 in = workd + ipntr[2] - 1;
543 if (ido == 1 || isBempty)
551 Scalar *in = workd + ipntr[0] - 1;
554 if (isBempty || mode == 1)
577 char howmny[2] =
"A";
581 int *select =
new int[ncv];
585 m_eivalues.resize(nev, 1);
588 &sigma, bmat, &
n, whch, &nev, &tol, resid, &ncv,
589 v, &ldv, iparam, ipntr, workd, workl, &lworkl, &
info);
599 m_eivec.resize(
A.
rows(), nev);
600 for (
int i=0;
i<nev;
i++)
601 for (
int j=0;
j<
n;
j++)
604 if (mode == 1 && !isBempty && BisSPD)
607 m_eigenvectorsOk =
true;
610 m_nbrIterations = iparam[2];
611 m_nbrConverged = iparam[4];
626 m_isInitialized =
true;
634extern "C" void ssaupd_(
int *ido,
char *bmat,
int *
n,
char *which,
635 int *nev,
float *tol,
float *resid,
int *ncv,
636 float *
v,
int *ldv,
int *iparam,
int *ipntr,
637 float *workd,
float *workl,
int *lworkl,
640extern "C" void sseupd_(
int *rvec,
char *All,
int *select,
float *d,
641 float *z,
int *ldz,
float *sigma,
642 char *bmat,
int *
n,
char *which,
int *nev,
643 float *tol,
float *resid,
int *ncv,
float *
v,
644 int *ldv,
int *iparam,
int *ipntr,
float *workd,
645 float *workl,
int *lworkl,
int *ierr);
649extern "C" void dsaupd_(
int *ido,
char *bmat,
int *
n,
char *which,
650 int *nev,
double *tol,
double *resid,
int *ncv,
651 double *
v,
int *ldv,
int *iparam,
int *ipntr,
652 double *workd,
double *workl,
int *lworkl,
655extern "C" void dseupd_(
int *rvec,
char *All,
int *select,
double *d,
656 double *z,
int *ldz,
double *sigma,
657 char *bmat,
int *
n,
char *which,
int *nev,
658 double *tol,
double *resid,
int *ncv,
double *
v,
659 int *ldv,
int *iparam,
int *ipntr,
double *workd,
660 double *workl,
int *lworkl,
int *ierr);
693 ssaupd_(
ido,
bmat,
n,
which,
nev,
tol,
resid,
ncv,
v,
ldv,
iparam,
ipntr,
workd,
workl,
lworkl,
info);
703 sseupd_(
rvec,
All, select, d, z,
ldz,
sigma,
bmat,
n,
which,
nev,
tol,
resid,
ncv,
v,
ldv,
iparam,
ipntr,
715 dsaupd_(
ido,
bmat,
n,
which,
nev,
tol,
resid,
ncv,
v,
ldv,
iparam,
ipntr,
workd,
workl,
lworkl,
info);
725 dseupd_(
rvec,
All, select, d,
v,
ldv,
sigma,
bmat,
n,
which,
nev,
tol,
resid,
ncv,
v,
ldv,
iparam,
ipntr,
731template<
typename MatrixSolver,
typename MatrixType,
typename Scalar,
bool BisSPD>
738template<
typename MatrixSolver,
typename MatrixType,
typename Scalar>
770template<
typename MatrixSolver,
typename MatrixType,
typename Scalar>
Array< int, Dynamic, 1 > v
Definition Array_initializer_list_vector_cxx11.cpp:1
int n
Definition BiCGSTAB_simple.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition StaticAssert.h:127
SCALAR Scalar
Definition bench_gemm.cpp:46
NumTraits< Scalar >::Real RealScalar
Definition bench_gemm.cpp:47
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition bench_gemm.cpp:49
MatrixXf MatrixType
Definition benchmark-blocking-sizes.cpp:52
Definition ArpackSelfAdjointEigenSolver.h:26
const Matrix< Scalar, Dynamic, 1 > & eigenvalues() const
Returns the eigenvalues of given matrix.
Definition ArpackSelfAdjointEigenSolver.h:230
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:333
NumTraits< Scalar >::Real RealScalar
Real scalar type for MatrixType.
Definition ArpackSelfAdjointEigenSolver.h:40
MatrixType::Index Index
Definition ArpackSelfAdjointEigenSolver.h:32
ComputationInfo m_info
Definition ArpackSelfAdjointEigenSolver.h:305
ComputationInfo info() const
Reports whether previous computation was successful.
Definition ArpackSelfAdjointEigenSolver.h:290
size_t m_nbrIterations
Definition ArpackSelfAdjointEigenSolver.h:310
Matrix< Scalar, Dynamic, Dynamic > operatorSqrt() const
Computes the positive-definite square root of the matrix.
Definition ArpackSelfAdjointEigenSolver.h:254
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:296
bool m_eigenvectorsOk
Definition ArpackSelfAdjointEigenSolver.h:307
Matrix< Scalar, Dynamic, Dynamic > m_eivec
Definition ArpackSelfAdjointEigenSolver.h:303
ArpackGeneralizedSelfAdjointEigenSolver()
Default constructor.
Definition ArpackSelfAdjointEigenSolver.h:55
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
Definition ArpackSelfAdjointEigenSolver.h:31
bool m_isInitialized
Definition ArpackSelfAdjointEigenSolver.h:306
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:86
Matrix< Scalar, Dynamic, Dynamic > operatorInverseSqrt() const
Computes the inverse square root of the matrix.
Definition ArpackSelfAdjointEigenSolver.h:279
const Matrix< Scalar, Dynamic, Dynamic > & eigenvectors() const
Returns the eigenvectors of given matrix.
Definition ArpackSelfAdjointEigenSolver.h:208
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
Type for vector of eigenvalues as returned by eigenvalues().
Definition ArpackSelfAdjointEigenSolver.h:47
Matrix< Scalar, Dynamic, 1 > m_eivalues
Definition ArpackSelfAdjointEigenSolver.h:304
size_t m_nbrConverged
Definition ArpackSelfAdjointEigenSolver.h:309
size_t getNbrIterations() const
Definition ArpackSelfAdjointEigenSolver.h:299
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
friend class Eigen::Map
Definition PlainObjectBase.h:987
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition PlainObjectBase.h:145
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition PlainObjectBase.h:143
Definition TensorRef.h:81
#define OP(X)
Definition common.h:47
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Definition dense_solvers.cpp:25
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
Definition gnuplot_common_settings.hh:54
ComputationInfo
Definition Constants.h:440
@ NumericalIssue
Definition Constants.h:444
@ InvalidInput
Definition Constants.h:449
@ Success
Definition Constants.h:442
@ NoConvergence
Definition Constants.h:446
@ GenEigMask
Definition Constants.h:418
@ EigVecMask
Definition Constants.h:407
@ ComputeEigenvectors
Definition Constants.h:405
else if n * info
Definition cholesky.cpp:18
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
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:74
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)
Definition BandTriangularSolver.h:13
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233
static void project(MatrixSolver &OP, int n, int k, Scalar *vecs)
Definition ArpackSelfAdjointEigenSolver.h:778
static void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out)
Definition ArpackSelfAdjointEigenSolver.h:773
static void applyOP(MatrixSolver &OP, const MatrixType &A, int n, Scalar *in, Scalar *out)
Definition ArpackSelfAdjointEigenSolver.h:741
static void project(MatrixSolver &OP, int n, int k, Scalar *vecs)
Definition ArpackSelfAdjointEigenSolver.h:760
Definition ArpackSelfAdjointEigenSolver.h:733
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:718
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:710
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:688
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:696
Definition ArpackSelfAdjointEigenSolver.h:666
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:667
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:675
Definition ForwardDeclarations.h:17
std::ofstream out("Result.txt")
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2