diff options
| author | Stefan van der Walt <stefan@sun.ac.za> | 2007-12-15 01:48:01 +0000 |
|---|---|---|
| committer | Stefan van der Walt <stefan@sun.ac.za> | 2007-12-15 01:48:01 +0000 |
| commit | 4fc786ed80c5b26c8457f8f65bdf58ad67c64b8e (patch) | |
| tree | bfafccd22c39f4dce5f4243d88bcfd0b1bd2a22e /numpy/ma/bench.py | |
| parent | 703e8d6323b19cbfeb96772c1e35f1cd68629336 (diff) | |
| download | numpy-4fc786ed80c5b26c8457f8f65bdf58ad67c64b8e.tar.gz | |
Fix benchmarks. Remove remaining imports of maskedarray.
Diffstat (limited to 'numpy/ma/bench.py')
| -rw-r--r-- | numpy/ma/bench.py | 89 |
1 files changed, 28 insertions, 61 deletions
diff --git a/numpy/ma/bench.py b/numpy/ma/bench.py index cdb010df1..19fbe9461 100644 --- a/numpy/ma/bench.py +++ b/numpy/ma/bench.py @@ -1,13 +1,14 @@ #! python +# encoding: utf-8 import timeit #import IPython.ipapi #ip = IPython.ipapi.get() #from IPython import ipmagic import numpy -import maskedarray -from maskedarray import filled -from maskedarray.testutils import assert_equal +from numpy import ma +from numpy.ma import filled +from numpy.ma.testutils import assert_equal #####--------------------------------------------------------------------------- @@ -23,9 +24,6 @@ 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 = maskedarray.array(xs, mask=m1) -mmys = maskedarray.array(ys, mask=m2) -mmzs = maskedarray.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) @@ -35,20 +33,17 @@ 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 = maskedarray.array(xl, mask=maskx, shrink=True) -mmyl = maskedarray.array(yl, mask=masky, shrink=True) -mmzl = maskedarray.array(zl, mask=maskx, shrink=True) #####--------------------------------------------------------------------------- #---- --- Functions --- #####--------------------------------------------------------------------------- def timer(s, v='', nloop=500, nrep=3): - units = ["s", "ms", "\xb5s", "ns"] + units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print "%s : %-50s : " % (v,s), - varnames = ["%ss,nm%ss,mm%ss,%sl,nm%sl,mm%sl" % tuple(x*6) for x in 'xyz'] - setup = 'from __main__ import numpy, maskedarray, %s' % ','.join(varnames) + varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] + setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: @@ -63,69 +58,45 @@ def timer(s, v='', nloop=500, nrep=3): -def compare_functions_1v(func, nloop=500, test=True, - xs=xs, nmxs=nmxs, mmxs=mmxs, - xl=xl, nmxl=nmxl, mmxl=mmxl): +def compare_functions_1v(func, nloop=500, + xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl): funcname = func.__name__ print "-"*50 print "%s on small arrays" % funcname - 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"), - ("xs","nmxs","mmxs")): - timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) + module, data = "numpy.ma","nmxs" + 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"), - ("xl","nmxl","mmxl")): - timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) + module, data = "numpy.ma","nmxl" + 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, - xs=xs, nmxs=nmxs, mmxs=mmxs, - xl=xl, nmxl=nmxl, mmxl=mmxl): + xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl): print "-"*50 print "%s on small arrays" % methodname - if test: - assert_equal(filled(eval("nm%ss.%s(%s)" % (vars,methodname,args)),0), - filled(eval("mm%ss.%s(%s)" % (vars,methodname,args)),0)) - for (data, ver) in zip(["nm%ss" % vars, "mm%ss" % vars], ('numpy.ma ','maskedarray')): - timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) + data, ver = "nm%ss" % vars, 'numpy.ma' + timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) # print "%s on large arrays" % methodname - if test: - assert_equal(filled(eval("nm%sl.%s(%s)" % (vars,methodname,args)),0), - filled(eval("mm%sl.%s(%s)" % (vars,methodname,args)),0)) - for (data, ver) in zip(["nm%sl" % vars, "mm%sl" % vars], ('numpy.ma ','maskedarray')): - timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) + data, ver = "nm%sl" % vars, 'numpy.ma' + timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) return def compare_functions_2v(func, nloop=500, test=True, - xs=xs, nmxs=nmxs, mmxs=mmxs, - ys=ys, nmys=nmys, mmys=mmys, - xl=xl, nmxl=nmxl, mmxl=mmxl, - yl=yl, nmyl=nmyl, mmyl=mmyl): + xs=xs, nmxs=nmxs, + ys=ys, nmys=nmys, + xl=xl, nmxl=nmxl, + yl=yl, nmyl=nmyl): funcname = func.__name__ print "-"*50 print "%s on small arrays" % funcname - 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"), - ("xs,ys","nmxs,nmys","mmxs,mmys")): - timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) + module, data = "numpy.ma","nmxs,nmys" + 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"), - ("xl,yl","nmxl,nmyl","mmxl,mmyl")): - timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) + module, data = "numpy.ma","nmxl,nmyl" + timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) return @@ -180,19 +151,15 @@ if __name__ == '__main__': print "-"*50 print "__setitem__ on small arrays" timer('nmxs.__setitem__((-1,0),numpy.ma.masked)', 'numpy.ma ',nloop=10000) - timer('mmxs.__setitem__((-1,0),maskedarray.masked)', 'maskedarray',nloop=10000) + print "-"*50 print "__setitem__ on large arrays" timer('nmxl.__setitem__((-1,0),numpy.ma.masked)', 'numpy.ma ',nloop=10000) - timer('mmxl.__setitem__((-1,0),maskedarray.masked)', 'maskedarray',nloop=10000) + #.................................................................... print "-"*50 print "where on small arrays" - assert_equal(eval("numpy.ma.where(nmxs>2,nmxs,nmys)"), - eval("maskedarray.where(mmxs>2, mmxs,mmys)")) timer('numpy.ma.where(nmxs>2,nmxs,nmys)', 'numpy.ma ',nloop=1000) - timer('maskedarray.where(mmxs>2, mmxs,mmys)', 'maskedarray',nloop=1000) print "-"*50 print "where on large arrays" timer('numpy.ma.where(nmxl>2,nmxl,nmyl)', 'numpy.ma ',nloop=100) - timer('maskedarray.where(mmxl>2, mmxl,mmyl)', 'maskedarray',nloop=100) |
