summaryrefslogtreecommitdiff
path: root/numpy/core/src/common
diff options
context:
space:
mode:
authorAllan Haldane <allan.haldane@gmail.com>2017-06-28 16:08:30 -0400
committerAllan Haldane <allan.haldane@gmail.com>2018-09-27 15:43:54 -0400
commit27d4ce926b7166c9e7fe88f7b64f8636cb464ee3 (patch)
treeec4d1e624ae9575e2e636d0dd1ff51fc0229cfea /numpy/core/src/common
parentb76c0dfbf9eec3bd3ac6ec2fc7b507bee8f3c0e1 (diff)
downloadnumpy-27d4ce926b7166c9e7fe88f7b64f8636cb464ee3.tar.gz
ENH: Implement methods for uint-alignment
Implements IsAligned, IsUintAligned, npy_uint_alignment
Diffstat (limited to 'numpy/core/src/common')
-rw-r--r--numpy/core/src/common/array_assign.c17
-rw-r--r--numpy/core/src/common/array_assign.h14
2 files changed, 31 insertions, 0 deletions
diff --git a/numpy/core/src/common/array_assign.c b/numpy/core/src/common/array_assign.c
index e4cb651d6..ac3fdbef7 100644
--- a/numpy/core/src/common/array_assign.c
+++ b/numpy/core/src/common/array_assign.c
@@ -130,6 +130,23 @@ raw_array_is_aligned(int ndim, npy_intp *shape,
}
}
+NPY_NO_EXPORT int
+IsAligned(PyArrayObject *ap)
+{
+ return raw_array_is_aligned(PyArray_NDIM(ap), PyArray_DIMS(ap),
+ PyArray_DATA(ap), PyArray_STRIDES(ap),
+ PyArray_DESCR(ap)->alignment);
+}
+
+NPY_NO_EXPORT int
+IsUintAligned(PyArrayObject *ap)
+{
+ return raw_array_is_aligned(PyArray_NDIM(ap), PyArray_DIMS(ap),
+ PyArray_DATA(ap), PyArray_STRIDES(ap),
+ npy_uint_alignment(PyArray_DESCR(ap)->elsize));
+}
+
+
/* Returns 1 if the arrays have overlapping data, 0 otherwise */
NPY_NO_EXPORT int
diff --git a/numpy/core/src/common/array_assign.h b/numpy/core/src/common/array_assign.h
index fdc36d3a2..07438c5e8 100644
--- a/numpy/core/src/common/array_assign.h
+++ b/numpy/core/src/common/array_assign.h
@@ -94,6 +94,20 @@ NPY_NO_EXPORT int
raw_array_is_aligned(int ndim, npy_intp *shape,
char *data, npy_intp *strides, int alignment);
+/*
+ * Checks if an array is aligned to its "true alignment"
+ * given by dtype->alignment.
+ */
+NPY_NO_EXPORT int
+IsAligned(PyArrayObject *ap);
+
+/*
+ * Checks if an array is aligned to its "uint alignment"
+ * given by npy_uint_alignment(dtype->elsize).
+ */
+NPY_NO_EXPORT int
+IsUintAligned(PyArrayObject *ap);
+
/* Returns 1 if the arrays have overlapping data, 0 otherwise */
NPY_NO_EXPORT int
arrays_overlap(PyArrayObject *arr1, PyArrayObject *arr2);