summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-04-19 02:52:56 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-04-19 02:52:56 +0000
commit5964bd79342fee24cb8b70caa6005046a897c949 (patch)
tree7bd9d40cb7299ce148463ba5a1202bee77576782
parent959e147a8a41c37bc3b9d1f11d89449cb4cc9882 (diff)
downloadnumpy-5964bd79342fee24cb8b70caa6005046a897c949.tar.gz
Add special-purpose code for copying aligned data.
-rw-r--r--numpy/core/src/arrayobject.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 8a8c55837..4eaed6c70 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -621,7 +621,6 @@ PyArray_Size(PyObject *op)
}
}
-
static void
_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
intp N, int elsize)
@@ -629,13 +628,37 @@ _strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides,
intp i, j;
char *tout = dst;
char *tin = src;
- for (i=0; i<N; i++) {
- for (j=0; j<elsize; j++) {
- *tout++ = *tin++;
+ switch(elsize) {
+ case 8:
+ for (i=0; i<N; i++) {
+ ((Float64 *)tout)[0] = ((Float64 *)tin)[0];
+ tin = tin + instrides - elsize;
+ tout = tout + outstrides - elsize;
+ }
+ return;
+ case 4:
+ for (i=0; i<N; i++) {
+ ((Int32 *)tout)[0] = ((Int32 *)tin)[0];
+ tin = tin + instrides - elsize;
+ tout = tout + outstrides - elsize;
+ }
+ return;
+ case 2:
+ for (i=0; i<N; i++) {
+ ((Int16 *)tout)[0] = ((Int16 *)tin)[0];
+ tin = tin + instrides - elsize;
+ tout = tout + outstrides - elsize;
}
- tin = tin + instrides - elsize;
- tout = tout + outstrides - elsize;
- }
+ return;
+ default:
+ for (i=0; i<N; i++) {
+ for (j=0; j<elsize; j++) {
+ *tout++ = *tin++;
+ }
+ tin = tin + instrides - elsize;
+ tout = tout + outstrides - elsize;
+ }
+ }
}
/* If destination is not the right type, then src
@@ -708,7 +731,8 @@ PyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)
}
/* See if we can iterate over the largest dimension */
- if (!swap && (nd = dest->nd) == src->nd && (nd > 0) &&
+ if (!swap && PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src) &&
+ (nd = dest->nd) == src->nd && (nd > 0) &&
PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) {
int maxaxis=0, maxdim=dest->dimensions[0];
int i;