summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/item_selection.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index ee66378a9..33d378c2b 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -2398,19 +2398,14 @@ PyArray_CountNonzero(PyArrayObject *self)
npy_intp *strideptr, *innersizeptr;
NPY_BEGIN_THREADS_DEF;
- // Special low-overhead version specific to the boolean/int types
dtype = PyArray_DESCR(self);
- switch(dtype->kind) {
- case 'u':
- case 'i':
- case 'b':
- if (dtype->elsize > 8) {
- break;
- }
- return count_nonzero_int(
- PyArray_NDIM(self), PyArray_BYTES(self), PyArray_DIMS(self),
- PyArray_STRIDES(self), dtype->elsize
- );
+ /* Special low-overhead version specific to the boolean/int types */
+ if (PyArray_ISALIGNED(self) && (
+ PyDataType_ISBOOL(dtype) || PyDataType_ISINTEGER(dtype))) {
+ return count_nonzero_int(
+ PyArray_NDIM(self), PyArray_BYTES(self), PyArray_DIMS(self),
+ PyArray_STRIDES(self), dtype->elsize
+ );
}
nonzero = PyArray_DESCR(self)->f->nonzero;