[Numpy-svn] r5152 - in trunk/numpy/ma: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Fri May 9 13:17:14 EDT 2008


Author: pierregm
Date: 2008-05-09 12:17:12 -0500 (Fri, 09 May 2008)
New Revision: 5152

Modified:
   trunk/numpy/ma/core.py
   trunk/numpy/ma/tests/test_core.py
Log:
core : power : mask all negative values when the exponent (b) doesn't satisfy b==b.astype(int)

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-05-09 17:03:36 UTC (rev 5151)
+++ trunk/numpy/ma/core.py	2008-05-09 17:17:12 UTC (rev 5152)
@@ -2852,14 +2852,13 @@
     fb = getdata(b)
     if fb.dtype.char in typecodes["Integer"]:
         return masked_array(umath.power(fa, fb), m)
-    md = (abs(fb-int(fb)) < numpy.finfo(float).precision)
-    m = mask_or(m, md) 
+    m = mask_or(m, (fa < 0) & (fb != fb.astype(int))) 
     if m is nomask:
         return masked_array(umath.power(fa, fb))
     else:
         fa = fa.copy()
         if m.all():
-            fa[m] = 1
+            fa.flat = 1
         else: 
             numpy.putmask(fa,m,1)
         return masked_array(umath.power(fa, fb), m)

Modified: trunk/numpy/ma/tests/test_core.py
===================================================================
--- trunk/numpy/ma/tests/test_core.py	2008-05-09 17:03:36 UTC (rev 5151)
+++ trunk/numpy/ma/tests/test_core.py	2008-05-09 17:17:12 UTC (rev 5152)
@@ -1567,6 +1567,11 @@
         assert_almost_equal(power(x,2.), 1.21)
         assert_equal(power(x,0.5)._mask, 1)
         assert_equal(power(x,masked)._mask, 1)
+        x = array([-1.1,-1.1,1.1,1.1,0.])
+        b = array([0.5,2.,0.5,2.,1.], mask=[0,0,0,0,1])
+        y = power(x,b)
+        assert_almost_equal(y, [0, 1.21, 1.04880884817, 1.21, 0.] )
+        assert_equal(y._mask, [1,0,0,0,1])        
 
 
 ###############################################################################




More information about the Numpy-svn mailing list