Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
- remove additional .on(...) calls
- add tests for old functionality
- add assertions for dynamic type

Co-authored-by: Pratik Nayak <pratik.nayak@kit.edu>
  • Loading branch information
upsj and pratikvn committed Oct 6, 2023
1 parent 1c3a4b7 commit 654ef6e
Show file tree
Hide file tree
Showing 25 changed files with 675 additions and 343 deletions.
13 changes: 13 additions & 0 deletions core/test/mpi/distributed/preconditioner/schwarz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,17 @@ TYPED_TEST(SchwarzFactory, CanBeCleared)
}


TYPED_TEST(SchwarzFactory, PassExplicitFactory)
{
using Jacobi = typename TestFixture::Jacobi;
using Schwarz = typename TestFixture::Schwarz;
auto jacobi_factory = gko::share(Jacobi::build().on(this->exec));

auto factory =
Schwarz::build().with_local_solver(jacobi_factory).on(this->exec);

ASSERT_EQ(factory->get_parameters().local_solver, jacobi_factory);
}


} // namespace
41 changes: 41 additions & 0 deletions core/test/preconditioner/ic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/preconditioner/ic.hpp>


#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 5211, 4973, 4974)
#endif


#include <memory>


Expand All @@ -44,6 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/solver/bicgstab.hpp>


#include "core/test/utils.hpp"


namespace {


Expand Down Expand Up @@ -95,4 +109,31 @@ TEST_F(IcFactory, CanSetFactorizationFactory)
}


TEST_F(IcFactory, DeprecatedFactoryParameter)
{
auto ilu_factory = ic_prec_type::build()
.with_l_solver_factory(this->l_factory)
.with_factorization_factory(this->fact_factory)
.on(this->exec);

ASSERT_EQ(ilu_factory->get_parameters().l_solver_factory, this->l_factory);
ASSERT_EQ(ilu_factory->get_parameters().factorization_factory,
this->fact_factory);
}


TEST_F(IcFactory, DeferredFactoryParameter)
{
auto ic_factory = ic_prec_type::build()
.with_l_solver(solver_type::build())
.with_factorization(ic_type::build())
.on(this->exec);

GKO_ASSERT_DYNAMIC_TYPE(ic_factory->get_parameters().l_solver_factory,
solver_type::Factory);
GKO_ASSERT_DYNAMIC_TYPE(ic_factory->get_parameters().factorization_factory,
ic_type::Factory);
}


} // namespace
46 changes: 46 additions & 0 deletions core/test/preconditioner/ilu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/preconditioner/ilu.hpp>


#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 5211, 4973, 4974)
#endif


#include <memory>


Expand All @@ -44,6 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/solver/bicgstab.hpp>


#include "core/test/utils.hpp"


namespace {


Expand Down Expand Up @@ -108,4 +122,36 @@ TEST_F(IluFactory, CanSetFactorizationFactory)
}


TEST_F(IluFactory, DeprecatedFactoryParameter)
{
auto ilu_factory = ilu_prec_type::build()
.with_l_solver_factory(this->l_factory)
.with_u_solver_factory(this->u_factory)
.with_factorization_factory(this->fact_factory)
.on(this->exec);

ASSERT_EQ(ilu_factory->get_parameters().l_solver_factory, this->l_factory);
ASSERT_EQ(ilu_factory->get_parameters().u_solver_factory, this->u_factory);
ASSERT_EQ(ilu_factory->get_parameters().factorization_factory,
this->fact_factory);
}


