[Numpy-svn] r5881 - branches/clean_math_config_chuck/numpy/core/src

numpy-svn@scip... numpy-svn@scip...
Mon Sep 29 21:03:03 CDT 2008


Author: charris
Date: 2008-09-29 21:03:00 -0500 (Mon, 29 Sep 2008)
New Revision: 5881

Modified:
   branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src
Log:
Work in Progress

Modified: branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src	2008-09-29 20:24:56 UTC (rev 5880)
+++ branches/clean_math_config_chuck/numpy/core/src/umathmodule.c.src	2008-09-30 02:03:00 UTC (rev 5881)
@@ -815,7 +815,7 @@
 {
     UNARY_LOOP {
         const @type@ in1 = *(@type@ *)ip1;
-        *((@type@ *)op) = (in1 > 0) ? in1 : -in1;
+        *((@type@ *)op) = (in1 >= 0) ? in1 : -in1;
     }
 }
 
@@ -970,6 +970,15 @@
     }
 }
 
+static void
+@TYPE@_logical_not(char **args, intp *dimensions, intp *steps, void *func)
+{
+    UNARY_LOOP {
+        const @type@ in1 = *(@type@ *)ip1;
+        *((Bool *)op) = !in1;
+    }
+}
+
 /**begin repeat1
  * #kind = isnan, isinf, isfinite, signbit#
  * #func = isnan, isinf, isfinite, signbit#
@@ -986,15 +995,25 @@
 
 /**begin repeat1
  * #kind = maximum, minimum#
- * #OP =  >, <#
+ * #OP1 =  >=, <=#
+ * #OP2 =  <=, >=#
  **/
 static void
 @TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)
 {
+    /* Return NaN if either value is NaN */
     BINARY_LOOP {
         const @type@ in1 = *(@type@ *)ip1;
         const @type@ in2 = *(@type@ *)ip2;
-        *((@type@ *)op) = (in1 @OP@ in2) ? in1 : in2;
+        if (in1 @OP1@ in2) {
+            *((@type@ *)op) = in1;
+        }
+        else if (in1 @OP2@ in2) {
+            *((@type@ *)op) = in2;
+        }
+        else {
+            *((@type@ *)op) = NAN;
+        }
     }
 }
 /**end repeat1**/
@@ -1065,7 +1084,9 @@
 {
     UNARY_LOOP {
         const @type@ in1 = *(@type@ *)ip1;
-        *((@type@ *)op) = (in1 < 0) ? -in1 : in1;
+        const @type@ tmp = (in1 > 0) ? in1 : -in1;
+        /* add 0 to clear -0.0 */
+        *((@type@ *)op) = tmp + 0;
     }
 }
 
@@ -1079,20 +1100,24 @@
 }
 
 static void
-@TYPE@_logical_not(char **args, intp *dimensions, intp *steps, void *func)
-{
-    UNARY_LOOP {
-        const @type@ in1 = *(@type@ *)ip1;
-        *((Bool *)op) = !in1;
-    }
-}
-
-static void
 @TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)
 {
+    /* Returns NaN as sign of NaN */
     UNARY_LOOP {
         const @type@ in1 = *(@type@ *)ip1;
-        *((@type@ *)op) = in1 > 0 ? 1 : (in1 < 0 ? -1 : 0);
+        if (in1 > 0) {
+            *((@type@ *)op) = 1;
+        }
+        else if (in1 < 0) {
+            *((@type@ *)op) = -1;
+        }
+        else if (in1 == 0) {
+            *((@type@ *)op) = 0;
+        }
+        else {
+            /* is NaN */
+            *((@type@ *)op) = in1;
+        }
     }
 }
 



More information about the Numpy-svn mailing list