[Numpy-svn] r5472 - in branches/1.1.x/numpy/core: src tests

numpy-svn@scip... numpy-svn@scip...
Sun Jul 20 14:30:41 CDT 2008


Author: charris
Date: 2008-07-20 14:30:37 -0500 (Sun, 20 Jul 2008)
New Revision: 5472

Modified:
   branches/1.1.x/numpy/core/src/umathmodule.c.src
   branches/1.1.x/numpy/core/tests/test_regression.py
Log:
Fix ticket #794.


Modified: branches/1.1.x/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/1.1.x/numpy/core/src/umathmodule.c.src	2008-07-20 19:29:30 UTC (rev 5471)
+++ branches/1.1.x/numpy/core/src/umathmodule.c.src	2008-07-20 19:30:37 UTC (rev 5472)
@@ -1682,9 +1682,15 @@
 
 #define BOOL_negative BOOL_logical_not
 
-#define _SIGN1(x) ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
+#define _SIGN1(x) (isnan((x)) ? NAN : ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0)) )
 #define _SIGN2(x) ((x) == 0 ? 0 : 1)
-#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))
+#define _SIGNC(x) (isnan((x.real)) ? NAN : \
+                   isnan((x.imag)) ? NAN : \
+                   ((x).real > 0) ? 1 : \
+                   ((x).real < 0 ? -1 : \
+                   ((x).imag > 0 ? 1 : \
+                   ((x).imag < 0) ? -1 : 0)))
+
 /**begin repeat
    #TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#
    #typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#

Modified: branches/1.1.x/numpy/core/tests/test_regression.py
===================================================================
--- branches/1.1.x/numpy/core/tests/test_regression.py	2008-07-20 19:29:30 UTC (rev 5471)
+++ branches/1.1.x/numpy/core/tests/test_regression.py	2008-07-20 19:30:37 UTC (rev 5472)
@@ -1084,6 +1084,13 @@
         b = np.array(['1','2','3'])
         assert_equal(a,b)
 
+    def check_sign_for_complex_nan(self, level=rlevel):
+        """Ticket 794."""
+        C = np.array([-np.inf, -2+1j, 0, 2-1j, np.inf, np.nan])
+        have = np.sign(C)
+        want = np.array([-1+0j, -1+0j, 0+0j, 1+0j, 1+0j, np.nan+0j])
+        assert_equal(have, want)
 
+
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list