diff options
author | Thomas A Caswell <tcaswell@gmail.com> | 2016-02-05 12:15:50 -0500 |
---|---|---|
committer | Thomas A Caswell <tcaswell@gmail.com> | 2016-02-07 14:26:55 -0500 |
commit | f473fe4418a98e2e0edb357f23b74964b09d6a7a (patch) | |
tree | c386be2011da53e30b04b7a3948d3930afd185d7 /numpy/core/fromnumeric.py | |
parent | 08fb5807118423e314f324b9bcafdbaab9316f4d (diff) | |
download | numpy-f473fe4418a98e2e0edb357f23b74964b09d6a7a.tar.gz |
MNT: reduce number of return statements
In sum, amax, amin, and prod simplify the logic to remove an identical
return statement / call to `_methods._xxx`. This removes several
elif/else pairs and reduces the number of exit points from the functions
but makes the code path a bit more complicated to trace.
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 00b2dbae0..52a15e30d 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1836,16 +1836,15 @@ def sum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): out[...] = res return out return res - elif type(a) is not mu.ndarray: + if type(a) is not mu.ndarray: try: sum = a.sum except AttributeError: - return _methods._sum(a, axis=axis, dtype=dtype, - out=out, **kwargs) - return sum(axis=axis, dtype=dtype, out=out, **kwargs) - else: - return _methods._sum(a, axis=axis, dtype=dtype, - out=out, **kwargs) + pass + else: + return sum(axis=axis, dtype=dtype, out=out, **kwargs) + return _methods._sum(a, axis=axis, dtype=dtype, + out=out, **kwargs) def product(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): @@ -2285,16 +2284,17 @@ def amax(a, axis=None, out=None, keepdims=np._NoValue): kwargs = {} if keepdims is not np._NoValue: kwargs['keepdims'] = keepdims + if type(a) is not mu.ndarray: try: amax = a.max except AttributeError: - return _methods._amax(a, axis=axis, - out=out, **kwargs) - return amax(axis=axis, out=out, **kwargs) - else: - return _methods._amax(a, axis=axis, - out=out, **kwargs) + pass + else: + return amax(axis=axis, out=out, **kwargs) + + return _methods._amax(a, axis=axis, + out=out, **kwargs) def amin(a, axis=None, out=None, keepdims=np._NoValue): @@ -2389,12 +2389,12 @@ def amin(a, axis=None, out=None, keepdims=np._NoValue): try: amin = a.min except AttributeError: - return _methods._amin(a, axis=axis, - out=out, **kwargs) - return amin(axis=axis, out=out, **kwargs) - else: - return _methods._amin(a, axis=axis, - out=out, **kwargs) + pass + else: + return amin(axis=axis, out=out, **kwargs) + + return _methods._amin(a, axis=axis, + out=out, **kwargs) def alen(a): @@ -2535,12 +2535,12 @@ def prod(a, axis=None, dtype=None, out=None, keepdims=np._NoValue): try: prod = a.prod except AttributeError: - return _methods._prod(a, axis=axis, dtype=dtype, - out=out, **kwargs) - return prod(axis=axis, dtype=dtype, out=out, **kwargs) - else: - return _methods._prod(a, axis=axis, dtype=dtype, - out=out, **kwargs) + pass + else: + return prod(axis=axis, dtype=dtype, out=out, **kwargs) + + return _methods._prod(a, axis=axis, dtype=dtype, + out=out, **kwargs) def cumprod(a, axis=None, dtype=None, out=None): |