Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

STY pep8

  • Loading branch information...
commit ee250d71abf6a9473d950677534daaa3f1791c39 1 parent 83fad40
@kwgoodman authored
Showing with 46,784 additions and 16,839 deletions.
  1. +3 −2 bottleneck/benchmark/autotimeit.py
  2. +56 −52 bottleneck/benchmark/bench.py
  3. +27,741 −8,762 bottleneck/src/func/func.c
  4. +18,250 −7,394 bottleneck/src/move/move.c
  5. +9 −9 bottleneck/src/template/func/allnan.py
  6. +10 −10 bottleneck/src/template/func/anynan.py
  7. +16 −16 bottleneck/src/template/func/argpartsort.py
  8. +4 −3 bottleneck/src/template/func/func.py
  9. +22 −22 bottleneck/src/template/func/median.py
  10. +14 −14 bottleneck/src/template/func/nanargmax.py
  11. +15 −15 bottleneck/src/template/func/nanargmin.py
  12. +21 −21 bottleneck/src/template/func/nanmax.py
  13. +19 −19 bottleneck/src/template/func/nanmean.py
  14. +29 −29 bottleneck/src/template/func/nanmedian.py
  15. +20 −20 bottleneck/src/template/func/nanmin.py
  16. +17 −17 bottleneck/src/template/func/nanrankdata.py
  17. +24 −24 bottleneck/src/template/func/nanstd.py
  18. +16 −16 bottleneck/src/template/func/nansum.py
  19. +26 −26 bottleneck/src/template/func/nanvar.py
  20. +12 −12 bottleneck/src/template/func/nn.py
  21. +18 −18 bottleneck/src/template/func/partsort.py
  22. +19 −19 bottleneck/src/template/func/rankdata.py
  23. +11 −11 bottleneck/src/template/func/replace.py
  24. +11 −11 bottleneck/src/template/func/ss.py
  25. +1 −0  bottleneck/src/template/move/move.py
  26. +26 −26 bottleneck/src/template/move/move_max.py
  27. +13 −13 bottleneck/src/template/move/move_mean.py
  28. +18 −18 bottleneck/src/template/move/move_median.py
  29. +26 −26 bottleneck/src/template/move/move_min.py
  30. +25 −25 bottleneck/src/template/move/move_nanmax.py
  31. +11 −11 bottleneck/src/template/move/move_nanmean.py
  32. +26 −26 bottleneck/src/template/move/move_nanmin.py
  33. +13 −13 bottleneck/src/template/move/move_nanstd.py
  34. +11 −11 bottleneck/src/template/move/move_nansum.py
  35. +15 −15 bottleneck/src/template/move/move_std.py
  36. +14 −14 bottleneck/src/template/move/move_sum.py
  37. +35 −28 bottleneck/src/template/template.py
  38. +31 −2 bottleneck/tests/fast_test.py
  39. +35 −12 bottleneck/tests/func_test.py
  40. +8 −6 bottleneck/tests/input_modifcation_test.py
  41. +36 −6 bottleneck/tests/list_input_test.py
  42. +19 −5 bottleneck/tests/move_test.py
  43. +4 −4 sandbox/setup.py
  44. +34 −36 setup.py
