[arrayfire] 46/408: TEST: Refactor reduce tests. Test intl/uintl

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.

commit 16b4c0a33675ba998054b5ca78c92d60a927fa26
Author: Umar Arshad <umar at arrayfire.com>
Date:   Thu Jun 25 22:58:11 2015 -0400

    TEST: Refactor reduce tests. Test intl/uintl
---
 test/reduce.cpp | 119 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 59 insertions(+), 60 deletions(-)

diff --git a/test/reduce.cpp b/test/reduce.cpp
index 3919920..5d30e81 100644
--- a/test/reduce.cpp
+++ b/test/reduce.cpp
@@ -30,7 +30,7 @@ class Reduce : public ::testing::Test
 {
 };
 
-typedef ::testing::Types<float, double, af::cfloat, af::cdouble, uint, int, char, uchar> TestTypes;
+typedef ::testing::Types<float, double, af::cfloat, af::cdouble, uint, int, intl, uintl, uchar> TestTypes;
 TYPED_TEST_CASE(Reduce, TestTypes);
 
 typedef af_err (*reduceFunc)(af_array *, const af_array, const int);
@@ -71,23 +71,40 @@ void reduceTest(string pTestFile, int off = 0, bool isSubRef=false, const vector
         // Run sum
         ASSERT_EQ(AF_SUCCESS, af_reduce(&outArray, inArray, d + off));
 
+        af_dtype t;
+        af_get_type(&t, outArray);
+
         // Get result
         To *outData;
         outData = new To[dims.elements()];
         ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)outData, outArray));
 
         size_t nElems = currGoldBar.size();
-        for (size_t elIter = 0; elIter < nElems; ++elIter) {
-            ASSERT_EQ(currGoldBar[elIter], outData[elIter]) << "at: " << elIter
-                                                            << " for dim " << d + off << std::endl;
+        if(std::equal(currGoldBar.begin(), currGoldBar.end(), outData) == false)
+        {
+            for (size_t elIter = 0; elIter < nElems; ++elIter) {
+
+                EXPECT_EQ(currGoldBar[elIter], outData[elIter]) << "at: " << elIter
+                                                                << " for dim " << d + off << std::endl;
+            }
+            af_print_array(outArray);
+            for(int i = 0; i < nElems; i++) {
+                cout << currGoldBar[i] << ", ";
+            }
+
+            cout << endl;
+            for(int i = 0; i < nElems; i++) {
+                cout << outData[i] << ", ";
+            }
+            FAIL();
         }
 
+
         // Delete
         delete[] outData;
         ASSERT_EQ(AF_SUCCESS, af_release_array(outArray));
     }
 
-
     ASSERT_EQ(AF_SUCCESS, af_release_array(inArray));
 }
 
@@ -101,61 +118,43 @@ vector<af_seq> init_subs()
     return subs;
 }
 
