[arrayfire] 65/408: BUGFIX: Ignoring NaN values in min and max for all backends

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:17 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 3ebc19e33147691affffd27457e1eb92d04ed450
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Jun 30 12:58:43 2015 -0400

    BUGFIX: Ignoring NaN values in min and max for all backends
---
 src/api/c/ops.hpp                | 21 +++++++++++++++++++++
 src/backend/opencl/kernel/ops.cl |  8 ++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/api/c/ops.hpp b/src/api/c/ops.hpp
index a94b984..b6e5422 100644
--- a/src/api/c/ops.hpp
+++ b/src/api/c/ops.hpp
@@ -19,6 +19,9 @@
 
 using namespace detail;
 
+// Because isnan(cfloat) and isnan(cdouble) is not defined
+#define IS_NAN(val) !((val) == (val))
+
 template<typename T, af_op_t op>
 struct Binary
 {
@@ -233,6 +236,24 @@ struct Transform
 };
 
 template<typename Ti, typename To>
+struct Transform<Ti, To, af_min_t>
+{
+    __DH__ To operator ()(Ti in)
+    {
+        return (To) (IS_NAN(in) ? Binary<To, af_min_t>().init() : in);
+    }
+};
+
+template<typename Ti, typename To>
+struct Transform<Ti, To, af_max_t>
+{
+    __DH__ To operator ()(Ti in)
+    {
+        return (To) (IS_NAN(in) ? Binary<To, af_max_t>().init() : in);
+    }
+};
+
+template<typename Ti, typename To>
 struct Transform<Ti, To, af_or_t>
 {
     __DH__ To operator ()(Ti in)
diff --git a/src/backend/opencl/kernel/ops.cl b/src/backend/opencl/kernel/ops.cl
index f81195a..93313c6 100644
--- a/src/backend/opencl/kernel/ops.cl
+++ b/src/backend/opencl/kernel/ops.cl
@@ -7,6 +7,8 @@
  * http://arrayfire.com/licenses/BSD-3-Clause
  ********************************************************/
 
+#define IS_NAN(in) !((in) == (in))
+
 #ifdef ADD_OP
 T binOp(T lhs, T rhs)
 {
@@ -102,7 +104,8 @@ uint transform(Ti in)
 
 T transform(T in)
 {
-    return in;
+    T val = init;
+    return IS_NAN(in) ? (val) : (in);
 }
 
 #if CPLX
@@ -121,7 +124,8 @@ T binOp(T lhs, T rhs)
 
 T transform(T in)
 {
-    return in;
+    T val = init;
+    return IS_NAN(in) ? (val) : (in);
 }
 
 #if CPLX

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