View
5 bottleneck/benchmark/autotimeit.py
@@ -1,18 +1,19 @@
import timeit
+
def autotimeit(stmt, setup='pass', repeat=3, mintime=0.2):
timer = timeit.Timer(stmt, setup)
number, time1 = autoscaler(timer, mintime)
time2 = timer.repeat(repeat=repeat-1, number=number)
return min(time2 + [time1]) / number
+
def autoscaler(timer, mintime):
number = 1
for i in range(12):
time = timer.timeit(number)
if time > mintime:
- return number, time
+ return number, time
number *= 10
raise RuntimeError('function is too fast to test')
-
View
108 bottleneck/benchmark/bench.py
@@ -10,7 +10,8 @@
def bench(mode='fast', dtype='float64', axis=1,
- shapes=[(10,10),(100,100),(1000,1000),(10,10),(100,100),(1000,1000)],
+ shapes=[(10, 10), (100, 100), (1000, 1000), (10, 10), (100, 100),
+ (1000, 1000)],
nans=[False, False, False, True, True, True]):
"""
Bottleneck benchmark.
@@ -39,7 +40,7 @@ def bench(mode='fast', dtype='float64', axis=1,
A benchmark report is printed to stdout.
"""
-
+
try:
import scipy as sp
SCIPY = True
@@ -64,12 +65,12 @@ def bench(mode='fast', dtype='float64', axis=1,
print("%sScipy (sp) Cannot import, skipping scipy benchmarks" % tab)
print("%sSpeed is NumPy or SciPy time divided by Bottleneck time" % tab)
tup = (tab, dtype, axis)
- print("%sNaN means one-third NaNs; %s and axis=%s are used" % tup )
+ print("%sNaN means one-third NaNs; %s and axis=%s are used" % tup)
if mode == 'fast':
print("%sHigh-level functions used (mode='fast')" % tab)
- elif mode == 'faster':
+ elif mode == 'faster':
print("%sLow-level functions used (mode='faster')" % tab)
-
+
print('')
header = [" "*14]
for nan in nans:
@@ -97,6 +98,7 @@ def bench(mode='fast', dtype='float64', axis=1,
for test in suite:
print("%s%s" % (test["name"].ljust(15), test['ref']))
+
def timer(statements, setups):
speed = []
if len(statements) != 2:
@@ -108,6 +110,7 @@ def timer(statements, setups):
speed.append(t1 / t0)
return speed
+
def getarray(shape, dtype, nans=False):
arr = np.arange(np.prod(shape), dtype=dtype)
if nans and issubclass(arr.dtype.type, np.inexact):
@@ -116,14 +119,15 @@ def getarray(shape, dtype, nans=False):
rs = np.random.RandomState(shape)
rs.shuffle(arr)
return arr.reshape(*shape)
-
+
+
def benchsuite(mode, shapes, dtype, axis, nans):
if mode not in ('fast', 'faster'):
raise ValueError("`mode` must be 'fast' or 'faster'")
suite = []
-
+
def getsetups(setup, shapes, nans):
template = """import numpy as np
import bottleneck as bn
@@ -144,13 +148,13 @@ def getsetups(setup, shapes, nans):
code = "bn.median(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "np.median(a, axis=AXIS)"]
+ run['statements'] = [code, "np.median(a, axis=AXIS)"]
setup = """
func, a = bn.func.median_selector(a, axis=AXIS)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# nanmedian
run = {}
run['name'] = "nanmedian"
@@ -160,14 +164,14 @@ def getsetups(setup, shapes, nans):
code = "bn.nanmedian(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "scipy_nanmedian(a, axis=AXIS)"]
+ run['statements'] = [code, "scipy_nanmedian(a, axis=AXIS)"]
setup = """
from bottleneck.slow.func import scipy_nanmedian
func, a = bn.func.nanmedian_selector(a, axis=AXIS)
"""
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# nansum
run = {}
run['name'] = "nansum"
@@ -177,10 +181,10 @@ def getsetups(setup, shapes, nans):
code = "bn.nansum(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "np.nansum(a, axis=AXIS)"]
+ run['statements'] = [code, "np.nansum(a, axis=AXIS)"]
setup = """
func, a = bn.func.nansum_selector(a, axis=AXIS)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
@@ -193,13 +197,13 @@ def getsetups(setup, shapes, nans):
code = "bn.nanmax(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "np.nanmax(a, axis=AXIS)"]
+ run['statements'] = [code, "np.nanmax(a, axis=AXIS)"]
setup = """
func, a = bn.func.nanmax_selector(a, axis=AXIS)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# nanmean
run = {}
run['name'] = "nanmean"
@@ -209,7 +213,7 @@ def getsetups(setup, shapes, nans):
code = "bn.nanmean(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "scipy_nanmean(a, axis=AXIS)"]
+ run['statements'] = [code, "scipy_nanmean(a, axis=AXIS)"]
setup = """
from bottleneck.slow.func import scipy_nanmean
func, a = bn.func.nanmean_selector(a, axis=AXIS)
@@ -226,14 +230,14 @@ def getsetups(setup, shapes, nans):
code = "bn.nanstd(a, axis=AXIS)"
else:
code = "func(a, 0)"
- run['statements'] = [code, "scipy_nanstd(a, axis=AXIS)"]
+ run['statements'] = [code, "scipy_nanstd(a, axis=AXIS)"]
setup = """
from bottleneck.slow.func import scipy_nanstd
func, a = bn.func.nanstd_selector(a, axis=AXIS)
"""
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# nanargmax
run = {}
run['name'] = "nanargmax"
@@ -243,7 +247,7 @@ def getsetups(setup, shapes, nans):
code = "bn.nanargmax(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "np.nanargmax(a, axis=AXIS)"]
+ run['statements'] = [code, "np.nanargmax(a, axis=AXIS)"]
setup = """
func, a = bn.func.nanargmax_selector(a, axis=AXIS)
"""
@@ -259,14 +263,14 @@ def getsetups(setup, shapes, nans):
code = "bn.ss(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "scipy_ss(a, axis=AXIS)"]
+ run['statements'] = [code, "scipy_ss(a, axis=AXIS)"]
setup = """
from bottleneck.slow.func import scipy_ss
func, a = bn.func.ss_selector(a, axis=AXIS)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# rankdata
run = {}
run['name'] = "rankdata"
@@ -276,14 +280,14 @@ def getsetups(setup, shapes, nans):
code = "bn.rankdata(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "bn.slow.rankdata(a, axis=AXIS)"]
+ run['statements'] = [code, "bn.slow.rankdata(a, axis=AXIS)"]
setup = """
ignore = bn.slow.rankdata(a, axis=AXIS)
func, a = bn.func.rankdata_selector(a, axis=AXIS)
"""
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# partsort
run = {}
run['name'] = "partsort"
@@ -293,7 +297,7 @@ def getsetups(setup, shapes, nans):
code = "bn.partsort(a, n=n, axis=AXIS)"
else:
code = "func(a, n)"
- run['statements'] = [code, "np.sort(a, axis=AXIS)"]
+ run['statements'] = [code, "np.sort(a, axis=AXIS)"]
setup = """
if AXIS is None: n = a.size
else: n = a.shape[AXIS]
@@ -302,7 +306,7 @@ def getsetups(setup, shapes, nans):
"""
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# argpartsort
run = {}
run['name'] = "argpartsort"
@@ -312,7 +316,7 @@ def getsetups(setup, shapes, nans):
code = "bn.argpartsort(a, n=n, axis=AXIS)"
else:
code = "func(a, n)"
- run['statements'] = [code, "np.argsort(a, axis=AXIS)"]
+ run['statements'] = [code, "np.argsort(a, axis=AXIS)"]
setup = """
if AXIS is None: n = a.size
else: n = a.shape[AXIS]
@@ -331,14 +335,14 @@ def getsetups(setup, shapes, nans):
code = "bn.replace(a, np.nan, 0)"
else:
code = "func(a, np.nan, 0)"
- run['statements'] = [code, "replace(a, np.nan, 0)"]
+ run['statements'] = [code, "replace(a, np.nan, 0)"]
setup = """
from bottleneck.slow.func import replace
func = bn.func.replace_selector(a)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
-
+
# anynan
run = {}
run['name'] = "anynan"
@@ -348,10 +352,10 @@ def getsetups(setup, shapes, nans):
code = "bn.anynan(a, axis=AXIS)"
else:
code = "func(a)"
- run['statements'] = [code, "np.isnan(a).any(axis=AXIS)"]
+ run['statements'] = [code, "np.isnan(a).any(axis=AXIS)"]
setup = """
func, a = bn.func.anynan_selector(a, axis=AXIS)
- """
+ """
run['setups'] = getsetups(setup, shapes, nans)
suite.append(run)
@@ -365,7 +369,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_sum(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_sum(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_sum(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_sum as scipy_move_sum
w = a.shape[AXIS] // 5
@@ -375,7 +379,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_nansum
run = {}
run['name'] = "move_nansum"
@@ -386,7 +390,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_nansum(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_nansum(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_nansum(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_nansum as scipy_move_nansum
w = a.shape[AXIS] // 5
@@ -396,7 +400,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_mean
run = {}
run['name'] = "move_mean"
@@ -407,7 +411,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_mean(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_mean(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_mean(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_mean as scipy_move_mean
w = a.shape[AXIS] // 5
@@ -417,7 +421,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_nanmean
run = {}
run['name'] = "move_nanmean"
@@ -428,7 +432,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_nanmean(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_nanmean(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_nanmean(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_nanmean as scipy_move_nanmean
w = a.shape[AXIS] // 5
@@ -438,7 +442,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_std
run = {}
run['name'] = "move_std"
@@ -449,7 +453,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_std(a, window=w, axis=AXIS)"
else:
code = "func(a, w, 0)"
- run['statements'] = [code, "scipy_move_std(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_std(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_std as scipy_move_std
w = a.shape[AXIS] // 5
@@ -459,7 +463,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_nanstd
run = {}
run['name'] = "move_nanstd"
@@ -470,7 +474,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_nanstd(a, window=w, axis=AXIS)"
else:
code = "func(a, w, 0)"
- run['statements'] = [code, "scipy_move_nanstd(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_nanstd(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_nanstd as scipy_move_nanstd
w = a.shape[AXIS] // 5
@@ -480,7 +484,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_max
run = {}
run['name'] = "move_max"
@@ -491,7 +495,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_max(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_max(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_max(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_max as scipy_move_max
w = a.shape[AXIS] // 5
@@ -501,7 +505,7 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# move_nanmax
run = {}
run['name'] = "move_nanmax"
@@ -512,7 +516,7 @@ def getsetups(setup, shapes, nans):
code = "bn.move_nanmax(a, window=w, axis=AXIS)"
else:
code = "func(a, w)"
- run['statements'] = [code, "scipy_move_nanmax(a, window=w, axis=AXIS)"]
+ run['statements'] = [code, "scipy_move_nanmax(a, window=w, axis=AXIS)"]
setup = """
from bottleneck.slow.move import move_nanmax as scipy_move_nanmax
w = a.shape[AXIS] // 5
@@ -522,14 +526,14 @@ def getsetups(setup, shapes, nans):
run['setups'] = getsetups(setup, shapes, nans)
if axis != 'None':
suite.append(run)
-
+
# Strip leading spaces from setup code
for i, run in enumerate(suite):
for j in range(len(run['setups'])):
t = run['setups'][j]
t = '\n'.join([z.strip() for z in t.split('\n')])
suite[i]['setups'][j] = t
-
+
# Set dtype and axis in setups
for i, run in enumerate(suite):
for j in range(len(run['setups'])):
@@ -546,4 +550,4 @@ def getsetups(setup, shapes, nans):
t = t.replace('AXIS', axis)
suite[i]['statements'][j] = t
- return suite
+ return suite
View
36,503 bottleneck/src/func/func.c
27,741 additions, 8,762 deletions not shown
View
25,644 bottleneck/src/move/move.c
18,250 additions, 7,394 deletions not shown
View
18 bottleneck/src/template/func/allnan.py
@@ -92,7 +92,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[2] = """\
@@ -119,7 +119,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------
-ints_None = deepcopy(ints)
+ints_None = deepcopy(ints)
ints_None['axisNone'] = True
loop = {}
@@ -226,7 +226,7 @@ def allnan(arr, axis=None):
def allnan_selector(arr, axis):
"""
Return allnan function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in bn.allnan()
is in checking that `axis` is within range, converting `arr` into an
@@ -241,7 +241,7 @@ def allnan_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which NaNs are searched.
-
+
Returns
-------
func : function
@@ -256,16 +256,16 @@ def allnan_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine if `arr` contains all NaNs:
>>> func, a = bn.func.allnan_selector(arr, axis=0)
>>> func
<function allnan_1d_float64_axisNone>
-
+
Use the returned function and array to determine is all elements are
NaN:
-
+
>>> func(a)
False
@@ -273,7 +273,7 @@ def allnan_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
@@ -292,4 +292,4 @@ def allnan_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
20 bottleneck/src/template/func/anynan.py
@@ -92,7 +92,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[2] = """\
@@ -111,7 +111,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------
-ints_None = deepcopy(ints)
+ints_None = deepcopy(ints)
ints_None['axisNone'] = True
loop = {}
@@ -186,7 +186,7 @@ def anynan(arr, axis=None):
>>> bn.anynan(a)
True
>>> bn.anynan(a, axis=0)
- array([False, True], dtype=bool)
+ array([False, True], dtype=bool)
"""
func, arr = anynan_selector(arr, axis)
@@ -195,7 +195,7 @@ def anynan(arr, axis=None):
def anynan_selector(arr, axis):
"""
Return anynan function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in bn.anynan()
is in checking that `axis` is within range, converting `arr` into an
@@ -210,7 +210,7 @@ def anynan_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which NaNs are searched.
-
+
Returns
-------
func : function
@@ -225,16 +225,16 @@ def anynan_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine if there are any NaN in `arr`:
>>> func, a = bn.func.anynan_selector(arr, axis=0)
>>> func
<function anynan_1d_float64_axisNone>
-
+
Use the returned function and array to determine if there are any
NaNs:
-
+
>>> func(a)
False
@@ -242,7 +242,7 @@ def anynan_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
@@ -261,4 +261,4 @@ def anynan_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
32 bottleneck/src/template/func/argpartsort.py
@@ -20,7 +20,7 @@
raise ValueError(PARTSORT_ERR_MSG % (n, nAXIS))
l = 0
r = nAXIS - 1
- with nogil:
+ with nogil:
while l < r:
x = b[k]
i = l
@@ -41,7 +41,7 @@
if j < k: l = i
if k < i: r = j
return y
-"""
+"""
loop[2] = """\
for i0 in range(n0):
for i1 in range(n1):
@@ -50,7 +50,7 @@
return y
if (n < 1) or (n > nAXIS):
raise ValueError(PARTSORT_ERR_MSG % (n, nAXIS))
- for iINDEX0 in range(nINDEX0):
+ for iINDEX0 in range(nINDEX0):
l = 0
r = nAXIS - 1
while l < r:
@@ -122,7 +122,7 @@
@cython.wraparound(False)
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int n):
"Partial sort of NDIMd array with dtype=DTYPE along axis=AXIS."
- cdef np.npy_intp i, j = 0, l, r, k = n-1, itmp
+ cdef np.npy_intp i, j = 0, l, r, k = n-1, itmp
cdef np.DTYPE_t x, tmp
cdef np.ndarray[np.DTYPE_t, ndim=NDIM] b = PyArray_Copy(a)
"""
@@ -132,7 +132,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int n):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
# Slow, unaccelerated ndim/dtype --------------------------------------------
@@ -157,7 +157,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int n):
# Select smallest k elements code used for inner loop of argpartsort method:
# http://projects.scipy.org/numpy/attachment/ticket/1213/quickselect.pyx
# (C) 2009 Sturla Molden
-# SciPy license
+# SciPy license
#
# From the original C function (code in public domain) in:
# Fast median search: an ANSI C implementation
@@ -191,7 +191,7 @@ def argpartsort(arr, n, axis=-1):
----------
arr : array_like
Input array. If `arr` is not an array, a conversion is attempted.
- n : int
+ n : int
The indices of the `n` smallest elements will appear in the first `n`
elements of the output array along the given `axis`.
axis : {int, None}, optional
@@ -208,7 +208,7 @@ def argpartsort(arr, n, axis=-1):
See Also
--------
bottleneck.partsort: Partial sorting of array elements along given axis.
-
+
Notes
-----
Unexpected results may occur if the input array contains NaN.
@@ -218,7 +218,7 @@ def argpartsort(arr, n, axis=-1):
Create a numpy array:
>>> a = np.array([1, 0, 3, 4, 2])
-
+
Find the indices that partially sort that array so that the first 3
elements are the smallest 3 elements:
@@ -231,7 +231,7 @@ def argpartsort(arr, n, axis=-1):
>>> a[index]
array([1, 0, 2, 4, 3])
-
+
"""
func, arr = argpartsort_selector(arr, axis)
return func(arr, n)
@@ -239,7 +239,7 @@ def argpartsort(arr, n, axis=-1):
def argpartsort_selector(arr, axis):
"""
Return argpartsort function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.argpartsort() is in checking that `axis` is within range, converting
@@ -255,7 +255,7 @@ def argpartsort_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which to partially sort.
-
+
Returns
-------
func : function
@@ -271,14 +271,14 @@ def argpartsort_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1, 0, 3, 4, 2])
-
+
Obtain the function needed to find the indices of a partial sort of `arr`
along axis=0:
>>> func, a = bn.func.argpartsort_selector(arr, axis=0)
>>> func
<function argpartsort_1d_int64_axis0>
-
+
Use the returned function and array to find the indices of the partial
sort:
@@ -289,7 +289,7 @@ def argpartsort_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef tuple key
cdef int ndim = PyArray_NDIM(a)
@@ -313,4 +313,4 @@ def argpartsort_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
7 bottleneck/src/template/func/func.py
@@ -56,7 +56,7 @@
from numpy cimport NPY_FLOAT64 as NPY_float64
from numpy cimport (PyArray_EMPTY, PyArray_TYPE, PyArray_NDIM,
PyArray_SIZE, PyArray_DIMS, import_array,
- PyArray_ArgSort, NPY_QUICKSORT, NPY_CORDER,
+ PyArray_ArgSort, NPY_QUICKSORT, NPY_CORDER,
PyArray_Ravel, PyArray_FillWithScalar, PyArray_Copy,
NPY_BOOL)
@@ -94,8 +94,8 @@
cdef extern from "math.h":
double sqrt(double x)
-
-PARTSORT_ERR_MSG = "`n` (=%d) must be between 1 and %d, inclusive."
+
+PARTSORT_ERR_MSG = "`n` (=%d) must be between 1 and %d, inclusive."
include "nanmax.pyx"
include "nanmin.pyx"
@@ -118,6 +118,7 @@
include "allnan.pyx"
"""
+
def funcpyx(funcs=funcs):
for func in funcs:
template(funcs[func])
View
44 bottleneck/src/template/func/median.py
@@ -16,8 +16,8 @@
return np.FLOAT(NAN)
k = nAXIS >> 1
l = 0
- r = nAXIS - 1
- with nogil:
+ r = nAXIS - 1
+ with nogil:
while l < r:
x = b[k]
i = l
@@ -34,7 +34,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if nAXIS % 2 == 0:
+ if nAXIS % 2 == 0:
amax = MINDTYPE
for i in range(k):
ai = b[i]
@@ -43,12 +43,12 @@
return np.FLOAT(0.5 * (b[k] + amax))
else:
return np.FLOAT(b[k])
-"""
+"""
loop[2] = """\
if nINDEX1 == 0:
PyArray_FillWithScalar(y, NAN)
return y
- for iINDEX0 in range(nINDEX0):
+ for iINDEX0 in range(nINDEX0):
k = nAXIS >> 1
l = 0
r = nAXIS - 1
@@ -68,7 +68,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if nAXIS % 2 == 0:
+ if nAXIS % 2 == 0:
amax = MINDTYPE
for i in range(k):
ai = b[INDEXREPLACE|i|]
@@ -76,7 +76,7 @@
amax = ai
y[INDEXPOP] = 0.5 * (b[INDEXREPLACE|k|] + amax)
else:
- y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
+ y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
return y
"""
loop[3] = """\
@@ -104,7 +104,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if nAXIS % 2 == 0:
+ if nAXIS % 2 == 0:
amax = MINDTYPE
for i in range(k):
ai = b[INDEXREPLACE|i|]
@@ -112,7 +112,7 @@
amax = ai
y[INDEXPOP] = 0.5 * (b[INDEXREPLACE|k|] + amax)
else:
- y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
+ y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
return y
"""
@@ -129,7 +129,7 @@
@cython.wraparound(False)
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"Median of NDIMd array with dtype=DTYPE along axis=AXIS."
- cdef np.npy_intp i, j = 0, l, r, k
+ cdef np.npy_intp i, j = 0, l, r, k
cdef np.DTYPE_t x, tmp, amax, ai
cdef np.ndarray[np.DTYPE_t, ndim=NDIM] b = PyArray_Copy(a)
"""
@@ -142,7 +142,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
ints['force_output_dtype'] = 'float64'
ints['loop'] = {}
ints['loop'][1] = loop[1].replace('FLOAT', 'float64')
@@ -172,7 +172,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Select smallest k elements code used for inner loop of median method:
# http://projects.scipy.org/numpy/attachment/ticket/1213/quickselect.pyx
# (C) 2009 Sturla Molden
-# SciPy license
+# SciPy license
#
# From the original C function (code in public domain) in:
# Fast median search: an ANSI C implementation
@@ -203,11 +203,11 @@ def median(arr, axis=None):
y : ndarray
An array with the same shape as `arr`, except that the specified axis
has been removed. If `arr` is a 0d array, or if axis is None, a scalar
- is returned. `float64` return values are used for integer inputs.
-
+ is returned. `float64` return values are used for integer inputs.
+
See also
--------
- bottleneck.nanmedian: Median along specified axis ignoring NaNs.
+ bottleneck.nanmedian: Median along specified axis ignoring NaNs.
Notes
-----
@@ -226,7 +226,7 @@ def median(arr, axis=None):
array([ 6.5, 4.5, 2.5])
>>> bn.median(a, axis=1)
array([ 7., 2.])
-
+
"""
func, arr = median_selector(arr, axis)
return func(arr)
@@ -234,7 +234,7 @@ def median(arr, axis=None):
def median_selector(arr, axis):
"""
Return median function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.median() is in checking that `axis` is within range, converting `arr`
@@ -250,7 +250,7 @@ def median_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the median is to be computed.
-
+
Returns
-------
func : function
@@ -266,13 +266,13 @@ def median_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the median of `arr` along axis=0:
>>> func, a = bn.func.median_selector(arr, axis=0)
>>> func
<function median_1d_float64_axis0>
-
+
Use the returned function and array to determine the median:
>>> func(a)
@@ -282,7 +282,7 @@ def median_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef tuple key
cdef int ndim = PyArray_NDIM(a)
@@ -306,4 +306,4 @@ def median_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
28 bottleneck/src/template/func/nanargmax.py
@@ -38,7 +38,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amax = ai
allnan = 0
idx = iINDEX0
- if allnan == 0:
+ if allnan == 0:
return np.intp(idx)
else:
return NAN
@@ -56,7 +56,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amax = ai
allnan = 0
idx = iINDEX1
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = idx
else:
raise ValueError(CANNOTCONVERT)
@@ -76,7 +76,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amax = ai
allnan = 0
idx = iINDEX2
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = idx
else:
raise ValueError(CANNOTCONVERT)
@@ -88,7 +88,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[1] = """\
@@ -162,7 +162,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
def nanargmax(arr, axis=None):
"""
Indices of the maximum values along an axis, ignoring NaNs.
-
+
Parameters
----------
a : array_like
@@ -170,7 +170,7 @@ def nanargmax(arr, axis=None):
axis : {int, None}, optional
Axis along which to operate. By default (axis=None) flattened input
is used.
-
+
See also
--------
bottleneck.nanargmin: Indices of the minimum values along an axis.
@@ -180,7 +180,7 @@ def nanargmax(arr, axis=None):
-------
index_array : ndarray
An array of indices or a single index value.
-
+
Examples
--------
>>> a = np.array([[np.nan, 4], [2, 3]])
@@ -192,7 +192,7 @@ def nanargmax(arr, axis=None):
array([1, 0])
>>> bn.nanargmax(a, axis=1)
array([1, 1])
-
+
"""
func, arr = nanargmax_selector(arr, axis)
return func(arr)
@@ -200,7 +200,7 @@ def nanargmax(arr, axis=None):
def nanargmax_selector(arr, axis):
"""
Return nanargmax function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.nanargmax() is in checking that `axis` is within range, converting
@@ -216,7 +216,7 @@ def nanargmax_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the indices are found.
-
+
Returns
-------
func : function
@@ -231,16 +231,16 @@ def nanargmax_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the nanargmax of `arr` along
axis=0:
>>> func, a = bn.func.nanargmax_selector(arr, axis=0)
>>> func
<function nanargmax_1d_float64_axis0>
-
+
Use the returned function and array to determine the maximum:
-
+
>>> func(a)
2
@@ -248,7 +248,7 @@ def nanargmax_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
View
30 bottleneck/src/template/func/nanargmin.py
@@ -38,7 +38,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amin = ai
allnan = 0
idx = iINDEX0
- if allnan == 0:
+ if allnan == 0:
return np.intp(idx)
else:
return NAN
@@ -56,7 +56,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amin = ai
allnan = 0
idx = iINDEX1
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = idx
else:
raise ValueError(CANNOTCONVERT)
@@ -64,7 +64,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"""
loop[3] = """\
if nINDEX2 == 0:
- msg = "numpy.nanargmin raises on a.shape[axis]==0; Bottleneck too."
+ msg = "numpy.nanargmin raises on a.shape[axis]==0; Bottleneck too."
raise ValueError(msg)
for iINDEX0 in range(nINDEX0 - 1, -1, -1):
for iINDEX1 in range(nINDEX1 - 1, -1, -1):
@@ -76,7 +76,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
amin = ai
allnan = 0
idx = iINDEX2
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = idx
else:
raise ValueError(CANNOTCONVERT)
@@ -88,7 +88,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[1] = """\
@@ -162,7 +162,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
def nanargmin(arr, axis=None):
"""
Indices of the minimum values along an axis, ignoring NaNs.
-
+
Parameters
----------
a : array_like
@@ -170,7 +170,7 @@ def nanargmin(arr, axis=None):
axis : {int, None}, optional
Axis along which to operate. By default (axis=None) flattened input
is used.
-
+
See also
--------
bottleneck.nanargmax: Indices of the maximum values along an axis.
@@ -180,7 +180,7 @@ def nanargmin(arr, axis=None):
-------
index_array : ndarray
An array of indices or a single index value.
-
+
Examples
--------
>>> a = np.array([[np.nan, 4], [2, 3]])
@@ -192,7 +192,7 @@ def nanargmin(arr, axis=None):
array([1, 1])
>>> bn.nanargmax(a, axis=1)
array([1, 0])
-
+
"""
func, arr = nanargmin_selector(arr, axis)
return func(arr)
@@ -200,7 +200,7 @@ def nanargmin(arr, axis=None):
def nanargmin_selector(arr, axis):
"""
Return nanargmin function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.nanargmin() is in checking that `axis` is within range, converting
@@ -216,7 +216,7 @@ def nanargmin_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the indices are found.
-
+
Returns
-------
func : function
@@ -231,16 +231,16 @@ def nanargmin_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the nanargmin of `arr` along
axis=0:
>>> func, a = bn.func.nanargmin_selector(arr, axis=0)
>>> func
<function nanargmin_1d_float64_axis0>
-
+
Use the returned function and array to determine the maximum:
-
+
>>> func(a)
0
@@ -248,7 +248,7 @@ def nanargmin_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
View
42 bottleneck/src/template/func/nanmax.py
@@ -28,7 +28,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
loop = {}
loop[2] = """\
if nINDEX1 == 0:
- msg = "numpy.nanmax raises on a.shape[axis]==0; so Bottleneck does."
+ msg = "numpy.nanmax raises on a.shape[axis]==0; so Bottleneck does."
raise ValueError(msg)
for iINDEX0 in range(nINDEX0):
amax = MINDTYPE
@@ -38,7 +38,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = amax
else:
y[INDEXPOP] = NAN
@@ -46,7 +46,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"""
loop[3] = """\
if nINDEX2 == 0:
- msg = "numpy.nanmax raises on a.shape[axis]==0; so Bottleneck does."
+ msg = "numpy.nanmax raises on a.shape[axis]==0; so Bottleneck does."
raise ValueError(msg)
for iINDEX0 in range(nINDEX0):
for iINDEX1 in range(nINDEX1):
@@ -57,7 +57,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = amax
else:
y[INDEXPOP] = NAN
@@ -74,7 +74,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
loop = {}
loop[1] = """\
if nINDEX0 == 0:
- m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amax = MINDTYPE
for iINDEX0 in range(nINDEX0):
@@ -82,14 +82,14 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amax)
else:
return np.DTYPE(NAN)
"""
loop[2] = """\
if nINDEX0 * nINDEX1 == 0:
- m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amax = MINDTYPE
for iINDEX0 in range(nINDEX0):
@@ -98,14 +98,14 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amax)
else:
return np.DTYPE(NAN)
"""
loop[3] = """\
if nINDEX0 * nINDEX1 * nINDEX2 == 0:
- m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmax raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amax = MINDTYPE
for iINDEX0 in range(nINDEX0):
@@ -115,7 +115,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amax)
else:
return np.DTYPE(NAN)
@@ -126,7 +126,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[2] = """\
@@ -161,7 +161,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------
-ints_None = deepcopy(ints)
+ints_None = deepcopy(ints)
ints_None['axisNone'] = True
loop = {}
@@ -248,8 +248,8 @@ def nanmax(arr, axis=None):
See also
--------
bottleneck.nanmin: Minimum along specified axis, ignoring NaNs.
- bottleneck.nanargmax: Indices of maximum values along axis, ignoring NaNs.
-
+ bottleneck.nanargmax: Indices of maximum values along axis, ignoring NaNs.
+
Examples
--------
>>> bn.nanmax(1)
@@ -263,7 +263,7 @@ def nanmax(arr, axis=None):
4.0
>>> bn.nanmax(a, axis=0)
array([ 1., 4.])
-
+
"""
func, arr = nanmax_selector(arr, axis)
return func(arr)
@@ -271,7 +271,7 @@ def nanmax(arr, axis=None):
def nanmax_selector(arr, axis):
"""
Return nanmax function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in bn.nanmax()
is in checking that `axis` is within range, converting `arr` into an
@@ -287,7 +287,7 @@ def nanmax_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the maximum is to be computed.
-
+
Returns
-------
func : function
@@ -303,16 +303,16 @@ def nanmax_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the maximum of `arr` along
axis=0:
>>> func, a = bn.func.nanmax_selector(arr, axis=0)
>>> func
<function nanmax_1d_float64_axis0>
-
+
Use the returned function and array to determine the maximum:
-
+
>>> func(a)
3.0
@@ -320,7 +320,7 @@ def nanmax_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
View
38 bottleneck/src/template/func/nanmean.py
@@ -35,7 +35,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai == ai:
asum += ai
count += 1
- if count > 0:
+ if count > 0:
y[INDEXPOP] = asum / count
else:
y[INDEXPOP] = NAN
@@ -51,7 +51,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai == ai:
asum += ai
count += 1
- if count > 0:
+ if count > 0:
y[INDEXPOP] = asum / count
else:
y[INDEXPOP] = NAN
@@ -69,7 +69,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
return np.DTYPE(asum / count)
else:
return np.DTYPE(NAN)
-"""
+"""
loop = {}
loop[1] = """\
@@ -101,7 +101,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
ints['force_output_dtype'] = 'float64'
ints['top'] = """
@@ -140,7 +140,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------
-ints_None = deepcopy(ints)
+ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True
@@ -149,28 +149,28 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
size = nINDEX0
for iINDEX0 in range(nINDEX0):
asum += a[INDEXALL]
- if size > 0:
+ if size > 0:
return np.float64(asum / size)
else:
return np.float64(NAN)
"""
loop[2] = """\
- size = nINDEX0 * nINDEX1
+ size = nINDEX0 * nINDEX1
for iINDEX0 in range(nINDEX0):
for iINDEX1 in range(nINDEX1):
asum += a[INDEXALL]
- if size > 0:
+ if size > 0:
return np.float64(asum / size)
else:
return np.float64(NAN)
"""
loop[3] = """\
- size = nINDEX0 * nINDEX1 * nINDEX2
+ size = nINDEX0 * nINDEX1 * nINDEX2
for iINDEX0 in range(nINDEX0):
for iINDEX1 in range(nINDEX1):
for iINDEX2 in range(nINDEX2):
asum += a[INDEXALL]
- if size > 0:
+ if size > 0:
return np.float64(asum / size)
else:
return np.float64(NAN)
@@ -220,12 +220,12 @@ def nanmean(arr, axis=None):
y : ndarray
An array with the same shape as `arr`, with the specified axis removed.
If `arr` is a 0-d array, or if axis is None, a scalar is returned.
- `float64` intermediate and return values are used for integer inputs.
+ `float64` intermediate and return values are used for integer inputs.
See also
--------
bottleneck.nanmedian: Median along specified axis, ignoring NaNs.
-
+
Notes
-----
No error is raised on overflow. (The sum is computed and then the result
@@ -257,7 +257,7 @@ def nanmean(arr, axis=None):
-inf
>>> bn.nanmean([1, np.nan, np.inf, np.NINF])
nan
-
+
"""
func, arr = nanmean_selector(arr, axis)
return func(arr)
@@ -265,7 +265,7 @@ def nanmean(arr, axis=None):
def nanmean_selector(arr, axis):
"""
Return nanmean function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.nanmean() is in checking that `axis` is within range, converting `arr`
@@ -281,7 +281,7 @@ def nanmean_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the mean is to be computed.
-
+
Returns
-------
func : function
@@ -296,13 +296,13 @@ def nanmean_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the nanmean of `arr` along axis=0:
>>> func, a = bn.func.nanmean_selector(arr, axis=0)
>>> func
<function nanmean_1d_float64_axis0>
-
+
Use the returned function and array to determine the mean:
>>> func(a)
@@ -312,7 +312,7 @@ def nanmean_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
@@ -331,4 +331,4 @@ def nanmean_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
58 bottleneck/src/template/func/nanmedian.py
@@ -21,7 +21,7 @@
while b[j] != b[j]:
if j <= 0:
break
- j -= 1
+ j -= 1
if i >= j:
flag = 0
break
@@ -31,8 +31,8 @@
n = i + flag
k = n >> 1
l = 0
- r = n - 1
- with nogil:
+ r = n - 1
+ with nogil:
while l < r:
x = b[k]
i = l
@@ -49,7 +49,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if n % 2 == 0:
+ if n % 2 == 0:
amax = MINDTYPE
allnan = 1
for i in range(k):
@@ -57,13 +57,13 @@
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.FLOAT(0.5 * (b[k] + amax))
else:
return np.FLOAT(b[k])
else:
return np.FLOAT(b[k])
-"""
+"""
loop[2] = """\
if nINDEX1 == 0:
PyArray_FillWithScalar(y, NAN)
@@ -76,7 +76,7 @@
while b[INDEXREPLACE|j|] != b[INDEXREPLACE|j|]:
if j <= 0:
break
- j -= 1
+ j -= 1
if i >= j:
flag = 0
break
@@ -103,7 +103,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if n % 2 == 0:
+ if n % 2 == 0:
amax = MINDTYPE
allnan = 1
for i in range(k):
@@ -111,12 +111,12 @@
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = 0.5 * (b[INDEXREPLACE|k|] + amax)
else:
- y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
+ y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
else:
- y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
+ y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
return y
"""
loop[3] = """\
@@ -132,7 +132,7 @@
while b[INDEXREPLACE|j|] != b[INDEXREPLACE|j|]:
if j <= 0:
break
- j -= 1
+ j -= 1
if i >= j:
flag = 0
break
@@ -159,7 +159,7 @@
if i > j: break
if j < k: l = i
if k < i: r = j
- if n % 2 == 0:
+ if n % 2 == 0:
amax = MINDTYPE
allnan = 1
for i in range(k):
@@ -167,12 +167,12 @@
if ai >= amax:
amax = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = 0.5 * (b[INDEXREPLACE|k|] + amax)
else:
y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
else:
- y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
+ y[INDEXPOP] = CASTb[INDEXREPLACE|k|]
return y
"""
@@ -190,7 +190,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"Median of NDIMd array with dtype=DTYPE along axis=AXIS."
cdef int allnan = 1, flag = 0
- cdef np.npy_intp i = 0, j = 0, l, r, k, n
+ cdef np.npy_intp i = 0, j = 0, l, r, k, n
cdef np.DTYPE_t x, tmp, amax, ai
cdef np.ndarray[np.DTYPE_t, ndim=NDIM] b = PyArray_Copy(a)
"""
@@ -203,7 +203,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
ints['reuse_non_nan_func'] = True
# Slow, unaccelerated ndim/dtype --------------------------------------------
@@ -229,7 +229,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Select smallest k elements code used for inner loop of median method:
# http://projects.scipy.org/numpy/attachment/ticket/1213/quickselect.pyx
# (C) 2009 Sturla Molden
-# SciPy license
+# SciPy license
#
# From the original C function (code in public domain) in:
# Fast median search: an ANSI C implementation
@@ -260,16 +260,16 @@ def nanmedian(arr, axis=None):
y : ndarray
An array with the same shape as `arr`, except that the specified axis
has been removed. If `arr` is a 0d array, or if axis is None, a scalar
- is returned. `float64` return values are used for integer inputs.
-
+ is returned. `float64` return values are used for integer inputs.
+
See also
--------
- bottleneck.median: Median along specified axis.
+ bottleneck.median: Median along specified axis.
Examples
--------
>>> a = np.array([[np.nan, 7, 4], [3, 2, 1]])
- >>> a
+ >>> a
array([[ nan, 7., 4.],
[ 3., 2., 1.]])
>>> bn.nanmedian(a)
@@ -278,7 +278,7 @@ def nanmedian(arr, axis=None):
array([ 3. , 4.5, 2.5])
>> bn.nanmedian(a, axis=1)
array([ 5.5, 2. ])
-
+
"""
func, arr = nanmedian_selector(arr, axis)
return func(arr)
@@ -286,7 +286,7 @@ def nanmedian(arr, axis=None):
def nanmedian_selector(arr, axis):
"""
Return nanmedian function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in
bn.nanmedian() is in checking that `axis` is within range, converting `arr`
@@ -302,7 +302,7 @@ def nanmedian_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the median is to be computed.
-
+
Returns
-------
func : function
@@ -318,13 +318,13 @@ def nanmedian_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the median of `arr` along axis=0:
>>> func, a = bn.func.nanmedian_selector(arr, axis=0)
>>> func
<function nanmedian_1d_float64_axis0>
-
+
Use the returned function and array to determine the median:
>>> func(a)
@@ -334,7 +334,7 @@ def nanmedian_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef tuple key
cdef int ndim = PyArray_NDIM(a)
@@ -358,4 +358,4 @@ def nanmedian_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
40 bottleneck/src/template/func/nanmin.py
@@ -38,7 +38,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai <= amin:
amin = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = amin
else:
y[INDEXPOP] = NAN
@@ -46,7 +46,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"""
loop[3] = """\
if nINDEX2 == 0:
- msg = "numpy.nanmin raises on a.shape[axis]==0; so Bottleneck does."
+ msg = "numpy.nanmin raises on a.shape[axis]==0; so Bottleneck does."
raise ValueError(msg)
for iINDEX0 in range(nINDEX0):
for iINDEX1 in range(nINDEX1):
@@ -57,7 +57,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai <= amin:
amin = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
y[INDEXPOP] = amin
else:
y[INDEXPOP] = NAN
@@ -74,7 +74,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
loop = {}
loop[1] = """\
if nINDEX0 == 0:
- m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amin = MAXDTYPE
for iINDEX0 in range(nINDEX0):
@@ -82,14 +82,14 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai <= amin:
amin = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amin)
else:
return np.DTYPE(NAN)
"""
loop[2] = """\
if nINDEX0 * nINDEX1 == 0:
- m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amin = MAXDTYPE
for iINDEX0 in range(nINDEX0):
@@ -98,14 +98,14 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai <= amin:
amin = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amin)
else:
return np.DTYPE(NAN)
"""
loop[3] = """\
if nINDEX0 * nINDEX1 * nINDEX2 == 0:
- m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
+ m = "numpy.nanmin raises on a.size==0 and axis=None; Bottleneck too."
raise ValueError(m)
amin = MAXDTYPE
for iINDEX0 in range(nINDEX0):
@@ -115,7 +115,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
if ai <= amin:
amin = ai
allnan = 0
- if allnan == 0:
+ if allnan == 0:
return np.DTYPE(amin)
else:
return np.DTYPE(NAN)
@@ -126,7 +126,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (not axis=None) ------------------------------------------------
ints = deepcopy(floats)
-ints['dtypes'] = INT_DTYPES
+ints['dtypes'] = INT_DTYPES
loop = {}
loop[2] = """\
@@ -161,7 +161,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------
-ints_None = deepcopy(ints)
+ints_None = deepcopy(ints)
ints_None['axisNone'] = True
loop = {}
@@ -248,7 +248,7 @@ def nanmin(arr, axis=None):
See also
--------
bottleneck.nanmax: Maximum along specified axis, ignoring NaNs.
- bottleneck.nanargmin: Indices of minimum values along axis, ignoring NaNs.
+ bottleneck.nanargmin: Indices of minimum values along axis, ignoring NaNs.
Examples
--------
@@ -263,7 +263,7 @@ def nanmin(arr, axis=None):
1.0
>>> bn.nanmin(a, axis=0)
array([ 1., 4.])
-
+
"""
func, arr = nanmin_selector(arr, axis)
return func(arr)
@@ -271,7 +271,7 @@ def nanmin(arr, axis=None):
def nanmin_selector(arr, axis):
"""
Return nanmin function and array that matches `arr` and `axis`.
-
+
Under the hood Bottleneck uses a separate Cython function for each
combination of ndim, dtype, and axis. A lot of the overhead in bn.nanmin()
is in checking that `axis` is within range, converting `arr` into an
@@ -287,7 +287,7 @@ def nanmin_selector(arr, axis):
Input array. If `arr` is not an array, a conversion is attempted.
axis : {int, None}
Axis along which the minimum is to be computed.
-
+
Returns
-------
func : function
@@ -303,16 +303,16 @@ def nanmin_selector(arr, axis):
Create a numpy array:
>>> arr = np.array([1.0, 2.0, 3.0])
-
+
Obtain the function needed to determine the minimum of `arr` along
axis=0:
>>> func, a = bn.func.nanmin_selector(arr, axis=0)
>>> func
<function nanmin_1d_float64_axis0>
-
+
Use the returned function and array to determine the minimum:
-
+
>>> func(a)
1.0
@@ -320,7 +320,7 @@ def nanmin_selector(arr, axis):
cdef np.ndarray a
if type(arr) is np.ndarray:
a = arr
- else:
+ else:
a = np.array(arr, copy=False)
cdef int ndim = PyArray_NDIM(a)
cdef int dtype = PyArray_TYPE(a)
@@ -339,4 +339,4 @@ def nanmin_selector(arr, axis):
tup = (str(ndim), str(a.dtype), str(axis))
raise TypeError("Unsupported ndim/dtype/axis (%s/%s/%s)." % tup)
return func, a
-'''
+'''
View
34 bottleneck/src/template/func/nanrankdata.py
@@ -9,7 +9,7 @@
INT_DTYPES = [x for x in bn.dtypes if 'int' in x]
# loops ---------------------------------------------------------------------
-
+
loop = {}
loop[1] = """\
if nINDEX0 == 0:
@@ -30,7 +30,7 @@
y[INDEXREPLACE|ivec[iINDEX0]|] = NAN
sumranks = 0
dupcount = 0
- old = new
+ old = new
sumranks += (nINDEX0 - 1)
dupcount += 1
if old == old:
@@ -40,7 +40,7 @@
else:
y[INDEXREPLACE|ivec[nINDEX0 - 1]|] = NAN
return y
-"""
+"""
loop[2] = """\