Skip to content

Commit

Permalink
Merge pull request #125 from shivupa/Davidsonspacesize
Browse files Browse the repository at this point in the history
Davidson Space Size
  • Loading branch information
yixuan authored Aug 14, 2021
2 parents 148d019 + 5c8d57a commit 904bbbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
7 changes: 5 additions & 2 deletions include/Spectra/DavidsonSymEigsSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class DavidsonSymEigsSolver : public JDSymEigsBase<DavidsonSymEigsSolver<OpType>
Vector m_diagonal;

public:
DavidsonSymEigsSolver(OpType& op, Index nev) :
JDSymEigsBase<DavidsonSymEigsSolver<OpType>, OpType>(op, nev)
DavidsonSymEigsSolver(OpType& op, Index nev, Index nvec_init, Index nvec_max) :
JDSymEigsBase<DavidsonSymEigsSolver<OpType>, OpType>(op, nev, nvec_init, nvec_max)
{
m_diagonal.resize(this->m_matrix_operator.rows());
for (Index i = 0; i < op.rows(); i++)
Expand All @@ -49,6 +49,9 @@ class DavidsonSymEigsSolver : public JDSymEigsBase<DavidsonSymEigsSolver<OpType>
}
}

DavidsonSymEigsSolver(OpType& op, Index nev) :
DavidsonSymEigsSolver(op, nev, 2 * nev, 10 * nev) {}

/// Create initial search space based on the diagonal
/// and the spectrum'target (highest or lowest)
///
Expand Down
35 changes: 21 additions & 14 deletions include/Spectra/JDSymEigsBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,35 @@ class JDSymEigsBase
throw std::invalid_argument("nev must satisfy 1 <= nev <= n - 1, n is the size of matrix");
}

public:
JDSymEigsBase(OpType& op, Index nev) :
m_matrix_operator(op),
m_number_eigenvalues(nev),
m_max_search_space_size(10 * m_number_eigenvalues),
m_initial_search_space_size(2 * m_number_eigenvalues),
m_correction_size(m_number_eigenvalues)
void initialize()
{
check_argument();
//TODO better input validation and checks
if (op.cols() < m_max_search_space_size)
if (m_matrix_operator.cols() < m_max_search_space_size)
{
m_max_search_space_size = op.cols();
m_max_search_space_size = m_matrix_operator.cols();
}

if (op.cols() < m_initial_search_space_size + m_correction_size)
if (m_matrix_operator.cols() < m_initial_search_space_size + m_correction_size)
{
m_initial_search_space_size = op.cols() / 3;
m_correction_size = op.cols() / 3;
m_initial_search_space_size = m_matrix_operator.cols() / 3;
m_correction_size = m_matrix_operator.cols() / 3;
}
}

public:
JDSymEigsBase(OpType& op, Index nev, Index nvec_init, Index nvec_max) :
m_matrix_operator(op),
m_number_eigenvalues(nev),
m_max_search_space_size(nvec_max < op.rows() ? nvec_max : 10 * m_number_eigenvalues),
m_initial_search_space_size(nvec_init < op.rows() ? nvec_init : 2 * m_number_eigenvalues),
m_correction_size(m_number_eigenvalues)
{
check_argument();
initialize();
}

JDSymEigsBase(OpType& op, Index nev) :
JDSymEigsBase(op, nev, 2 * nev, 10 * nev) {}

///
/// Sets the Maxmium SearchspaceSize after which is deflated
///
Expand Down

0 comments on commit 904bbbe

Please sign in to comment.