diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2020-04-30 09:15:04 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 09:15:04 -0600 |
commit | 6586541a45a7c88ef6623696a1fd27a6041cbfc1 (patch) | |
tree | 29eb3d911f8a1fe8a5a894b63458c6be3b4e26ab | |
parent | 373fb29326da080214e6e20fb86a5013735d3ad1 (diff) | |
parent | f6cdbfa1fcd65d9a24fc802090181e6c1199a9fa (diff) | |
download | numpy-6586541a45a7c88ef6623696a1fd27a6041cbfc1.tar.gz |
Merge pull request #16109 from seberg/revert-accidental-bool-fix
REV: Reverts side-effect changes to casting
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index 598ee8537..6ec060db5 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -1527,8 +1527,16 @@ OBJECT_to_@TOTYPE@(void *input, void *output, npy_intp n, * #oskip = 1*18,(PyArray_DESCR(aop)->elsize)*3,1*2, * 1*18,(PyArray_DESCR(aop)->elsize)*3,1*2, * 1*18,(PyArray_DESCR(aop)->elsize)*3,1*2# + * #convert = 1*14, 0, 1*3, 0*3, 1*2, + * 1*14, 0, 1*3, 0*3, 1*2, + * 0*23# + * #convstr = (Int*9, Long*2, Float*4, Complex*3, Tuple*3, Long*2)*3# */ +#if @convert@ + +#define IS_@from@ + static void @from@_to_@to@(void *input, void *output, npy_intp n, void *vaip, void *aop) @@ -1542,10 +1550,41 @@ static void int oskip = @oskip@; for (i = 0; i < n; i++, ip+=skip, op+=oskip) { + PyObject *new; PyObject *temp = PyArray_Scalar(ip, PyArray_DESCR(aip), (PyObject *)aip); if (temp == NULL) { return; } + +#if defined(NPY_PY3K) && defined(IS_STRING) + /* Work around some Python 3K */ + new = PyUnicode_FromEncodedObject(temp, "ascii", "strict"); + Py_DECREF(temp); + temp = new; + if (temp == NULL) { + return; + } +#endif + /* convert from Python object to needed one */ + { + PyObject *args; + + /* call out to the Python builtin given by convstr */ + args = Py_BuildValue("(N)", temp); +#if defined(NPY_PY3K) +#define PyInt_Type PyLong_Type +#endif + new = Py@convstr@_Type.tp_new(&Py@convstr@_Type, args, NULL); +#if defined(NPY_PY3K) +#undef PyInt_Type +#endif + Py_DECREF(args); + temp = new; + if (temp == NULL) { + return; + } + } + if (@to@_setitem(temp, op, aop)) { Py_DECREF(temp); return; @@ -1554,6 +1593,36 @@ static void } } +#undef IS_@from@ + +#else + +static void +@from@_to_@to@(void *input, void *output, npy_intp n, + void *vaip, void *aop) +{ + @fromtyp@ *ip = input; + @totyp@ *op = output; + PyArrayObject *aip = vaip; + + npy_intp i; + int skip = PyArray_DESCR(aip)->elsize; + int oskip = @oskip@; + + for (i = 0; i < n; i++, ip+=skip, op+=oskip) { + PyObject *temp = PyArray_Scalar(ip, PyArray_DESCR(aip), (PyObject *)aip); + if (temp == NULL) { + return; + } + if (@to@_setitem(temp, op, aop)) { + Py_DECREF(temp); + return; + } + Py_DECREF(temp); + } +} + +#endif /**end repeat**/ |