summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/src/multiarraymodule.c28
-rw-r--r--numpy/core/src/ufuncobject.c21
2 files changed, 36 insertions, 13 deletions
diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c
index 715d3ad76..c032c3a59 100644
--- a/numpy/core/src/multiarraymodule.c
+++ b/numpy/core/src/multiarraymodule.c
@@ -1926,7 +1926,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
PyObject *otmp;
PyArray_Descr *intype=NULL, *stype=NULL;
PyArray_Descr *newtype=NULL;
- NPY_SCALARKIND scalarkind;
+ NPY_SCALARKIND scalarkind, intypekind;
*retn = n = PySequence_Length(op);
if (PyErr_Occurred()) {*retn = 0; return NULL;}
@@ -1960,6 +1960,8 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
Py_XDECREF(intype);
intype = newtype;
mps[i] = NULL;
+ intypekind = PyArray_ScalarKind(intype->type_num,
+ NULL);
}
else {
newtype = PyArray_DescrFromObject(otmp, stype);
@@ -1967,13 +1969,6 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
stype = newtype;
scalarkind = PyArray_ScalarKind(newtype->type_num,
NULL);
- if (intype && \
- !PyArray_CanCoerceScalar(newtype->type_num,
- intype->type_num,
- scalarkind)) {
- Py_XDECREF(intype);
- intype = stype;
- }
mps[i] = (PyArrayObject *)Py_None;
Py_INCREF(Py_None);
}
@@ -1988,6 +1983,23 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
mps[i] = NULL;
}
}
+ else if (intypekind != scalarkind) { \
+ /* we need to upconvert to type that
+ handles both intype and stype
+ and don't forcecast the scalars.
+ */
+
+ if (!PyArray_CanCoerceScalar(stype->type_num,
+ intype->type_num,
+ scalarkind)) {
+ Py_XDECREF(intype);
+ intype = stype;
+ }
+ for (i=0; i<n; i++) {
+ Py_XDECREF(mps[i]);
+ mps[i] = NULL;
+ }
+ }
/* Make sure all arrays are actual array objects. */
for(i=0; i<n; i++) {
int flags = CARRAY;
diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c
index 51c2c3fbc..48a5f7aef 100644
--- a/numpy/core/src/ufuncobject.c
+++ b/numpy/core/src/ufuncobject.c
@@ -1118,8 +1118,10 @@ construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps,
int nargs, i;
int arg_types[NPY_MAXARGS];
PyArray_SCALARKIND scalars[NPY_MAXARGS];
+ PyArray_SCALARKIND kindof, new;
PyUFuncObject *self=loop->ufunc;
Bool allscalars=TRUE;
+ Bool samekind=TRUE;
PyTypeObject *subtype=&PyArray_Type;
PyObject *context=NULL;
PyObject *obj;
@@ -1160,11 +1162,18 @@ construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps,
at this point
*/
if (mps[i]->nd > 0) {
- scalars[i] = PyArray_NOSCALAR;
+ scalars[i] = PyArray_NOSCALAR;
allscalars=FALSE;
+ new = PyArray_ScalarKind(arg_types[i], NULL);
}
- else scalars[i] = PyArray_ScalarKind(arg_types[i], &(mps[i]));
-
+ else {
+ scalars[i] = PyArray_ScalarKind(arg_types[i], &(mps[i]));
+ new = scalars[i];
+ }
+ if (i==0) kindof=new;
+ else if (kindof != new) {
+ samekind=FALSE;
+ }
}
if (flexible && !object) {
@@ -1172,13 +1181,15 @@ construct_arrays(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps,
return nargs;
}
- /* If everything is a scalar, then use normal coercion rules */
- if (allscalars) {
+ /* If everything is a scalar, or scalars mixed with arrays of different kinds
+ then use normal coercion rules */
+ if (allscalars || !samekind) {
for (i=0; i<self->nin; i++) {
scalars[i] = PyArray_NOSCALAR;
}
}
+
/* Select an appropriate function for these argument types. */
if (select_types(loop->ufunc, arg_types, &(loop->function),
&(loop->funcdata), scalars, typetup) == -1)