Skip to content

Commit

Permalink
Merge pull request #20295 from charris/backport-20179
Browse files Browse the repository at this point in the history
BUG: Do not use nonzero fastpath on unaligned arrays
  • Loading branch information
charris committed Nov 4, 2021
2 parents 496c9c0 + 1ffbc3c commit 5fe9833
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions numpy/core/src/multiarray/item_selection.c
Expand Up @@ -2390,19 +2390,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;
Expand Down

0 comments on commit 5fe9833

Please sign in to comment.