diff options
author | Eric Cousineau <eric.cousineau@tri.global> | 2018-05-18 10:27:29 -0400 |
---|---|---|
committer | Eric Cousineau <eric.cousineau@tri.global> | 2018-05-18 10:27:29 -0400 |
commit | 682403ef7e41f3ec171f10e4cbf317225312fd06 (patch) | |
tree | f67e12484ed665f9504fac166e3144977cb092be | |
parent | 290aa88e50e65c2dd5df4ddb062b895e9e7baae3 (diff) | |
download | numpy-682403ef7e41f3ec171f10e4cbf317225312fd06.tar.gz |
ENH: Have dtype transfer for equivalent user dtypes prefer user-defined `copyswapn`
-rw-r--r-- | doc/release/1.15.0-notes.rst | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/dtype_transfer.c | 9 |
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 d3f34d2bc..ad0844114 100644 --- a/doc/release/1.15.0-notes.rst +++ b/doc/release/1.15.0-notes.rst @@ -141,6 +141,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 |