Skip to content

Commit caacb1f

Browse files
committed
Reject non-finite PPCG inputs
1 parent 550e807 commit caacb1f

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

source/source_hsolver/ppcg/diago_ppcg_ops.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ void DiagoPPCG<T, Device>::validate_input(
6060
throw std::invalid_argument("PPCG: dim must not exceed ld_psi.");
6161
if (ethr_band.size() < static_cast<size_t>(n_band_))
6262
throw std::invalid_argument("PPCG: ethr_band size is smaller than nband.");
63+
for (int i = 0; i < n_band_; ++i)
64+
if (!std::isfinite(ethr_band[i]))
65+
throw std::invalid_argument("PPCG: ethr_band contains non-finite value.");
66+
for (int i = 0; i < n_dim_; ++i)
67+
if (!std::isfinite(prec[i]))
68+
throw std::invalid_argument("PPCG: preconditioner contains non-finite value.");
6369
}
6470

6571
// =============================================================================

source/source_hsolver/test/diago_ppcg_test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,41 @@ TEST_F(DiagoPPCGDiagonalTest, EmptyHOperatorThrows)
291291
);
292292
}
293293

294+
TEST_F(DiagoPPCGDiagonalTest, NonFiniteInputThrows)
295+
{
296+
std::vector<T> psi_run = psi;
297+
std::vector<Real> eval(nband, 0.0);
298+
299+
hsolver::DiagoPPCG<T, hsolver::base_device::DEVICE_CPU> solver(
300+
/* diag_thr = */ 1e-12,
301+
/* max_iter = */ 50,
302+
/* sbsize = */ 3,
303+
/* rr_step = */ 3,
304+
/* gamma_g0 = */ false,
305+
hsolver::PpcgStrategy::BLOCK_SUBSPACE
306+
);
307+
308+
auto h_op = [this](T* in, T* out, int ld_in, int ncol) {
309+
dense_h_multiply(H_mat.data(), n_dim, in, out, ld_in, ncol);
310+
};
311+
312+
std::vector<double> bad_ethr = ethr;
313+
bad_ethr[0] = std::numeric_limits<double>::quiet_NaN();
314+
EXPECT_THROW(
315+
solver.diag(h_op, nullptr, ld, nband, n_dim,
316+
psi_run.data(), eval.data(), bad_ethr, prec.data()),
317+
std::invalid_argument
318+
);
319+
320+
std::vector<Real> bad_prec = prec;
321+
bad_prec[0] = std::numeric_limits<Real>::infinity();
322+
EXPECT_THROW(
323+
solver.diag(h_op, nullptr, ld, nband, n_dim,
324+
psi_run.data(), eval.data(), ethr, bad_prec.data()),
325+
std::invalid_argument
326+
);
327+
}
328+
294329
TEST(DiagoPPCGLeadingDimensionTest, BlockSubspaceWithPadding)
295330
{
296331
const int n_dim = 5;

0 commit comments

Comments
 (0)