Skip to content

Commit

Permalink
BUG Wrong output for very large input arrays.
Browse files Browse the repository at this point in the history
Closes #35.
  • Loading branch information
kwgoodman committed Mar 17, 2012
1 parent 6de1216 commit 7147ad8
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions RELEASE.rst
Expand Up @@ -23,6 +23,7 @@ Bottleneck 0.6.0

- #31 Confusing error message in partsort and argpartsort
- #32 Update path in MANIFEST.in
- #35 Wrong output for very large (2**31) input arrays

Older versions
==============
Expand Down
4 changes: 2 additions & 2 deletions bottleneck/src/template/func/nanmean.py
Expand Up @@ -21,7 +21,7 @@
@cython.wraparound(False)
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
"Mean of NDIMd array with dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef np.DTYPE_t asum = 0, ai
"""

Expand Down Expand Up @@ -141,7 +141,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------

ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef int size\n"
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True

loop = {}
Expand Down
4 changes: 2 additions & 2 deletions bottleneck/src/template/func/nanstd.py
Expand Up @@ -21,7 +21,7 @@
@cython.wraparound(False)
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
"Variance of NDIMd array with dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef np.DTYPE_t asum = 0, amean, ai
"""

Expand Down Expand Up @@ -193,7 +193,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
# Int dtypes (axis=None) ----------------------------------------------------

ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef int size\n"
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True

loop = {}
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/func/nansum.py
Expand Up @@ -135,7 +135,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------

ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef int size\n"
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True

loop = {}
Expand Down
4 changes: 2 additions & 2 deletions bottleneck/src/template/func/nanvar.py
Expand Up @@ -21,7 +21,7 @@
@cython.wraparound(False)
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
"Variance of NDIMd array with dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef np.DTYPE_t asum = 0, amean, ai
"""

Expand Down Expand Up @@ -193,7 +193,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
# Int dtypes (axis=None) ----------------------------------------------------

ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef int size\n"
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True

loop = {}
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_max.py
Expand Up @@ -197,7 +197,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int window):
"Moving max of NDIMd array of dtype=DTYPE along axis=AXIS."
cdef np.float64_t ai, aold
cdef int count
cdef Py_ssize_t count
cdef pairs* ring
cdef pairs* minpair
cdef pairs* end
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_mean.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window):
"Moving mean of NDIMd array of dtype=DTYPE along axis=AXIS."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, ai, aold
"""

Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_min.py
Expand Up @@ -197,7 +197,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int window):
"Moving min of NDIMd array of dtype=DTYPE along axis=AXIS."
cdef np.float64_t ai, aold
cdef int count
cdef Py_ssize_t count
cdef pairs* ring
cdef pairs* minpair
cdef pairs* end
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_nanmax.py
Expand Up @@ -197,7 +197,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int window):
"Moving max of NDIMd array of dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef np.float64_t ai, aold
cdef int count
cdef Py_ssize_t count
cdef pairs* ring
cdef pairs* minpair
cdef pairs* end
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_nanmean.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window):
"Moving mean of NDIMd array of dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, aold, ai
"""

Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_nanmin.py
Expand Up @@ -197,7 +197,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int window):
"Moving min of NDIMd array of dtype=DTYPE along axis=AXIS ignoring NaNs."
cdef np.float64_t ai, aold
cdef int count
cdef Py_ssize_t count
cdef pairs* ring
cdef pairs* minpair
cdef pairs* end
Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_nanstd.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window, int ddof):
"Moving std of NDIMd array of dtype=DTYPE along axis=AXIS, ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, a2sum = 0, ai
"""

Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_nansum.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window):
"Moving sum of NDIMd array of dtype=DTYPE along axis=AXIS, ignoring NaNs."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, ai, aold
"""

Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_std.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window, int ddof):
"Moving std of NDIMd array of dtype=DTYPE along axis=AXIS."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, a2sum = 0, ai
"""

Expand Down
2 changes: 1 addition & 1 deletion bottleneck/src/template/move/move_sum.py
Expand Up @@ -23,7 +23,7 @@
def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a,
int window):
"Moving sum of NDIMd array of dtype=DTYPE along axis=AXIS."
cdef int count = 0
cdef Py_ssize_t count = 0
cdef double asum = 0, ai, aold
"""

Expand Down
18 changes: 9 additions & 9 deletions bottleneck/src/template/template.py
Expand Up @@ -234,8 +234,8 @@ def loop_cdef(ndim, dtype, axis, is_reducing_function, cdef_output=True):
The output string contains code for: index array counters, one for each
dimension (cdef Py_size_t i0, i1, i2, ....); the length along each
dimension of the input array, `a` (cdef int n0 = a.shape[0],...); the
initialized, empty output array, `y`.
dimension of the input array, `a` (cdef Py_ssize_t n0 = a.shape[0],...);
the initialized, empty output array, `y`.
Parameters
----------
Expand Down Expand Up @@ -275,9 +275,9 @@ def loop_cdef(ndim, dtype, axis, is_reducing_function, cdef_output=True):
cdef Py_ssize_t i0, i1, i2
cdef np.npy_intp *dim
dim = PyArray_DIMS(a)
cdef int n0 = dim[0]
cdef int n1 = dim[1]
cdef int n2 = dim[2]
Py_ssize_t n0 = dim[0]
Py_ssize_t n1 = dim[1]
Py_ssize_t n2 = dim[2]
cdef np.npy_intp *dims = [n0, n2]
cdef np.ndarray[np.float64_t, ndim=2] y = PyArray_EMPTY(2, dims,
NPY_float64, 0)
Expand All @@ -289,9 +289,9 @@ def loop_cdef(ndim, dtype, axis, is_reducing_function, cdef_output=True):
cdef Py_ssize_t i0, i1, i2
cdef np.npy_intp *dim
dim = PyArray_DIMS(a)
cdef int n0 = dim[0]
cdef int n1 = dim[1]
cdef int n2 = dim[2]
Py_ssize_t n0 = dim[0]
Py_ssize_t n1 = dim[1]
Py_ssize_t n2 = dim[2]
cdef np.npy_intp *dims = [n0, n1, n2]
cdef np.ndarray[np.float64_t, ndim=3] y = PyArray_EMPTY(3, dims,
NPY_float64, 0)
Expand All @@ -316,7 +316,7 @@ def loop_cdef(ndim, dtype, axis, is_reducing_function, cdef_output=True):
cdefs.append(tab + "cdef np.npy_intp *dim")
cdefs.append(tab + "dim = PyArray_DIMS(a)")
for dim in range(ndim):
cdefs.append(tab + "cdef int n%d = dim[%d]" % (dim, dim))
cdefs.append(tab + "cdef Py_ssize_t n%d = dim[%d]" % (dim, dim))

if not cdef_output:
return '\n'.join(cdefs) + '\n'
Expand Down

0 comments on commit 7147ad8

Please sign in to comment.