Skip to content

Commit

Permalink
Add multiprecision tests for the new parilu tests and prefix_sum.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcojean committed Jan 23, 2020
1 parent 12bac51 commit c443835
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
13 changes: 10 additions & 3 deletions omp/test/components/prefix_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <ginkgo/core/base/array.hpp>


#include <core/test/utils.hpp>


namespace {


template <typename T>
class PrefixSum : public ::testing::Test {
protected:
using index_type = gko::int32;
using index_type = T;
PrefixSum()
: ref(gko::ReferenceExecutor::create()),
exec(gko::OmpExecutor::create()),
Expand Down Expand Up @@ -84,10 +88,13 @@ class PrefixSum : public ::testing::Test {
};


TEST_F(PrefixSum, SmallEqualsReference) { test(100); }
TYPED_TEST_CASE(PrefixSum, gko::test::IndexTypes);


TYPED_TEST(PrefixSum, SmallEqualsReference) { this->test(100); }


TEST_F(PrefixSum, BigEqualsReference) { test(total_size); }
TYPED_TEST(PrefixSum, BigEqualsReference) { this->test(this->total_size); }


} // namespace
16 changes: 12 additions & 4 deletions reference/test/components/prefix_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <gtest/gtest.h>


#include <core/test/utils.hpp>


namespace {


template <typename T>
class PrefixSum : public ::testing::Test {
protected:
using index_type = gko::int32;
using index_type = T;
PrefixSum()
: exec(gko::ReferenceExecutor::create()),
vals{3, 5, 6, 7, 1, 5, 9, 7, 2, 0, 5},
Expand All @@ -59,11 +63,15 @@ class PrefixSum : public ::testing::Test {
};


TEST_F(PrefixSum, Works)
TYPED_TEST_CASE(PrefixSum, gko::test::IndexTypes);


TYPED_TEST(PrefixSum, Works)
{
gko::kernels::reference::prefix_sum(exec, vals.data(), vals.size());
gko::kernels::reference::prefix_sum(this->exec, this->vals.data(),
this->vals.size());

ASSERT_EQ(vals, expected);
ASSERT_EQ(this->vals, this->expected);
}


Expand Down
45 changes: 26 additions & 19 deletions reference/test/factorization/par_ilu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,22 @@ TYPED_TEST(ParIlu, KernelInitializeRowPtrsLU)
}


TEST_F(ParIlu, KernelInitializeRowPtrsLUZeroMatrix)
TYPED_TEST(ParIlu, KernelInitializeRowPtrsLUZeroMatrix)
{
auto empty_csr_l_expected = Csr::create(ref);
identity->convert_to(gko::lend(empty_csr_l_expected));
auto empty_csr_u_expected = Csr::create(ref);
identity->convert_to(gko::lend(empty_csr_u_expected));
auto num_row_ptrs = empty_csr->get_size()[0] + 1;
using Csr = typename TestFixture::Csr;
using index_type = typename TestFixture::index_type;
auto empty_csr_l_expected = Csr::create(this->ref);
this->identity->convert_to(gko::lend(empty_csr_l_expected));
auto empty_csr_u_expected = Csr::create(this->ref);
this->identity->convert_to(gko::lend(empty_csr_u_expected));
auto num_row_ptrs = this->empty_csr->get_size()[0] + 1;
std::vector<index_type> l_row_ptrs_vector(num_row_ptrs);
std::vector<index_type> u_row_ptrs_vector(num_row_ptrs);
auto l_row_ptrs = l_row_ptrs_vector.data();
auto u_row_ptrs = u_row_ptrs_vector.data();

gko::kernels::reference::par_ilu_factorization::initialize_row_ptrs_l_u(
ref, gko::lend(empty_csr), l_row_ptrs, u_row_ptrs);
this->ref, gko::lend(this->empty_csr), l_row_ptrs, u_row_ptrs);

ASSERT_TRUE(std::equal(l_row_ptrs, l_row_ptrs + num_row_ptrs,
empty_csr_l_expected->get_const_row_ptrs()));
Expand All @@ -243,6 +245,7 @@ TYPED_TEST(ParIlu, KernelInitializeLU)
using Dense = typename TestFixture::Dense;
using Csr = typename TestFixture::Csr;
using index_type = typename TestFixture::index_type;
using value_type = typename TestFixture::value_type;
// clang-format off
auto expected_l =
gko::initialize<Dense>({{1., 0., 0.},
Expand All @@ -266,23 +269,26 @@ TYPED_TEST(ParIlu, KernelInitializeLU)
this->ref, gko::lend(this->mtx_csr_small), gko::lend(actual_l),
gko::lend(actual_u));

GKO_ASSERT_MTX_NEAR(actual_l, expected_l, 1e-14);
GKO_ASSERT_MTX_NEAR(actual_u, expected_u, 1e-14);
GKO_ASSERT_MTX_NEAR(actual_l, expected_l, r<value_type>::value);
GKO_ASSERT_MTX_NEAR(actual_u, expected_u, r<value_type>::value);
}


TEST_F(ParIlu, KernelInitializeLUZeroMatrix)
TYPED_TEST(ParIlu, KernelInitializeLUZeroMatrix)
{
auto actual_l = Csr::create(ref);
auto actual_u = Csr::create(ref);
actual_l->copy_from(identity.get());
actual_u->copy_from(identity.get());
using Csr = typename TestFixture::Csr;
using value_type = typename TestFixture::value_type;
auto actual_l = Csr::create(this->ref);
auto actual_u = Csr::create(this->ref);
actual_l->copy_from(this->identity.get());
actual_u->copy_from(this->identity.get());

gko::kernels::reference::par_ilu_factorization::initialize_l_u(
ref, gko::lend(empty_csr), gko::lend(actual_l), gko::lend(actual_u));
this->ref, gko::lend(this->empty_csr), gko::lend(actual_l),
gko::lend(actual_u));

GKO_ASSERT_MTX_NEAR(actual_l, identity, 1e-14);
GKO_ASSERT_MTX_NEAR(actual_u, identity, 1e-14);
GKO_ASSERT_MTX_NEAR(actual_l, this->identity, r<value_type>::value);
GKO_ASSERT_MTX_NEAR(actual_u, this->identity, r<value_type>::value);
}


Expand All @@ -291,6 +297,7 @@ TYPED_TEST(ParIlu, KernelComputeLU)
using Dense = typename TestFixture::Dense;
using Coo = typename TestFixture::Coo;
using Csr = typename TestFixture::Csr;
using value_type = typename TestFixture::value_type;
// clang-format off
auto l_dense =
gko::initialize<Dense>({{1., 0., 0.},
Expand Down Expand Up @@ -319,8 +326,8 @@ TYPED_TEST(ParIlu, KernelComputeLU)
this->ref, iterations, gko::lend(mtx_coo), gko::lend(l_csr),
gko::lend(u_csr));

GKO_ASSERT_MTX_NEAR(l_csr, this->small_l_expected, 1e-14);
GKO_ASSERT_MTX_NEAR(u_csr, u_expected, 1e-14);
GKO_ASSERT_MTX_NEAR(l_csr, this->small_l_expected, r<value_type>::value);
GKO_ASSERT_MTX_NEAR(u_csr, u_expected, r<value_type>::value);
}


Expand Down

0 comments on commit c443835

Please sign in to comment.