[arrayfire] 89/408: TEST: Adding tests for reductions when using NaNs

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:25 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 248de68764324dd7ee415ad295dfbcaceb1698fe
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Thu Jul 2 15:46:43 2015 -0400

    TEST: Adding tests for reductions when using NaNs
---
 test/reduce.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 89 insertions(+)

diff --git a/test/reduce.cpp b/test/reduce.cpp
index 49200b4..ad99430 100644
--- a/test/reduce.cpp
+++ b/test/reduce.cpp
@@ -433,3 +433,92 @@ TYPED_TEST(Reduce, Test_Any_Global)
         h_vals[i] = false;
     }
 }
+
+TEST(MinMax, NaN)
+{
+    const int num = 10000;
+    af::array A = af::randu(num);
+    A(where(A < 0.25)) = af::NaN;
+
+    float minval = af::min<float>(A);
+    float maxval = af::max<float>(A);
+
+    ASSERT_NE(std::isnan(minval), true);
+    ASSERT_NE(std::isnan(maxval), true);
+
+    float *h_A = A.host<float>();
+
+    for (int i = 0; i < num; i++) {
+        if (!std::isnan(h_A[i])) {
+            ASSERT_LE(minval, h_A[i]);
+            ASSERT_GE(maxval, h_A[i]);
+        }
+    }
+}
+
+TEST(Count, NaN)
+{
+    const int num = 10000;
+    af::array A = af::round(5 * af::randu(num));
+    af::array B = A;
+
+    A(where(A == 2)) = af::NaN;
+
+    ASSERT_EQ(af::count<uint>(A), af::count<uint>(B));
+}
+
+TEST(Sum, NaN)
+{
+    const int num = 10000;
+    af::array A = af::randu(num);
+    A(where(A < 0.25)) = af::NaN;
+
+    float res = af::sum<float>(A);
+
+    ASSERT_EQ(std::isnan(res), true);
+
+    res = af::sum<float>(A, 0);
+    float *h_A = A.host<float>();
+
+    float tmp = 0;
+    for (int i = 0; i < num; i++) {
+        tmp += std::isnan(h_A[i]) ? 0 : h_A[i];
+    }
+
+    ASSERT_NEAR(res/num, tmp/num, 1E-5);
+}
+
+TEST(Product, NaN)
+{
+    const int num = 5;
+    af::array A = af::randu(num);
+    A(2) = af::NaN;
+
+    float res = af::product<float>(A);
+
+    ASSERT_EQ(std::isnan(res), true);
+
+    res = af::product<float>(A, 1);
+    float *h_A = A.host<float>();
+
+    float tmp = 1;
+    for (int i = 0; i < num; i++) {
+        tmp *= std::isnan(h_A[i]) ? 1 : h_A[i];
+    }
+
+    ASSERT_NEAR(res/num, tmp/num, 1E-5);
+}
+
+TEST(AnyAll, NaN)
+{
+    const int num = 10000;
+    af::array A = (af::randu(num) > 0.5).as(f32);
+    af::array B = A;
+
+    B(af::where(B == 0)) = af::NaN;
+
+    ASSERT_EQ(af::anyTrue<bool>(B), true);
+    ASSERT_EQ(af::allTrue<bool>(B), true);
+    ASSERT_EQ(af::anyTrue<bool>(A), true);
+    ASSERT_EQ(af::allTrue<bool>(A), false);
+}

-- 
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