summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c136
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.c.src6
-rw-r--r--numpy/core/src/private/lowlevel_strided_loops.h34
-rw-r--r--numpy/core/src/umath/umathmodule.c.src3
4 files changed, 107 insertions, 72 deletions
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index 9b1ba4aa7..e3431e450 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -1059,13 +1059,22 @@ get_nbo_datetime_to_string_transfer_function(int aligned,
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
printf("\n");
- printf("has conversion fraction %lld/%lld\n", num, denom);
#endif
return NPY_SUCCEED;
}
static int
+get_datetime_to_unicode_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+
+}
+
+static int
get_nbo_string_to_datetime_transfer_function(int aligned,
npy_intp src_stride, npy_intp dst_stride,
PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
@@ -1112,13 +1121,21 @@ get_nbo_string_to_datetime_transfer_function(int aligned,
printf(" to ");
PyObject_Print((PyObject *)dst_dtype, stdout, 0);
printf("\n");
- printf("has conversion fraction %lld/%lld\n", num, denom);
#endif
return NPY_SUCCEED;
}
static int
+get_unicode_to_datetime_transfer_function(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
+ PyArray_StridedTransferFn **out_stransfer,
+ void **out_transferdata)
+{
+}
+
+static int
get_nbo_cast_transfer_function(int aligned,
npy_intp src_stride, npy_intp dst_stride,
PyArray_Descr *src_dtype, PyArray_Descr *dst_dtype,
@@ -1179,7 +1196,11 @@ get_nbo_cast_transfer_function(int aligned,
case NPY_UNICODE:
*out_needs_api = 1;
- break;
+ return get_datetime_to_unicode_transfer_function(
+ aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ out_stransfer, out_transferdata);
}
}
else if (dst_dtype->type_num == NPY_DATETIME) {
@@ -1195,7 +1216,11 @@ get_nbo_cast_transfer_function(int aligned,
case NPY_UNICODE:
*out_needs_api = 1;
- break;
+ return get_unicode_to_datetime_transfer_function(
+ aligned,
+ src_stride, dst_stride,
+ src_dtype, dst_dtype,
+ out_stransfer, out_transferdata);
}
}
}
@@ -1366,69 +1391,17 @@ get_cast_transfer_function(int aligned,
PyArray_StridedTransferFn *tobuffer, *frombuffer;
/* Get the copy/swap operation from src */
-
- /* If it's a custom data type, wrap its copy swap function */
- if (src_dtype->type_num >= NPY_NTYPES) {
- tobuffer = NULL;
- wrap_copy_swap_function(aligned,
+ PyArray_GetDTypeCopySwapFn(aligned,
src_stride, src_itemsize,
src_dtype,
- !PyArray_ISNBO(src_dtype->byteorder),
&tobuffer, &todata);
- }
- /* A straight copy */
- else if (src_itemsize == 1 || PyArray_ISNBO(src_dtype->byteorder)) {
- tobuffer = PyArray_GetStridedCopyFn(aligned,
- src_stride, src_itemsize,
- src_itemsize);
- }
- /* If it's not complex, one swap */
- else if(src_dtype->kind != 'c') {
- tobuffer = PyArray_GetStridedCopySwapFn(aligned,
- src_stride, src_itemsize,
- src_itemsize);
- }
- /* If complex, a paired swap */
- else {
- tobuffer = PyArray_GetStridedCopySwapPairFn(aligned,
- src_stride, src_itemsize,
- src_itemsize);
- }
- /* Get the copy/swap operation to dst */
- /* If it's a custom data type, wrap its copy swap function */
- if (dst_dtype->type_num >= NPY_NTYPES) {
- frombuffer = NULL;
- wrap_copy_swap_function(aligned,
+ /* Get the copy/swap operation to dst */
+ PyArray_GetDTypeCopySwapFn(aligned,
dst_itemsize, dst_stride,
dst_dtype,
- !PyArray_ISNBO(dst_dtype->byteorder),
&frombuffer, &fromdata);
- }
- /* A straight copy */
- else if (dst_itemsize == 1 || PyArray_ISNBO(dst_dtype->byteorder)) {
- if (dst_dtype->type_num == NPY_OBJECT) {
- frombuffer = &_strided_to_strided_move_references;
- }
- else {
- frombuffer = PyArray_GetStridedCopyFn(aligned,
- dst_itemsize, dst_stride,
- dst_itemsize);
- }
- }
- /* If it's not complex, one swap */
- else if(dst_dtype->kind != 'c') {
- frombuffer = PyArray_GetStridedCopySwapFn(aligned,
- dst_itemsize, dst_stride,
- dst_itemsize);
- }
- /* If complex, a paired swap */
- else {
- frombuffer = PyArray_GetStridedCopySwapPairFn(aligned,
- dst_itemsize, dst_stride,
- dst_itemsize);
- }
if (frombuffer == NULL || tobuffer == NULL) {
PyArray_FreeStridedTransferData(castdata);
@@ -3252,6 +3225,51 @@ get_decsrcref_transfer_function(int aligned,
}
}
+/********************* DTYPE COPY SWAP FUNCTION ***********************/
+
+NPY_NO_EXPORT int
+PyArray_GetDTypeCopySwapFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *dtype,
+ PyArray_StridedTransferFn **outstransfer,
+ void **outtransferdata)
+{
+ npy_intp itemsize = dtype->elsize;
+
+ /* If it's a custom data type, wrap its copy swap function */
+ if (dtype->type_num >= NPY_NTYPES) {
+ *outstransfer = NULL;
+ wrap_copy_swap_function(aligned,
+ src_stride, dst_stride,
+ dtype,
+ !PyArray_ISNBO(dtype->byteorder),
+ outstransfer, outtransferdata);
+ }
+ /* A straight copy */
+ else if (itemsize == 1 || PyArray_ISNBO(dtype->byteorder)) {
+ *outstransfer = PyArray_GetStridedCopyFn(aligned,
+ src_stride, dst_stride,
+ itemsize);
+ *outtransferdata = NULL;
+ }
+ /* If it's not complex, one swap */
+ else if(dtype->kind != 'c') {
+ *outstransfer = PyArray_GetStridedCopySwapFn(aligned,
+ src_stride, dst_stride,
+ itemsize);
+ *outtransferdata = NULL;
+ }
+ /* If complex, a paired swap */
+ else {
+ *outstransfer = PyArray_GetStridedCopySwapPairFn(aligned,
+ src_stride, dst_stride,
+ itemsize);
+ *outtransferdata = NULL;
+ }
+
+ return (*outstransfer == NULL) ? NPY_FAIL : NPY_SUCCEED;
+}
+
/********************* MAIN DTYPE TRANSFER FUNCTION ***********************/
NPY_NO_EXPORT int
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
index 0a1786bc4..170a7167e 100644
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -311,7 +311,7 @@ _contig_to_contig(char *dst, npy_intp NPY_UNUSED(dst_stride),
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
+PyArray_GetStridedCopyFn(int aligned, npy_intp src_stride,
npy_intp dst_stride, npy_intp itemsize)
{
/*
@@ -466,7 +466,7 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
*/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-@function@(npy_intp aligned, npy_intp src_stride,
+@function@(int aligned, npy_intp src_stride,
npy_intp dst_stride, npy_intp itemsize)
{
/*
@@ -848,7 +848,7 @@ static void
/**end repeat**/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedNumericCastFn(npy_intp aligned, npy_intp src_stride,
+PyArray_GetStridedNumericCastFn(int aligned, npy_intp src_stride,
npy_intp dst_stride,
int src_type_num, int dst_type_num)
{
diff --git a/numpy/core/src/private/lowlevel_strided_loops.h b/numpy/core/src/private/lowlevel_strided_loops.h
index 79b8f6fd7..166ece29a 100644
--- a/numpy/core/src/private/lowlevel_strided_loops.h
+++ b/numpy/core/src/private/lowlevel_strided_loops.h
@@ -60,8 +60,9 @@ PyArray_CopyStridedTransferData(void *transferdata);
*
*/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
- npy_intp dst_stride, npy_intp itemsize);
+PyArray_GetStridedCopyFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp itemsize);
/*
* Gives back a function pointer to a specialized function for copying
@@ -74,8 +75,9 @@ PyArray_GetStridedCopyFn(npy_intp aligned, npy_intp src_stride,
* Parameters are as for PyArray_GetStridedCopyFn.
*/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedCopySwapFn(npy_intp aligned, npy_intp src_stride,
- npy_intp dst_stride, npy_intp itemsize);
+PyArray_GetStridedCopySwapFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp itemsize);
/*
* Gives back a function pointer to a specialized function for copying
@@ -88,8 +90,9 @@ PyArray_GetStridedCopySwapFn(npy_intp aligned, npy_intp src_stride,
* Parameters are as for PyArray_GetStridedCopyFn.
*/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedCopySwapPairFn(npy_intp aligned, npy_intp src_stride,
- npy_intp dst_stride, npy_intp itemsize);
+PyArray_GetStridedCopySwapPairFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ npy_intp itemsize);
/*
* Gives back a transfer function and transfer data pair which copies
@@ -115,9 +118,22 @@ PyArray_GetStridedZeroPadCopyFn(int aligned,
* without setting a Python exception.
*/
NPY_NO_EXPORT PyArray_StridedTransferFn *
-PyArray_GetStridedNumericCastFn(npy_intp aligned, npy_intp src_stride,
- npy_intp dst_stride,
- int src_type_num, int dst_type_num);
+PyArray_GetStridedNumericCastFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ int src_type_num, int dst_type_num);
+
+/*
+ * Gets an operation which copies elements of the given dtype,
+ * swapping if the dtype isn't in NBO.
+ *
+ * Returns NPY_SUCCEED or NPY_FAIL
+ */
+NPY_NO_EXPORT int
+PyArray_GetDTypeCopySwapFn(int aligned,
+ npy_intp src_stride, npy_intp dst_stride,
+ PyArray_Descr *dtype,
+ PyArray_StridedTransferFn **outstransfer,
+ void **outtransferdata);
/*
* If it's possible, gives back a transfer function which casts and/or
diff --git a/numpy/core/src/umath/umathmodule.c.src b/numpy/core/src/umath/umathmodule.c.src
index b4cece358..a6da7c2dd 100644
--- a/numpy/core/src/umath/umathmodule.c.src
+++ b/numpy/core/src/umath/umathmodule.c.src
@@ -43,7 +43,8 @@
static PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};
-static int object_ufunc_type_resolution(PyUFuncObject *ufunc,
+static int
+object_ufunc_type_resolution(PyUFuncObject *ufunc,
NPY_CASTING casting,
PyArrayObject **operands,
PyObject *type_tup,