summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2013-03-21 16:34:44 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2013-04-01 21:12:51 +0200
commit3a4ed02bca07d0995aedc8846b7aeac7af3bf310 (patch)
tree04c0c1d112db1ffb1b7e2437ea00aaab769059c9 /numpy
parent79d22dcef7947347660cbb953cb54ee3b38822f5 (diff)
downloadnumpy-3a4ed02bca07d0995aedc8846b7aeac7af3bf310.tar.gz
ENH: Relax aligned flag for shape[i] <= 1
In this case, either the dimensions stride will never be used to access an element, so that it does not matter to the data alignment, or the array has a size of 0 and is thus never unaligned. Relaxed align flag is only active if NPY_RELAXED_STRIDES_CHECKING was set during compile time.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/common.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index f27de491f..f0a6a761c 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -628,8 +628,20 @@ _IsAligned(PyArrayObject *ap)
}
ptr = (npy_intp) PyArray_DATA(ap);
aligned = (ptr % alignment) == 0;
+
for (i = 0; i < PyArray_NDIM(ap); i++) {
+#if NPY_RELAXED_STRIDES_CHECKING
+ if (PyArray_DIM(ap, i) > 1) {
+ /* if shape[i] == 1, the stride is never used */
+ aligned &= ((PyArray_STRIDES(ap)[i] % alignment) == 0);
+ }
+ else if (PyArray_DIM(ap, i) == 0) {
+ /* an array with zero elements is always aligned */
+ return 1;
+ }
+#else /* not NPY_RELAXED_STRIDES_CHECKING */
aligned &= ((PyArray_STRIDES(ap)[i] % alignment) == 0);
+#endif /* not NPY_RELAXED_STRIDES_CHECKING */
}
return aligned != 0;
}