summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-05-28 10:38:46 -0700
committerGitHub <noreply@github.com>2018-05-28 10:38:46 -0700
commit515900db98c2f340acd929e8aecb4c584c6f2dd8 (patch)
tree3ebcb4b5dafd71a052f72a8a591035356f460f5f
parent69458b02956d39082014573eb0350ae3eb3436ee (diff)
parent682403ef7e41f3ec171f10e4cbf317225312fd06 (diff)
downloadnumpy-515900db98c2f340acd929e8aecb4c584c6f2dd8.tar.gz
Merge pull request #10898 from EricCousineau-TRI/prefer-user-copyswapn
ENH: Have dtype transfer for equivalent user dtypes prefer user-defined `copyswapn`
-rw-r--r--doc/release/1.15.0-notes.rst6
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c9
2 files changed, 12 insertions, 3 deletions
diff --git a/doc/release/1.15.0-notes.rst b/doc/release/1.15.0-notes.rst
index 23e0284c4..f8bb389aa 100644
--- a/doc/release/1.15.0-notes.rst
+++ b/doc/release/1.15.0-notes.rst
@@ -153,6 +153,12 @@ C API changes
checked before the operation whose status we wanted to check was run.
See `#10339 <https://github.com/numpy/numpy/issues/10370>`__.
+* ``PyArray_GetDTypeTransferFunction`` now defaults to using user-defined
+ ``copyswapn`` / ``copyswap`` for user-defined dtypes. If this causes a
+ significant performance hit, consider implementing ``copyswapn`` to reflect
+ the implementation of ``PyArray_GetStridedCopyFn``.
+ See `#10898 <https://github.com/numpy/numpy/pull/10898>`__.
+
New Features
============
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index 9c27255aa..9f9aa6757 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -3400,6 +3400,7 @@ PyArray_GetDTypeTransferFunction(int aligned,
{
npy_intp src_itemsize, dst_itemsize;
int src_type_num, dst_type_num;
+ int is_builtin;
#if NPY_DT_DBG_TRACING
printf("Calculating dtype transfer from ");
@@ -3439,6 +3440,7 @@ PyArray_GetDTypeTransferFunction(int aligned,
dst_itemsize = dst_dtype->elsize;
src_type_num = src_dtype->type_num;
dst_type_num = dst_dtype->type_num;
+ is_builtin = src_type_num < NPY_NTYPES && dst_type_num < NPY_NTYPES;
/* Common special case - number -> number NBO cast */
if (PyTypeNum_ISNUMBER(src_type_num) &&
@@ -3462,13 +3464,14 @@ PyArray_GetDTypeTransferFunction(int aligned,
}
/*
- * If there are no references and the data types are equivalent,
+ * If there are no references and the data types are equivalent and builtin,
* return a simple copy
*/
if (PyArray_EquivTypes(src_dtype, dst_dtype) &&
!PyDataType_REFCHK(src_dtype) && !PyDataType_REFCHK(dst_dtype) &&
( !PyDataType_HASFIELDS(dst_dtype) ||
- is_dtype_struct_simple_unaligned_layout(dst_dtype)) ) {
+ is_dtype_struct_simple_unaligned_layout(dst_dtype)) &&
+ is_builtin) {
/*
* We can't pass through the aligned flag because it's not
* appropriate. Consider a size-8 string, it will say it's
@@ -3494,7 +3497,7 @@ PyArray_GetDTypeTransferFunction(int aligned,
!PyDataType_HASSUBARRAY(dst_dtype) &&
src_type_num != NPY_DATETIME && src_type_num != NPY_TIMEDELTA) {
/* A custom data type requires that we use its copy/swap */
- if (src_type_num >= NPY_NTYPES || dst_type_num >= NPY_NTYPES) {
+ if (!is_builtin) {
/*
* If the sizes and kinds are identical, but they're different
* custom types, then get a cast function