Skip to content

Commit eb9800c

Browse files
committed
Early termination for single eigenpair calculation added
1 parent c0da95e commit eb9800c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/lambda_lanczos/lambda_lanczos.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ class LambdaLanczos {
346346
if (nothing_added) {
347347
break;
348348
}
349+
350+
if (this->num_eigs == 1) {
351+
// If only one eigenpair is required, iteration can be stopped
352+
break;
353+
}
349354
}
350355

351356
const auto& eigenpairs = ep_manager.getEigenpairs();

test/lambda_lanczos_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ TEST(DIAGONALIZE_TEST, SIMPLE_MATRIX) {
157157
for (size_t i = 0; i < n; ++i) {
158158
EXPECT_NEAR(correct_eigvec[i], eigvec[i], std::abs(correct_eigvalue * engine.eps * 10));
159159
}
160+
EXPECT_EQ(engine.getIterationCounts().size(), 1);
160161
}
161162

162163
TEST(DIAGONALIZE_TEST, SIMPLE_MATRIX_FLOAT) {

0 commit comments

Comments
 (0)