[Numpy-svn] r5955 - in branches/ufunc_cleanup/numpy/core: src tests

numpy-svn@scip... numpy-svn@scip...
Wed Oct 22 00:45:45 CDT 2008


Author: charris
Date: 2008-10-22 00:45:42 -0500 (Wed, 22 Oct 2008)
New Revision: 5955

Modified:
   branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src
   branches/ufunc_cleanup/numpy/core/tests/test_umath.py
Log:
Merge up to current trunk.

Modified: branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src	2008-10-21 20:13:17 UTC (rev 5954)
+++ branches/ufunc_cleanup/numpy/core/src/umathmodule.c.src	2008-10-22 05:45:42 UTC (rev 5955)
@@ -1440,18 +1440,14 @@
         const @type@ in1i = ((@type@ *)ip1)[1];
         const @type@ in2r = ((@type@ *)ip2)[0];
         const @type@ in2i = ((@type@ *)ip2)[1];
-        if (@OP1@(in1r, in1i, in2r, in2i)) {
+        if (@OP1@(in1r, in1i, in2r, in2i) || isnan(in1r) || isnan(in1i)) {
             ((@type@ *)op)[0] = in1r;
             ((@type@ *)op)[1] = in1i;
         }
-        else if (@OP2@(in1r, in1i, in2r, in2i)) {
+        else {
             ((@type@ *)op)[0] = in2r;
             ((@type@ *)op)[1] = in2i;
         }
-        else {
-            ((@type@ *)op)[0] = NAN;
-            ((@type@ *)op)[1] = NAN;
-        }
     }
 }
 /**end repeat1**/
@@ -1469,14 +1465,8 @@
         const @type@ in2r = ((@type@ *)ip2)[0];
         const @type@ in2i = ((@type@ *)ip2)[1];
         if (@OP1@(in1r, in1i, in2r, in2i) || isnan(in2r) || isnan(in2i)) {
-            if (isnan(in1r) || isnan(in1i)) {
-                ((@type@ *)op)[0] = NAN;
-                ((@type@ *)op)[1] = NAN;
-            }
-            else {
-                ((@type@ *)op)[0] = in1r;
-                ((@type@ *)op)[1] = in1i;
-            }
+            ((@type@ *)op)[0] = in1r;
+            ((@type@ *)op)[1] = in1i;
         }
         else {
             ((@type@ *)op)[0] = in2r;
@@ -1515,6 +1505,7 @@
 }
 /**end repeat**/
 
+static void
 OBJECT_sign(char **args, intp *dimensions, intp *steps, void *NPY_UNUSED(func))
 {
     PyObject *zero = PyInt_FromLong(0);

Modified: branches/ufunc_cleanup/numpy/core/tests/test_umath.py
===================================================================
--- branches/ufunc_cleanup/numpy/core/tests/test_umath.py	2008-10-21 20:13:17 UTC (rev 5954)
+++ branches/ufunc_cleanup/numpy/core/tests/test_umath.py	2008-10-22 05:45:42 UTC (rev 5955)
@@ -47,13 +47,84 @@
 
 class TestMaximum(TestCase):
     def test_reduce_complex(self):
-        assert_equal(ncu.maximum.reduce([1,2j]),1)
-        assert_equal(ncu.maximum.reduce([1+3j,2j]),1+3j)
+        assert_equal(np.maximum.reduce([1,2j]),1)
+        assert_equal(np.maximum.reduce([1+3j,2j]),1+3j)
 
+    def test_float_nans(self):
+        nan = np.nan
+        arg1 = np.array([0,   nan, nan])
+        arg2 = np.array([nan, 0,   nan])
+        out  = np.array([nan, nan, nan])
+        assert_equal(np.maximum(arg1, arg2), out)
+
+    def test_complex_nans(self):
+        nan = np.nan
+        for cnan in [nan, nan*1j, nan + nan*1j] :
+            arg1 = np.array([0, cnan, cnan], dtype=np.complex)
+            arg2 = np.array([cnan, 0, cnan], dtype=np.complex)
+            out  = np.array([nan, nan, nan], dtype=np.complex)
+            assert_equal(np.maximum(arg1, arg2), out)
+
 class TestMinimum(TestCase):
     def test_reduce_complex(self):
-        assert_equal(ncu.minimum.reduce([1,2j]),2j)
+        assert_equal(np.minimum.reduce([1,2j]),2j)
+        assert_equal(np.minimum.reduce([1+3j,2j]),2j)
 
+    def test_float_nans(self):
+        nan = np.nan
+        arg1 = np.array([0,   nan, nan])
+        arg2 = np.array([nan, 0,   nan])
+        out  = np.array([nan, nan, nan])
+        assert_equal(np.minimum(arg1, arg2), out)
+
+    def test_complex_nans(self):
+        nan = np.nan
+        for cnan in [nan, nan*1j, nan + nan*1j] :
+            arg1 = np.array([0, cnan, cnan], dtype=np.complex)
+            arg2 = np.array([cnan, 0, cnan], dtype=np.complex)
+            out  = np.array([nan, nan, nan], dtype=np.complex)
+            assert_equal(np.minimum(arg1, arg2), out)
+
+class TestFmax(TestCase):
+    def test_reduce_complex(self):
+        assert_equal(np.fmax.reduce([1,2j]),1)
+        assert_equal(np.fmax.reduce([1+3j,2j]),1+3j)
+
+    def test_float_nans(self):
+        nan = np.nan
+        arg1 = np.array([0,   nan, nan])
+        arg2 = np.array([nan, 0,   nan])
+        out  = np.array([0,   0,   nan])
+        assert_equal(np.fmax(arg1, arg2), out)
+
+    def test_complex_nans(self):
+        nan = np.nan
+        for cnan in [nan, nan*1j, nan + nan*1j] :
+            arg1 = np.array([0, cnan, cnan], dtype=np.complex)
+            arg2 = np.array([cnan, 0, cnan], dtype=np.complex)
+            out  = np.array([0,    0, nan], dtype=np.complex)
+            assert_equal(np.fmax(arg1, arg2), out)
+
+class TestFmin(TestCase):
+    def test_reduce_complex(self):
+        assert_equal(np.fmin.reduce([1,2j]),2j)
+        assert_equal(np.fmin.reduce([1+3j,2j]),2j)
+
+    def test_float_nans(self):
+        nan = np.nan
+        arg1 = np.array([0,   nan, nan])
+        arg2 = np.array([nan, 0,   nan])
+        out  = np.array([0,   0,   nan])
+        assert_equal(np.fmin(arg1, arg2), out)
+
+    def test_complex_nans(self):
+        nan = np.nan
+        for cnan in [nan, nan*1j, nan + nan*1j] :
+            arg1 = np.array([0, cnan, cnan], dtype=np.complex)
+            arg2 = np.array([cnan, 0, cnan], dtype=np.complex)
+            out  = np.array([0,    0, nan], dtype=np.complex)
+            assert_equal(np.fmin(arg1, arg2), out)
+
 class TestFloatingPoint(TestCase):
     def test_floating_point(self):
         assert_equal(ncu.FLOATING_POINT_SUPPORT, 1)



More information about the Numpy-svn mailing list