-#define REDUCE_TESTS(FN, TAG, Ti, To)                   \
-    TEST(Reduce,Test_##FN##_##TAG)                      \
-    {                                                   \
-        reduceTest<Ti, To, af_##FN>(                    \
-            string(TEST_DIR"/reduce/"#FN".test")        \
-            );                                          \
-    }                                                   \
-
-REDUCE_TESTS(sum, float   , float     , float     );
-REDUCE_TESTS(sum, double  , double    , double    );
-REDUCE_TESTS(sum, int     , int       , int       );
-REDUCE_TESTS(sum, cfloat  , cfloat , cfloat );
-REDUCE_TESTS(sum, cdouble , cdouble, cdouble);
-REDUCE_TESTS(sum, unsigned, unsigned  , unsigned  );
-REDUCE_TESTS(sum, uchar   , unsigned char, unsigned);
-
-REDUCE_TESTS(min, float   , float     , float     );
-REDUCE_TESTS(min, double  , double    , double    );
-REDUCE_TESTS(min, int     , int       , int       );
-REDUCE_TESTS(min, cfloat  , cfloat , cfloat );
-REDUCE_TESTS(min, cdouble , cdouble, cdouble);
-REDUCE_TESTS(min, unsigned, unsigned  , unsigned  );
-REDUCE_TESTS(min, uchar   , unsigned char, unsigned char);
-
-REDUCE_TESTS(max, float   , float     , float     );
-REDUCE_TESTS(max, double  , double    , double    );
-REDUCE_TESTS(max, int     , int       , int       );
-REDUCE_TESTS(max, cfloat  , cfloat , cfloat );
-REDUCE_TESTS(max, cdouble , cdouble, cdouble);
-REDUCE_TESTS(max, unsigned, unsigned  , unsigned  );
-REDUCE_TESTS(max, uchar   , unsigned char, unsigned char);
-
-REDUCE_TESTS(any_true, float   , float     , unsigned char);
-REDUCE_TESTS(any_true, double  , double    , unsigned char);
-REDUCE_TESTS(any_true, int     , int       , unsigned char);
-REDUCE_TESTS(any_true, cfloat  , cfloat , unsigned char);
-REDUCE_TESTS(any_true, cdouble , cdouble, unsigned char);
-REDUCE_TESTS(any_true, unsigned, unsigned  , unsigned char);
-REDUCE_TESTS(any_true, uchar   , unsigned char, unsigned char);
-
-REDUCE_TESTS(all_true, float   , float     , unsigned char);
-REDUCE_TESTS(all_true, double  , double    , unsigned char);
-REDUCE_TESTS(all_true, int     , int       , unsigned char);
-REDUCE_TESTS(all_true, cfloat  , cfloat , unsigned char);
-REDUCE_TESTS(all_true, cdouble , cdouble, unsigned char);
-REDUCE_TESTS(all_true, unsigned, unsigned  , unsigned char);
-REDUCE_TESTS(all_true, uchar   , unsigned char, unsigned char);
-
-REDUCE_TESTS(count, float   , float     , unsigned);
-REDUCE_TESTS(count, double  , double    , unsigned);
-REDUCE_TESTS(count, int     , int       , unsigned);
-REDUCE_TESTS(count, cfloat  , cfloat , unsigned);
-REDUCE_TESTS(count, cdouble , cdouble, unsigned);
-REDUCE_TESTS(count, unsigned, unsigned  , unsigned);
-REDUCE_TESTS(count, uchar   , unsigned char, unsigned);
+template<typename T,reduceFunc OP>
+struct promote_type {
+    typedef T type;
+};
+
+// char and uchar are promoted to int for sum and product
+template<> struct promote_type<uchar, af_sum>       { typedef uint type; };
+template<> struct promote_type<char , af_sum>       { typedef uint type; };
+template<> struct promote_type<uchar, af_product>   { typedef uint type; };
+template<> struct promote_type<char , af_product>   { typedef uint type; };
+
+#define REDUCE_TESTS(FN)                                                                    \
+    TYPED_TEST(Reduce,Test_##FN)                                                    \
+    {                                                                                       \
+        reduceTest<TypeParam, typename promote_type<TypeParam, af_##FN>::type, af_##FN>(    \
+            string(TEST_DIR"/reduce/"#FN".test")                                            \
+            );                                                                              \
+    }                                                                                       \
+
+REDUCE_TESTS(sum);
+REDUCE_TESTS(min);
+REDUCE_TESTS(max);
+
+#undef REDUCE_TESTS
+#define REDUCE_TESTS(FN, OT)                        \
+    TYPED_TEST(Reduce,Test_##FN)            \
+    {                                               \
+        reduceTest<TypeParam, OT, af_##FN>(         \
+            string(TEST_DIR"/reduce/"#FN".test")    \
+            );                                      \
+    }                                               \
+
+REDUCE_TESTS(any_true, unsigned char);
+REDUCE_TESTS(all_true, unsigned char);
+REDUCE_TESTS(count, unsigned);
+
+#undef REDUCE_TESTS
 
 TEST(Reduce,Test_Reduce_Big0)
 {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list