[Numpy-svn] r5151 - in trunk/numpy/ma: . tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri May 9 13:03:40 EDT 2008
Author: pierregm
Date: 2008-05-09 12:03:36 -0500 (Fri, 09 May 2008)
New Revision: 5151
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 (abs(b-int(b))<np.finfo(float).precision)
Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py 2008-05-09 05:12:31 UTC (rev 5150)
+++ trunk/numpy/ma/core.py 2008-05-09 17:03:36 UTC (rev 5151)
@@ -2842,8 +2842,6 @@
def power(a, b, third=None):
"""Computes a**b elementwise.
- Masked values are set to 1.
-
"""
if third is not None:
raise MAError, "3-argument power not supported."
@@ -2854,14 +2852,16 @@
fb = getdata(b)
if fb.dtype.char in typecodes["Integer"]:
return masked_array(umath.power(fa, fb), m)
- if numpy.abs(fb) < 1.:
- md = make_mask((fa < 0), shrink=True)
- m = mask_or(m, md)
+ md = (abs(fb-int(fb)) < numpy.finfo(float).precision)
+ m = mask_or(m, md)
if m is nomask:
return masked_array(umath.power(fa, fb))
else:
fa = fa.copy()
- fa[m] = 1
+ if m.all():
+ fa[m] = 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 05:12:31 UTC (rev 5150)
+++ trunk/numpy/ma/tests/test_core.py 2008-05-09 17:03:36 UTC (rev 5151)
@@ -1566,6 +1566,7 @@
x = -1.1
assert_almost_equal(power(x,2.), 1.21)
assert_equal(power(x,0.5)._mask, 1)
+ assert_equal(power(x,masked)._mask, 1)
###############################################################################
More information about the Numpy-svn
mailing list