From e83a38bded41b58f370927e90261081fa1809354 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Wed, 21 Apr 2021 09:18:51 -0400 Subject: [PATCH 1/2] test/reductions: start using a typed testsuite Actually, my goal was to include tests for complex numbers, but that doesn't appear to be as straightforward as I was hoping... --- tests/test_reductions.cxx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_reductions.cxx b/tests/test_reductions.cxx index 12f6a58e..de28d35e 100644 --- a/tests/test_reductions.cxx +++ b/tests/test_reductions.cxx @@ -1,5 +1,6 @@ #include +#include #include #include @@ -9,18 +10,28 @@ using namespace gt::placeholders; -TEST(reductions, sum_axis_to_2d) +template +class Reductions : public testing::Test +{}; + +// FIXME, would be nice to test gt::complex, too, but that doesn't +// compile right now +using number_types = ::testing::Types; +TYPED_TEST_SUITE(Reductions, number_types); + +TYPED_TEST(Reductions, sum_axis_to_2d) { - gt::gtensor a({{11., 21., 31.}, {12., 22., 32.}}); + using T = TypeParam; + gt::gtensor a({{11., 21., 31.}, {12., 22., 32.}}); GT_DEBUG_VAR(a.shape()); - gt::gtensor asum0(gt::shape(2)); - gt::gtensor asum1(gt::shape(3)); + gt::gtensor asum0(gt::shape(2)); + gt::gtensor asum1(gt::shape(3)); sum_axis_to(asum0, a, 0); - EXPECT_EQ(asum0, (gt::gtensor{63., 66.})); + EXPECT_EQ(asum0, (gt::gtensor{63., 66.})); sum_axis_to(asum1, a, 1); - EXPECT_EQ(asum1, (gt::gtensor{23., 43., 63.})); + EXPECT_EQ(asum1, (gt::gtensor{23., 43., 63.})); } TEST(reductions, sum_axis_to_2d_view) From be773323ef96866aa0e7badafedece7927252045 Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Wed, 21 Apr 2021 09:28:58 -0400 Subject: [PATCH 2/2] test/reductions: unify host and device tests --- tests/test_reductions.cxx | 52 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/tests/test_reductions.cxx b/tests/test_reductions.cxx index de28d35e..4fc7fa39 100644 --- a/tests/test_reductions.cxx +++ b/tests/test_reductions.cxx @@ -10,28 +10,44 @@ using namespace gt::placeholders; -template +template +struct reductions_config +{ + using value_type = T; + using space_type = S; +}; + +template class Reductions : public testing::Test {}; // FIXME, would be nice to test gt::complex, too, but that doesn't // compile right now -using number_types = ::testing::Types; -TYPED_TEST_SUITE(Reductions, number_types); +using reduction_configs = + ::testing::Types, + reductions_config +#ifdef GTENSOR_HAVE_DEVICE + , + reductions_config, + reductions_config +#endif + >; +TYPED_TEST_SUITE(Reductions, reduction_configs); TYPED_TEST(Reductions, sum_axis_to_2d) { - using T = TypeParam; - gt::gtensor a({{11., 21., 31.}, {12., 22., 32.}}); + using T = typename TypeParam::value_type; + using S = typename TypeParam::space_type; + gt::gtensor a({{11., 21., 31.}, {12., 22., 32.}}); GT_DEBUG_VAR(a.shape()); - gt::gtensor asum0(gt::shape(2)); - gt::gtensor asum1(gt::shape(3)); + gt::gtensor asum0(gt::shape(2)); + gt::gtensor asum1(gt::shape(3)); sum_axis_to(asum0, a, 0); - EXPECT_EQ(asum0, (gt::gtensor{63., 66.})); + EXPECT_EQ(asum0, (gt::gtensor{63., 66.})); sum_axis_to(asum1, a, 1); - EXPECT_EQ(asum1, (gt::gtensor{23., 43., 63.})); + EXPECT_EQ(asum1, (gt::gtensor{23., 43., 63.})); } TEST(reductions, sum_axis_to_2d_view) @@ -73,24 +89,6 @@ TEST(reductions, sum_axis_to_3d_view_2d) #ifdef GTENSOR_HAVE_DEVICE -TEST(reductions, device_sum_axis_to_2d) -{ - gt::gtensor_device a({{11., 21., 31.}, {12., 22., 32.}}); - GT_DEBUG_VAR(a.shape()); - - gt::gtensor_device asum0(gt::shape(2)); - gt::gtensor_device asum1(gt::shape(3)); - gt::gtensor h_asum0(gt::shape(2)); - gt::gtensor h_asum1(gt::shape(3)); - - sum_axis_to(asum0, a, 0); - gt::copy(asum0, h_asum0); - EXPECT_EQ(h_asum0, (gt::gtensor{63., 66.})); - sum_axis_to(asum1, a, 1); - gt::copy(asum1, h_asum1); - EXPECT_EQ(h_asum1, (gt::gtensor{23., 43., 63.})); -} - TEST(reductions, device_sum_axis_to_3d_view_2d) { gt::gtensor_device a({{{11., 21., 31.}, {12., 22., 32.}},