[Scipy-svn] r3375 - trunk/scipy/sandbox/maskedarray
scipy-svn@scip...
scipy-svn@scip...
Thu Sep 27 10:41:40 CDT 2007
Author: pierregm
Date: 2007-09-27 10:41:34 -0500 (Thu, 27 Sep 2007)
New Revision: 3375
Modified:
trunk/scipy/sandbox/maskedarray/__init__.py
trunk/scipy/sandbox/maskedarray/bench.py
trunk/scipy/sandbox/maskedarray/core.py
Log:
Fixed __init__
core : add the .shrink_mask() method
Modified: trunk/scipy/sandbox/maskedarray/__init__.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/__init__.py 2007-09-27 14:26:00 UTC (rev 3374)
+++ trunk/scipy/sandbox/maskedarray/__init__.py 2007-09-27 15:41:34 UTC (rev 3375)
@@ -17,8 +17,6 @@
import extras
from extras import *
-import _nfcore
-
__all__ = ['core', 'extras']
__all__ += core.__all__
__all__ += extras.__all__
\ No newline at end of file
Modified: trunk/scipy/sandbox/maskedarray/bench.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/bench.py 2007-09-27 14:26:00 UTC (rev 3374)
+++ trunk/scipy/sandbox/maskedarray/bench.py 2007-09-27 15:41:34 UTC (rev 3375)
@@ -72,17 +72,17 @@
if test:
assert_equal(filled(eval("numpy.ma.%s(nmxs)" % funcname),0),
filled(eval("maskedarray.%s(mmxs)" % funcname),0))
- for (module, data) in zip(("numpy", "numpy.ma","maskedarray","maskedarray._nfcore"),
- ("xs","nmxs","mmxs","mmxs")):
- timer("%(module)s.%(funcname)s(%(data)s)" % locals())
+ for (module, data) in zip(("numpy", "numpy.ma","maskedarray"),
+ ("xs","nmxs","mmxs")):
+ timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
#
print "%s on large arrays" % funcname
if test:
assert_equal(filled(eval("numpy.ma.%s(nmxl)" % funcname),0),
filled(eval("maskedarray.%s(mmxl)" % funcname),0))
- for (module, data) in zip(("numpy", "numpy.ma","maskedarray","maskedarray._nfcore"),
- ("xl","nmxl","mmxl","mmxl")):
- timer("%(module)s.%(funcname)s(%(data)s)" % locals())
+ for (module, data) in zip(("numpy", "numpy.ma","maskedarray"),
+ ("xl","nmxl","mmxl")):
+ timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
return
def compare_methods(methodname, args, vars='x', nloop=500, test=True,
@@ -115,17 +115,17 @@
if test:
assert_equal(filled(eval("numpy.ma.%s(nmxs,nmys)" % funcname),0),
filled(eval("maskedarray.%s(mmxs,mmys)" % funcname),0))
- for (module, data) in zip(("numpy", "numpy.ma","maskedarray","maskedarray._nfcore"),
- ("xs,ys","nmxs,nmys","mmxs,mmys","mmxs,mmys")):
- timer("%(module)s.%(funcname)s(%(data)s)" % locals())
+ for (module, data) in zip(("numpy", "numpy.ma","maskedarray"),
+ ("xs,ys","nmxs,nmys","mmxs,mmys")):
+ timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
#
print "%s on large arrays" % funcname
if test:
assert_equal(filled(eval("numpy.ma.%s(nmxl, nmyl)" % funcname),0),
filled(eval("maskedarray.%s(mmxl, mmyl)" % funcname),0))
- for (module, data) in zip(("numpy", "numpy.ma","maskedarray","maskedarray._nfcore"),
- ("xl,yl","nmxl,nmyl","mmxl,mmyl","mmxl,mmyl")):
- timer("%(module)s.%(funcname)s(%(data)s)" % locals())
+ for (module, data) in zip(("numpy", "numpy.ma","maskedarray"),
+ ("xl,yl","nmxl,nmyl","mmxl,mmyl")):
+ timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
return
Modified: trunk/scipy/sandbox/maskedarray/core.py
===================================================================
--- trunk/scipy/sandbox/maskedarray/core.py 2007-09-27 14:26:00 UTC (rev 3374)
+++ trunk/scipy/sandbox/maskedarray/core.py 2007-09-27 15:41:34 UTC (rev 3375)
@@ -362,9 +362,10 @@
d1 = get_data(a)
if self.domain is not None:
dm = narray(self.domain(d1), copy=False)
- m = mask_or(m, narray(self.domain(d1)))
+ m = numpy.logical_or(m, dm)
# The following two lines control the domain filling methods.
d1 = d1.copy()
+# d1[dm] = self.fill
numpy.putmask(d1, dm, self.fill)
# Take care of the masked singletong first ...
if not m.ndim and m:
@@ -1252,6 +1253,13 @@
if self._sharedmask:
self._mask = self._mask.copy()
self._sharedmask = False
+
+ def shrink_mask(self):
+ "Reduces a mask to nomask when possible."
+ m = self._mask
+ if m.ndim and not m.any():
+ self._mask = nomask
+
#............................................
def _get_data(self):
"Returns the current data (as a view of the original underlying data)>"
@@ -2159,7 +2167,7 @@
masked_array = MaskedArray
def array(data, dtype=None, copy=False, order=False, mask=nomask, subok=True,
- keep_mask=True, hard_mask=False, fill_value=None):
+ keep_mask=True, hard_mask=False, fill_value=None, shrink=True):
"""array(data, dtype=None, copy=True, order=False, mask=nomask,
keep_mask=True, shrink=True, fill_value=None)
Acts as shortcut to MaskedArray, with options in a different order for convenience.
@@ -2778,14 +2786,32 @@
###############################################################################
-#if __name__ == '__main__':
- #from maskedarray.testutils import assert_equal, assert_almost_equal
+if __name__ == '__main__':
+ from maskedarray.testutils import assert_equal, assert_almost_equal
- #xm = array(numpy.random.uniform(-1,1,25))
- #xm[xm>0.5] = masked
- #xm.fill_value = -999
- ##
- #z = 3//where(xm.mask,0,xm)
- #assert_equal(z._mask, numpy.logical_or(xm==0,xm._mask))
- #assert_equal(z._data[xm._mask], 1)
-
+ # Small arrays ..................................
+ xs = numpy.random.uniform(-1,1,6).reshape(2,3)
+ ys = numpy.random.uniform(-1,1,6).reshape(2,3)
+ zs = xs + 1j * ys
+ m1 = [[True, False, False], [False, False, True]]
+ m2 = [[True, False, True], [False, False, True]]
+ nmxs = numpy.ma.array(xs, mask=m1)
+ nmys = numpy.ma.array(ys, mask=m2)
+ nmzs = numpy.ma.array(zs, mask=m1)
+ mmxs = array(xs, mask=m1)
+ mmys = array(ys, mask=m2)
+ mmzs = array(zs, mask=m1)
+ # Big arrays ....................................
+ xl = numpy.random.uniform(-1,1,100*100).reshape(100,100)
+ yl = numpy.random.uniform(-1,1,100*100).reshape(100,100)
+ zl = xl + 1j * yl
+ maskx = xl > 0.8
+ masky = yl < -0.8
+ nmxl = numpy.ma.array(xl, mask=maskx)
+ nmyl = numpy.ma.array(yl, mask=masky)
+ nmzl = numpy.ma.array(zl, mask=maskx)
+ mmxl = array(xl, mask=maskx, shrink=True)
+ mmyl = array(yl, mask=masky, shrink=True)
+ mmzl = array(zl, mask=maskx, shrink=True)
+ #
+ z = log(mmxl)
\ No newline at end of file
More information about the Scipy-svn
mailing list