7 #ifndef GEN_EIGS_BASE_H 8 #define GEN_EIGS_BASE_H 101 Matrix
Q = Matrix::Identity(m_ncv, m_ncv);
114 const Scalar t = norm(m_ritz_val[i]);
150 Array thresh = tol * m_ritz_val.head(m_nev).array().abs().max(m_eps23);
151 Array resid = m_ritz_est.head(m_nev).array().abs() * m_fac.
f_norm();
153 m_ritz_conv = (resid < thresh);
155 return m_ritz_conv.cast<Index>().
sum();
163 Index nev_new =
m_nev;
164 for (Index
i = m_nev;
i <
m_ncv;
i++)
165 if (
abs(m_ritz_est[
i]) < m_near_0)
169 nev_new +=
std::min(nconv, (m_ncv - nev_new) / 2);
170 if (nev_new == 1 && m_ncv >= 6)
172 else if (nev_new == 1 && m_ncv > 3)
175 if (nev_new > m_ncv - 2)
181 is_conj(m_ritz_val[nev_new - 1], m_ritz_val[nev_new]))
194 ComplexMatrix evecs = decomp.eigenvectors();
196 SortEigenvalue<Complex, SelectionRule> sorting(evals.data(), evals.size());
197 std::vector<int> ind = sorting.index();
202 m_ritz_val[
i] = evals[ind[
i]];
203 m_ritz_est[
i] = evecs(m_ncv - 1, ind[
i]);
207 m_ritz_vec.col(
i).noalias() = evecs.col(ind[
i]);
217 SortEigenvalue<Complex, LARGEST_MAGN> sorting(m_ritz_val.
data(),
m_nev);
218 std::vector<int> ind = sorting.index();
226 SortEigenvalue<Complex, LARGEST_REAL> sorting(m_ritz_val.
data(),
m_nev);
227 ind = sorting.index();
232 SortEigenvalue<Complex, LARGEST_IMAG> sorting(m_ritz_val.
data(),
m_nev);
233 ind = sorting.index();
238 SortEigenvalue<Complex, SMALLEST_MAGN> sorting(m_ritz_val.
data(),
m_nev);
239 ind = sorting.index();
244 SortEigenvalue<Complex, SMALLEST_REAL> sorting(m_ritz_val.
data(),
m_nev);
245 ind = sorting.index();
250 SortEigenvalue<Complex, SMALLEST_IMAG> sorting(m_ritz_val.
data(),
m_nev);
251 ind = sorting.index();
255 throw std::invalid_argument(
"unsupported sorting rule");
258 ComplexVector new_ritz_val(m_ncv);
259 ComplexMatrix new_ritz_vec(m_ncv, m_nev);
260 BoolArray new_ritz_conv(m_nev);
264 new_ritz_val[
i] = m_ritz_val[ind[
i]];
265 new_ritz_vec.col(
i).noalias() = m_ritz_vec.col(ind[
i]);
266 new_ritz_conv[
i] = m_ritz_conv[ind[
i]];
269 m_ritz_val.
swap(new_ritz_val);
270 m_ritz_vec.
swap(new_ritz_vec);
271 m_ritz_conv.
swap(new_ritz_conv);
277 GenEigsBase(OpType* op, BOpType* Bop, Index nev, Index ncv) :
281 m_ncv(ncv > m_n ? m_n : ncv),
290 if (nev < 1 || nev > m_n - 2)
291 throw std::invalid_argument(
"nev must satisfy 1 <= nev <= n - 2, n is the size of matrix");
293 if (ncv < nev + 2 || ncv > m_n)
294 throw std::invalid_argument(
"ncv must satisfy nev + 2 <= ncv <= n, n is the size of matrix");
317 m_ritz_vec.
resize(m_ncv, m_nev);
319 m_ritz_conv.
resize(m_nev);
330 MapConstVec
v0(init_resid, m_n);
331 m_fac.
init(v0, m_nmatop);
343 SimpleRandom<Scalar>
rng(0);
344 Vector init_resid = rng.random_vec(m_n);
374 Index
i, nconv = 0, nev_adj;
375 for (i = 0; i < maxit; i++)
418 const Index nconv = m_ritz_conv.cast<Index>().
sum();
419 ComplexVector
res(nconv);
429 res[
j] = m_ritz_val[
i];
448 const Index nconv = m_ritz_conv.cast<Index>().
sum();
450 ComplexMatrix
res(m_n, nvec);
455 ComplexMatrix ritz_vec_conv(m_ncv, nvec);
457 for (Index
i = 0;
i < m_nev && j < nvec;
i++)
461 ritz_vec_conv.col(j).noalias() = m_ritz_vec.col(i);
466 res.noalias() = m_fac.
matrix_V() * ritz_vec_conv;
482 #endif // GEN_EIGS_BASE_H
void apply_YQ(GenericMatrix Y) const
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic > ComplexMatrix
virtual void compute(ConstGenericMatrix &mat, const Scalar &shift=Scalar(0))
Eigen::Map< Vector > MapVec
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
EIGEN_DEVICE_FUNC void swap(DenseBase< OtherDerived > &other)
static bool is_complex(const Complex &v)
A matrix or vector expression mapping an existing array of data.
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > ComplexVector
static bool is_conj(const Complex &v1, const Complex &v2)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
void init(const Scalar *init_resid)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
void compute(ConstGenericMatrix &mat, const Scalar &s, const Scalar &t)
const ComplexVector & eigenvalues() const
Computation was successful.
void init(MapConstVec &v0, Index &op_counter)
Select eigenvalues with smallest imaginary part (in magnitude). Only for general eigen solvers...
Eigen::Map< const Vector > MapConstVec
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
const Matrix & matrix_H() const
ArnoldiOp< Scalar, OpType, BOpType > ArnoldiOpType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Index num_iterations() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Index num_converged(Scalar tol)
Eigen::Map< Matrix > MapMat
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
ComplexMatrix eigenvectors() const
Index compute(Index maxit=1000, Scalar tol=1e-10, int sort_rule=LARGEST_MAGN)
Arnoldi< Scalar, ArnoldiOpType > ArnoldiFac
Select eigenvalues with largest real part. Only for general eigen solvers.
virtual void sort_ritzpair(int sort_rule)
void compress_V(const Matrix &Q)
Select eigenvalues with smallest real part. Only for general eigen solvers.
Eigen::Array< Scalar, Eigen::Dynamic, 1 > Array
EIGEN_DEVICE_FUNC internal::pow_impl< ScalarX, ScalarY >::result_type pow(const ScalarX &x, const ScalarY &y)
void apply_YQ(GenericMatrix Y) const
The quaternion class used to represent 3D orientations and rotations.
std::complex< Scalar > Complex
void compress_H(const DoubleShiftQR< Scalar > &decomp)
Select eigenvalues with largest imaginary part (in magnitude). Only for general eigen solvers...
const Matrix & matrix_V() const
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
ComplexMatrix eigenvectors(Index nvec) const
ComplexVector eigenvalues() const
Index nev_adjusted(Index nconv)
Eigen::Array< bool, Eigen::Dynamic, 1 > BoolArray
virtual void factorize_from(Index from_k, Index to_m, Index &op_counter)
ScalarWithExceptions conj(const ScalarWithExceptions &x)
Index num_operations() const