Skip to content

Commit

Permalink
add documentation and test
Browse files Browse the repository at this point in the history
Co-authored-by: Pratik Nayak <pratikvn@protonmail.com>
  • Loading branch information
yhmtsai and pratikvn committed Apr 7, 2023
1 parent cfeb919 commit 23dc74a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/test/stop/criterion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ class Criterion : public ::testing::Test {
};


TEST_F(Criterion, DefaultUpdateStatus)
{
EXPECT_EQ(criterion->update().num_iterations_, 0);
EXPECT_EQ(criterion->update().ignore_residual_check_, false);
EXPECT_EQ(criterion->update().residual_, nullptr);
EXPECT_EQ(criterion->update().residual_norm_, nullptr);
EXPECT_EQ(criterion->update().implicit_sq_residual_norm_, nullptr);
EXPECT_EQ(criterion->update().solution_, nullptr);
}


TEST_F(Criterion, CanLogCheck)
{
auto before_logger = *logger;
Expand Down
1 change: 1 addition & 0 deletions include/ginkgo/core/stop/criterion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Criterion : public EnableAbstractPolymorphicObject<Criterion> {
mutable _type* _name##_ {}

GKO_UPDATER_REGISTER_PARAMETER(size_type, num_iterations);
// ignore_residual_check default is false
GKO_UPDATER_REGISTER_PARAMETER(bool, ignore_residual_check);
GKO_UPDATER_REGISTER_PTR_PARAMETER(const LinOp, residual);
GKO_UPDATER_REGISTER_PTR_PARAMETER(const LinOp, residual_norm);
Expand Down
22 changes: 22 additions & 0 deletions test/stop/residual_norm_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ class ResidualNorm : public CommonTestFixture {
TYPED_TEST_SUITE(ResidualNorm, gko::test::ValueTypes, TypenameNameGenerator);


TYPED_TEST(ResidualNorm, CanIgorneResidualNorm)
{
using Mtx = typename TestFixture::Mtx;
using NormVector = typename TestFixture::NormVector;
auto initial_res = gko::initialize<Mtx>({100.0}, this->exec);
std::shared_ptr<gko::LinOp> rhs = gko::initialize<Mtx>({10.0}, this->exec);
auto criterion =
this->factory->generate(nullptr, rhs, nullptr, initial_res.get());
constexpr gko::uint8 RelativeStoppingId{1};
bool one_changed{};
gko::array<gko::stopping_status> stop_status(this->ref, 1);
stop_status.get_data()[0].reset();
stop_status.set_executor(this->exec);

ASSERT_THROW(criterion->update().check(RelativeStoppingId, true,
&stop_status, &one_changed),
gko::NotSupported);
ASSERT_NO_THROW(criterion->update().ignore_residual_check(true).check(
RelativeStoppingId, true, &stop_status, &one_changed));
}


TYPED_TEST(ResidualNorm, WaitsTillResidualGoal)
{
using Mtx = typename TestFixture::Mtx;
Expand Down

0 comments on commit 23dc74a

Please sign in to comment.