Skip to content

Ticket #1756 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Mar 5, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions numpy/core/src/multiarray/dtype_transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,37 @@ _strided_to_strided_zero_pad_copy(char *dst, npy_intp dst_stride,
}
}

/*
* Does a strided to strided zero-padded copy for the case where
* dst_itemsize < src_itemsize
*/
static void
_strided_to_strided_truncate_copy(char *dst, npy_intp dst_stride,
char *src, npy_intp src_stride,
npy_intp N, npy_intp src_itemsize,
void *data)
{
_strided_zero_pad_data *d = (_strided_zero_pad_data *)data;
npy_intp dst_itemsize = d->dst_itemsize;

while (N > 0) {
memcpy(dst, src, dst_itemsize);
src += src_stride;
dst += dst_stride;
--N;
}
}

NPY_NO_EXPORT int
PyArray_GetStridedZeroPadCopyFn(int aligned,
npy_intp src_stride, npy_intp dst_stride,
npy_intp src_itemsize, npy_intp dst_itemsize,
PyArray_StridedTransferFn **out_stransfer,
void **out_transferdata)
{
if (src_itemsize >= dst_itemsize) {
/* If the sizes are different, the alignment flag isn't trustworthy */
if (src_itemsize != dst_itemsize) {
aligned = 0;
}
if (src_itemsize == dst_itemsize) {
*out_stransfer = PyArray_GetStridedCopyFn(aligned, src_stride,
dst_stride, dst_itemsize);
dst_stride, src_itemsize);
*out_transferdata = NULL;
return (*out_stransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
}
Expand All @@ -213,7 +230,13 @@ PyArray_GetStridedZeroPadCopyFn(int aligned,
d->freefunc = &PyArray_free;
d->copyfunc = &_strided_zero_pad_data_copy;

*out_stransfer = &_strided_to_strided_zero_pad_copy;
if (src_itemsize < dst_itemsize) {
*out_stransfer = &_strided_to_strided_zero_pad_copy;
}
else {
*out_stransfer = &_strided_to_strided_truncate_copy;
}

*out_transferdata = d;
return NPY_SUCCEED;
}
Expand Down
42 changes: 7 additions & 35 deletions numpy/core/src/multiarray/lowlevel_strided_loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -301,34 +301,6 @@ _swap_pair_strided_to_strided(char *dst, npy_intp dst_stride,
}
}

static void
_strided_to_contig(char *dst, npy_intp dst_stride,
char *src, npy_intp src_stride,
npy_intp N, npy_intp NPY_UNUSED(src_itemsize),
void *NPY_UNUSED(data))
{
while (N > 0) {
memcpy(dst, src, dst_stride);
dst += dst_stride;
src += src_stride;
--N;
}
}

static void
_contig_to_strided(char *dst, npy_intp dst_stride,
char *src, npy_intp NPY_UNUSED(src_stride),
npy_intp N, npy_intp src_itemsize,
void *NPY_UNUSED(data))
{
while (N > 0) {
memcpy(dst, src, src_itemsize);
dst += dst_stride;
src += src_itemsize;
--N;
}
}

static void
_contig_to_contig(char *dst, npy_intp NPY_UNUSED(dst_stride),
char *src, npy_intp NPY_UNUSED(src_stride),
Expand Down Expand Up @@ -381,7 +353,7 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
}
}

return &_strided_to_contig;
return &_strided_to_strided;
}
/* general dst */
else {
Expand All @@ -408,7 +380,7 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
/**end repeat**/
}

return &_contig_to_strided;
return &_strided_to_strided;
}
else {
switch (itemsize) {
Expand Down Expand Up @@ -445,7 +417,7 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
}
}

return &_strided_to_contig;
return &_strided_to_strided;
}
/* general dst */
else {
Expand All @@ -462,7 +434,7 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
/**end repeat**/
}

return &_contig_to_strided;
return &_strided_to_strided;
}
/* general src */
else {
Expand Down Expand Up @@ -578,7 +550,7 @@ NPY_NO_EXPORT PyArray_StridedTransferFn *
/**end repeat1**/
}

return &_contig_to_strided;
return &_strided_to_strided;
}
else {
switch (itemsize) {
Expand Down Expand Up @@ -626,7 +598,7 @@ NPY_NO_EXPORT PyArray_StridedTransferFn *
}
}

return &_strided_to_contig;
return &_strided_to_strided;
}
/* general dst */
else {
Expand All @@ -643,7 +615,7 @@ NPY_NO_EXPORT PyArray_StridedTransferFn *
/**end repeat1**/
}

return &_contig_to_strided;
return &_strided_to_strided;
}
/* general src */
else {
Expand Down