summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2013-06-10 19:06:44 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2013-06-10 23:03:05 +0200
commitc9bf9b0b1c8a85391695d4ded39921e98c63257d (patch)
tree7ce5c0e3ff1d280d697d1eeb9c98d41ff5964597 /numpy
parent75cdf3d82e96e4fb605f3b0ea85961bbc24e70d8 (diff)
downloadnumpy-c9bf9b0b1c8a85391695d4ded39921e98c63257d.tar.gz
ENH: properly fix unaligned load of complex types
the workaround of setting the aligned to false unconditionally makes copying strided complex data extremely slow as it will always do unaligned elementwise memmoves. Instead set the alignment requirement for complex types correct in the dtype to begin with. Note that on 32 bit gcc complex double will still be aligned to 8 bytes unless compiled with -malign-double. It is possible this will introduce new segfaults on architectures without unaligned loads, but this now indicates a missing alignment check in the affected code as the array description is correct.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src7
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c14
2 files changed, 4 insertions, 17 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 217a5ddaa..52b787975 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -3817,9 +3817,9 @@ NPY_NO_EXPORT PyArray_Descr @from@_Descr = {
/* type_num */
NPY_@from@,
/* elsize */
- @num@*sizeof(@fromtype@),
+ @num@ * sizeof(@fromtype@),
/* alignment */
- _ALIGN(@fromtype@),
+ @num@ * _ALIGN(@fromtype@),
/* subarray */
NULL,
/* fields */
@@ -4150,6 +4150,7 @@ set_typeinfo(PyObject *dict)
* CFLOAT, CDOUBLE, CLONGDOUBLE#
* #Name = Half, Float, Double, LongDouble,
* CFloat, CDouble, CLongDouble#
+ * #num = 1, 1, 1, 1, 2, 2, 2#
*/
PyDict_SetItemString(infodict, "@name@",
@@ -4160,7 +4161,7 @@ set_typeinfo(PyObject *dict)
#endif
NPY_@name@,
NPY_BITSOF_@name@,
- _ALIGN(@type@),
+ @num@ * _ALIGN(@type@),
(PyObject *) &Py@Name@ArrType_Type));
Py_DECREF(s);
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index e964bc265..93fef8495 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -3574,13 +3574,6 @@ PyArray_GetDTypeTransferFunction(int aligned,
PyArray_ISNBO(dst_dtype->byteorder)) {
if (PyArray_EquivTypenums(src_type_num, dst_type_num)) {
- /*
- * For complex numbers, the alignment is smaller than the
- * type size, so we turn off the aligned flag then.
- */
- if (src_dtype->kind == 'c' || dst_dtype->kind == 'c') {
- aligned = 0;
- }
*out_stransfer = PyArray_GetStridedCopyFn(aligned,
src_stride, dst_stride,
src_itemsize);
@@ -3677,13 +3670,6 @@ PyArray_GetDTypeTransferFunction(int aligned,
/* This is a straight copy */
if (src_itemsize == 1 || PyArray_ISNBO(src_dtype->byteorder) ==
PyArray_ISNBO(dst_dtype->byteorder)) {
- /*
- * For complex numbers, the alignment is smaller than the
- * type size, so we turn off the aligned flag then.
- */
- if (src_dtype->kind == 'c' || dst_dtype->kind == 'c') {
- aligned = 0;
- }
*out_stransfer = PyArray_GetStridedCopyFn(aligned,
src_stride, dst_stride,
src_itemsize);