summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2013-09-28 16:30:37 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2013-09-28 17:15:51 +0200
commit58d79003da26c9fb9919a82b64295338360106ba (patch)
treed8d12162e839afecaaab265a9f16922e0161f7e2 /numpy
parent1475cfa46356c63c337b2d3d5903be2451dbb9c5 (diff)
downloadnumpy-58d79003da26c9fb9919a82b64295338360106ba.tar.gz
ENH: reduce calls to npy_is_aligned in _IsAligned
one can just bitwise_or the memory and all strides and call npy_is_aligned on that to get the same result.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/common.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index 5a7a58b33..4e2d64be3 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -675,7 +675,8 @@ _zerofill(PyArrayObject *ret)
NPY_NO_EXPORT int
_IsAligned(PyArrayObject *ap)
{
- unsigned int i, aligned = 1;
+ unsigned int i;
+ npy_uintp aligned;
const unsigned int alignment = PyArray_DESCR(ap)->alignment;
/* The special casing for STRING and VOID types was removed
@@ -688,24 +689,24 @@ _IsAligned(PyArrayObject *ap)
if (alignment == 1) {
return 1;
}
- aligned = npy_is_aligned(PyArray_DATA(ap), alignment);
+ aligned = (npy_uintp)PyArray_DATA(ap);
for (i = 0; i < PyArray_NDIM(ap); i++) {
#if NPY_RELAXED_STRIDES_CHECKING
+ /* skip dim == 1 as it is not required to have stride 0 */
if (PyArray_DIM(ap, i) > 1) {
/* if shape[i] == 1, the stride is never used */
- aligned &= npy_is_aligned((void*)PyArray_STRIDES(ap)[i],
- alignment);
+ aligned |= (npy_uintp)PyArray_STRIDES(ap)[i];
}
else if (PyArray_DIM(ap, i) == 0) {
/* an array with zero elements is always aligned */
return 1;
}
#else /* not NPY_RELAXED_STRIDES_CHECKING */
- aligned &= npy_is_aligned((void*)PyArray_STRIDES(ap)[i], alignment);
+ aligned |= (npy_uintp)PyArray_STRIDES(ap)[i];
#endif /* not NPY_RELAXED_STRIDES_CHECKING */
}
- return aligned != 0;
+ return npy_is_aligned(aligned, alignment);
}
NPY_NO_EXPORT npy_bool