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
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)
static bool is_complex(const Complex &v)
ComplexMatrix eigenvectors(Index nvec) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar * data() const
A matrix or vector expression mapping an existing array of data.
Index num_operations() const
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > ComplexVector
static bool is_conj(const Complex &v1, const Complex &v2)
Index num_iterations() 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)
void apply_YQ(GenericMatrix Y) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(DenseBase< OtherDerived > &other)
const Matrix & matrix_V() const
Computation was successful.
void init(MapConstVec &v0, Index &op_counter)
AnnoyingScalar conj(const AnnoyingScalar &x)
Select eigenvalues with smallest imaginary part (in magnitude). Only for general eigen solvers...
Eigen::Map< const Vector > MapConstVec
ComplexVector eigenvalues() const
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
ArnoldiOp< Scalar, OpType, BOpType > ArnoldiOpType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Array< int, Dynamic, 1 > v
Index num_converged(Scalar tol)
Eigen::Map< Matrix > MapMat
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Index compute(Index maxit=1000, Scalar tol=1e-10, int sort_rule=LARGEST_MAGN)
Arnoldi< Scalar, ArnoldiOpType > ArnoldiFac
const Matrix & matrix_H() const
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)
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...
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > Matrix
void apply_YQ(GenericMatrix Y) const
ComplexMatrix eigenvectors() const
Index nev_adjusted(Index nconv)
Eigen::Array< bool, Eigen::Dynamic, 1 > BoolArray
const ComplexVector & eigenvalues() const
virtual void factorize_from(Index from_k, Index to_m, Index &op_counter)