TEST_F(IluFactory, DeferredFactoryParameter)
{
auto ilu_factory = ilu_prec_type::build()
.with_l_solver(l_solver_type::build())
.with_u_solver(u_solver_type::build())
.with_factorization(ilu_type::build())
.on(this->exec);

GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().l_solver_factory,
l_solver_type::Factory);
GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().u_solver_factory,
u_solver_type::Factory);
GKO_ASSERT_DYNAMIC_TYPE(ilu_factory->get_parameters().factorization_factory,
ilu_type::Factory);
}


} // namespace
1 change: 1 addition & 0 deletions core/test/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ginkgo_create_test(bicg)
ginkgo_create_test(bicgstab)
ginkgo_create_test(cg)
ginkgo_create_test(cgs)
ginkgo_create_test(direct)
ginkgo_create_test(fcg)
ginkgo_create_test(gcr)
ginkgo_create_test(gmres)
Expand Down
35 changes: 23 additions & 12 deletions core/test/solver/bicg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,12 @@ TYPED_TEST(Bicg, CanSetPreconditionerGenerator)
using value_type = typename TestFixture::value_type;
auto bicg_factory =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(this->exec),
gko::stop::ResidualNorm<value_type>::build()
.with_reduction_factor(
gko::remove_complex<value_type>(1e-6))
.on(this->exec))
.with_preconditioner(
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(
this->exec))
.on(this->exec))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u),
gko::stop::ResidualNorm<value_type>::build()
.with_reduction_factor(
gko::remove_complex<value_type>(1e-6)))
.with_preconditioner(Solver::build().with_criteria(
gko::stop::Iteration::build().with_max_iters(3u)))
.on(this->exec);
auto solver = bicg_factory->generate(this->mtx);
auto precond = dynamic_cast<const gko::solver::Bicg<value_type>*>(
Expand Down Expand Up @@ -291,4 +285,21 @@ TYPED_TEST(Bicg, CanSetPreconditioner)
}


TYPED_TEST(Bicg, PassExplicitFactory)
{
using Solver = typename TestFixture::Solver;
auto stop_factory = gko::share(
gko::stop::Iteration::build().with_max_iters(1u).on(this->exec));
auto precond_factory = gko::share(Solver::build().on(this->exec));

auto factory = Solver::build()
.with_criteria(stop_factory)
.with_preconditioner(precond_factory)
.on(this->exec);

ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory);
ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory);
}


} // namespace
46 changes: 26 additions & 20 deletions core/test/solver/bicgstab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,9 @@ TYPED_TEST(Bicgstab, CanSetPreconditionerGenerator)
using value_type = typename TestFixture::value_type;
auto bicgstab_factory =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_preconditioner(
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u).on(
this->exec))
)
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.with_preconditioner(Solver::build().with_criteria(
gko::stop::Iteration::build().with_max_iters(3u)))
.on(this->exec);

auto solver = bicgstab_factory->generate(this->mtx);
Expand Down Expand Up @@ -207,15 +202,13 @@ TYPED_TEST(Bicgstab, CanSetPreconditionerInFactory)
using Solver = typename TestFixture::Solver;
std::shared_ptr<Solver> bicgstab_precond =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec)
->generate(this->mtx);

auto bicgstab_factory =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.with_generated_preconditioner(bicgstab_precond)
.on(this->exec);
auto solver = bicgstab_factory->generate(this->mtx);
Expand All @@ -234,15 +227,13 @@ TYPED_TEST(Bicgstab, ThrowsOnWrongPreconditionerInFactory)
Mtx::create(this->exec, gko::dim<2>{2, 2});
std::shared_ptr<Solver> bicgstab_precond =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec)
->generate(wrong_sized_mtx);

auto bicgstab_factory =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.with_generated_preconditioner(bicgstab_precond)
.on(this->exec);

Expand All @@ -267,15 +258,13 @@ TYPED_TEST(Bicgstab, CanSetPreconditioner)
using Solver = typename TestFixture::Solver;
std::shared_ptr<Solver> bicgstab_precond =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec)
->generate(this->mtx);

auto bicgstab_factory =
Solver::build()
.with_criteria(
gko::stop::Iteration::build().with_max_iters(3u))
.with_criteria(gko::stop::Iteration::build().with_max_iters(3u))
.on(this->exec);
auto solver = bicgstab_factory->generate(this->mtx);
solver->set_preconditioner(bicgstab_precond);
Expand All @@ -286,4 +275,21 @@ TYPED_TEST(Bicgstab, CanSetPreconditioner)
}


TYPED_TEST(Bicgstab, PassExplicitFactory)
{
using Solver = typename TestFixture::Solver;
auto stop_factory = gko::share(
gko::stop::Iteration::build().with_max_iters(1u).on(this->exec));
auto precond_factory = gko::share(Solver::build().on(this->exec));

auto factory = Solver::build()
.with_criteria(stop_factory)
.with_preconditioner(precond_factory)
.on(this->exec);

ASSERT_EQ(factory->get_parameters().criteria.front(), stop_factory);
ASSERT_EQ(factory->get_parameters().preconditioner, precond_factory);
}


} // namespace
Loading

0 comments on commit 654ef6e

Please sign in to comment.