Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
* make condition for printing matrices in tests more explicit
* test for preservation of triangular part in matrix_utils_test
* fix invalid parameters in solver advanced apply tests

Co-authored-by: Aditya Kashi <aditya.kashi@kit.edu>
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
  • Loading branch information
3 people committed Apr 6, 2022
1 parent 2fa1b45 commit 50f4d25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/test/utils/assertions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ::testing::AssertionResult matrices_near_impl(
<< second_expression << " is " << err << "\n"
<< "\twhich is larger than " << tolerance_expression
<< " (which is " << tolerance << ")\n";
if (num_rows * num_cols <= 25) {
if (num_rows <= 10 && num_cols <= 10) {
fail << first_expression << " is:\n";
detail::print_matrix(fail, first);
fail << second_expression << " is:\n";
Expand Down
14 changes: 12 additions & 2 deletions core/test/utils/matrix_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ TYPED_TEST(MatrixUtils, MakeHpdMatrixThrowsError)

TYPED_TEST(MatrixUtils, MakeLowerTriangularCorrectly)
{
auto orig_mtx = TestFixture::mtx_type::create(this->exec);
orig_mtx->read(this->data);
gko::test::make_lower_triangular(this->data);

auto mtx = TestFixture::mtx_type::create(this->exec);
mtx->read(this->data);
for (gko::size_type i = 0; i < mtx->get_size()[0]; i++) {
for (gko::size_type j = 0; j <= i; j++) {
ASSERT_EQ(mtx->at(i, j), orig_mtx->at(i, j));
}
for (gko::size_type j = i + 1; j < mtx->get_size()[1]; j++) {
ASSERT_EQ(mtx->at(i, j), gko::zero<TypeParam>());
}
Expand All @@ -118,6 +123,8 @@ TYPED_TEST(MatrixUtils, MakeLowerTriangularCorrectly)

TYPED_TEST(MatrixUtils, MakeUpperTriangularCorrectly)
{
auto orig_mtx = TestFixture::mtx_type::create(this->exec);
orig_mtx->read(this->data);
gko::test::make_upper_triangular(this->data);

auto mtx = TestFixture::mtx_type::create(this->exec);
Expand All @@ -126,6 +133,9 @@ TYPED_TEST(MatrixUtils, MakeUpperTriangularCorrectly)
for (gko::size_type j = 0; j < i; j++) {
ASSERT_EQ(mtx->at(i, j), gko::zero<TypeParam>());
}
for (gko::size_type j = i; j < mtx->get_size()[1]; j++) {
ASSERT_EQ(mtx->at(i, j), orig_mtx->at(i, j));
}
}
}

Expand Down Expand Up @@ -231,7 +241,7 @@ TYPED_TEST(MatrixUtils, MakeHpdMatrixCorrectly)
using T = typename TestFixture::value_type;
auto cpy_data = this->data;

gko::test::make_hpd(this->data);
gko::test::make_hpd(this->data, 1.001);
gko::test::make_hermitian(cpy_data);
gko::test::make_diag_dominant(cpy_data, 1.001);

Expand Down Expand Up @@ -266,7 +276,7 @@ TYPED_TEST(MatrixUtils, MakeSpdMatrixCorrectly)
using T = typename TestFixture::value_type;
auto cpy_data = this->data;

gko::test::make_spd(this->data);
gko::test::make_spd(this->data, 1.001);
gko::test::make_symmetric(cpy_data);
gko::test::make_diag_dominant(cpy_data, 1.001);

Expand Down
11 changes: 6 additions & 5 deletions test/solver/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ using SolverTypes =
TYPED_TEST_SUITE(Solver, SolverTypes, TypenameNameGenerator);


// The tolerances we set above don't provide any useful information for float
#if !(GINKGO_DPCPP_SINGLE_MODE)
TYPED_TEST(Solver, ApplyIsEquivalentToRef)
{
this->forall_matrix_scenarios([&](auto mtx) {
Expand All @@ -618,9 +620,9 @@ TYPED_TEST(Solver, AdvancedApplyIsEquivalentToRef)
auto alpha = this->gen_scalar();
auto beta = this->gen_scalar();

solver.ref->apply(alpha.ref.get(), b.ref.get(), alpha.ref.get(),
solver.ref->apply(alpha.ref.get(), b.ref.get(), beta.ref.get(),
x.ref.get());
solver.dev->apply(alpha.dev.get(), b.dev.get(), alpha.dev.get(),
solver.dev->apply(alpha.dev.get(), b.dev.get(), beta.dev.get(),
x.dev.get());

GKO_ASSERT_MTX_NEAR(x.ref, x.dev, this->tol(x));
Expand All @@ -630,7 +632,6 @@ TYPED_TEST(Solver, AdvancedApplyIsEquivalentToRef)
}


#if !(GINKGO_DPCPP_SINGLE_MODE)
TYPED_TEST(Solver, MixedApplyIsEquivalentToRef)
{
using MixedVec = typename TestFixture::MixedVec;
Expand Down Expand Up @@ -659,9 +660,9 @@ TYPED_TEST(Solver, MixedAdvancedApplyIsEquivalentToRef)
auto beta = this->template gen_scalar<MixedVec>();

solver.ref->apply(alpha.ref.get(), b.ref.get(),
alpha.ref.get(), x.ref.get());
beta.ref.get(), x.ref.get());
solver.dev->apply(alpha.dev.get(), b.dev.get(),
alpha.dev.get(), x.dev.get());
beta.dev.get(), x.dev.get());

GKO_ASSERT_MTX_NEAR(x.ref, x.dev, this->mixed_tol(x));
});
Expand Down

0 comments on commit 50f4d25

Please sign in to comment.