summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-08-06 09:08:10 -0700
committerCharles Harris <charlesr.harris@gmail.com>2011-08-27 07:26:52 -0600
commitb9a45089db195e9efd6724f3fb9ecf0f3d6f17a5 (patch)
tree742bbcb212cfbd306409ea9670a9cb3d065b9ca3 /numpy
parent1f91c531797fa9c105b5f5bccd65e461554d99a1 (diff)
downloadnumpy-b9a45089db195e9efd6724f3fb9ecf0f3d6f17a5.tar.gz
ENH: missingata: Move the alignment check out of the assignment functions
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/array_assign.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/numpy/core/src/multiarray/array_assign.c b/numpy/core/src/multiarray/array_assign.c
index 17ebbbe35..c5607916a 100644
--- a/numpy/core/src/multiarray/array_assign.c
+++ b/numpy/core/src/multiarray/array_assign.c
@@ -88,6 +88,28 @@ broadcast_error: {
}
/*
+ * Checks whether a data pointer + set of strides refers to a raw
+ * array which is fully aligned data.
+ */
+static int
+strides_are_aligned(int ndim, char *data, npy_intp *strides, int alignment)
+{
+ if (alignment > 1) {
+ npy_intp align_check = (npy_intp)data;
+ int idim;
+
+ for (idim = 0; idim < ndim; ++idim) {
+ align_check |= strides[idim];
+ }
+
+ return ((align_check & (alignment - 1)) == 0);
+ }
+ else {
+ return 1;
+ }
+}
+
+/*
* Assigns the scalar value to every element of the destination raw array.
*
* Returns 0 on success, -1 on failure.
@@ -104,19 +126,12 @@ raw_array_assign_scalar(int ndim, npy_intp *shape,
PyArray_StridedTransferFn *stransfer = NULL;
NpyAuxData *transferdata = NULL;
- int aligned = 1, needs_api = 0;
+ int aligned, needs_api = 0;
npy_intp src_itemsize = src_dtype->elsize;
/* Check alignment */
- if (dst_dtype->alignment > 1) {
- npy_intp align_check = (npy_intp)dst_data;
- for (idim = 0; idim < ndim; ++idim) {
- align_check |= dst_strides[idim];
- }
- if ((align_check & (dst_dtype->alignment - 1)) != 0) {
- aligned = 0;
- }
- }
+ aligned = strides_are_aligned(ndim, dst_data, dst_strides,
+ dst_dtype->alignment);
if (((npy_intp)src_data & (src_dtype->alignment - 1)) != 0) {
aligned = 0;
}
@@ -181,19 +196,12 @@ raw_array_wheremasked_assign_scalar(int ndim, npy_intp *shape,
PyArray_MaskedStridedTransferFn *stransfer = NULL;
NpyAuxData *transferdata = NULL;
- int aligned = 1, needs_api = 0;
+ int aligned, needs_api = 0;
npy_intp src_itemsize = src_dtype->elsize;
/* Check alignment */
- if (dst_dtype->alignment > 1) {
- npy_intp align_check = (npy_intp)dst_data;
- for (idim = 0; idim < ndim; ++idim) {
- align_check |= dst_strides[idim];
- }
- if ((align_check & (dst_dtype->alignment - 1)) != 0) {
- aligned = 0;
- }
- }
+ aligned = strides_are_aligned(ndim, dst_data, dst_strides,
+ dst_dtype->alignment);
if (((npy_intp)src_data & (src_dtype->alignment - 1)) != 0) {
aligned = 0;
}