Skip to content

Commit

Permalink
STY,MAINT: PEP8 and pyflakes fixes for numpy/ma/*.py
Browse files Browse the repository at this point in the history
Also

* Add __all__ to numpy/ma/testutils.py
* Remove various stray "#"

We might want to consider removing/refactoring both numpy/ma/bench.py
and numpy/ma/timer_comparison.
  • Loading branch information
charris committed Jul 5, 2015
1 parent c2ae6aa commit 7c8c9ad
Show file tree
Hide file tree
Showing 8 changed files with 1,135 additions and 999 deletions.
8 changes: 3 additions & 5 deletions numpy/ma/__init__.py
Expand Up @@ -35,14 +35,12 @@
.. [1] Not-a-Number, a floating point value that is the result of an
invalid operation.
.. moduleauthor:: Pierre Gerard-Marchant
.. moduleauthor:: Jarrod Millman
"""
from __future__ import division, absolute_import, print_function

__author__ = "Pierre GF Gerard-Marchant ($Author: jarrod.millman $)"
__version__ = '1.0'
__revision__ = "$Revision: 3473 $"
__date__ = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $'

from . import core
from .core import *

Expand Down
75 changes: 20 additions & 55 deletions numpy/ma/bench.py
@@ -1,22 +1,16 @@
#! python
# encoding: utf-8
from __future__ import division, absolute_import, print_function
#! /usr/bin/env python
from __future__ import division, print_function

import timeit
#import IPython.ipapi
#ip = IPython.ipapi.get()
#from IPython import ipmagic
import numpy
#from numpy import ma
#from numpy.ma import filled
#from numpy.ma.testutils import assert_equal


#####---------------------------------------------------------------------------
#---- --- Global variables ---
#####---------------------------------------------------------------------------
###############################################################################
# Global variables #
###############################################################################


# Small arrays ..................................
# 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
Expand All @@ -25,7 +19,8 @@
nmxs = numpy.ma.array(xs, mask=m1)
nmys = numpy.ma.array(ys, mask=m2)
nmzs = numpy.ma.array(zs, mask=m1)
# Big arrays ....................................

# 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
Expand All @@ -35,9 +30,11 @@
nmyl = numpy.ma.array(yl, mask=masky)
nmzl = numpy.ma.array(zl, mask=maskx)

#####---------------------------------------------------------------------------
#---- --- Functions ---
#####---------------------------------------------------------------------------

###############################################################################
# Functions #
###############################################################################


def timer(s, v='', nloop=500, nrep=3):
units = ["s", "ms", "µs", "ns"]
Expand All @@ -55,8 +52,6 @@ def timer(s, v='', nloop=500, nrep=3):
3,
best * scaling[order],
units[order]))
# ip.magic('timeit -n%i %s' % (nloop,s))



def compare_functions_1v(func, nloop=500,
Expand All @@ -66,7 +61,7 @@ def compare_functions_1v(func, nloop=500,
print("%s on small arrays" % funcname)
module, data = "numpy.ma", "nmxs"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
#

print("%s on large arrays" % funcname)
module, data = "numpy.ma", "nmxl"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
Expand All @@ -78,7 +73,7 @@ def compare_methods(methodname, args, vars='x', nloop=500, test=True,
print("%s on small arrays" % methodname)
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)
data, ver = "nm%sl" % vars, 'numpy.ma'
timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop)
Expand All @@ -94,51 +89,22 @@ def compare_functions_2v(func, nloop=500, test=True,
print("%s on small arrays" % funcname)
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)
module, data = "numpy.ma", "nmxl,nmyl"
timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop)
return


###############################################################################


################################################################################
if __name__ == '__main__':
# # 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 = 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)
# 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 = maskedarray.array(xl, mask=maskx, shrink=True)
# mmyl = maskedarray.array(yl, mask=masky, shrink=True)
# mmzl = maskedarray.array(zl, mask=maskx, shrink=True)
#
compare_functions_1v(numpy.sin)
compare_functions_1v(numpy.log)
compare_functions_1v(numpy.sqrt)
#....................................................................

compare_functions_2v(numpy.multiply)
compare_functions_2v(numpy.divide)
compare_functions_2v(numpy.power)
#....................................................................

compare_methods('ravel', '', nloop=1000)
compare_methods('conjugate', '', 'z', nloop=1000)
compare_methods('transpose', '', nloop=1000)
Expand All @@ -148,7 +114,7 @@ def compare_functions_2v(func, nloop=500, test=True,
compare_methods('__getitem__', '[0,-1]', nloop=1000)
compare_methods('__setitem__', '0, 17', nloop=1000, test=False)
compare_methods('__setitem__', '(0,0), 17', nloop=1000, test=False)
#....................................................................

print("-"*50)
print("__setitem__ on small arrays")
timer('nmxs.__setitem__((-1,0),numpy.ma.masked)', 'numpy.ma ', nloop=10000)
Expand All @@ -157,7 +123,6 @@ def compare_functions_2v(func, nloop=500, test=True,
print("__setitem__ on large arrays")
timer('nmxl.__setitem__((-1,0),numpy.ma.masked)', 'numpy.ma ', nloop=10000)

#....................................................................
print("-"*50)
print("where on small arrays")
timer('numpy.ma.where(nmxs>2,nmxs,nmys)', 'numpy.ma ', nloop=1000)
Expand Down

0 comments on commit 7c8c9ad

Please sign in to comment.