diff options
author | Travis Oliphant <oliphant@enthought.com> | 2007-03-26 20:40:01 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2007-03-26 20:40:01 +0000 |
commit | 336d765e2cd78009505d67832de988e8078e02a6 (patch) | |
tree | 124203728d05561212773ca5e22b1ce2b99d7679 /numpy/core/src/ufuncobject.c | |
parent | 14a5747967255b2fef4cf89ded1b3271ca3710ec (diff) | |
download | numpy-336d765e2cd78009505d67832de988e8078e02a6.tar.gz |
Fix scalar coercion rules between different basic kinds.
Diffstat (limited to 'numpy/core/src/ufuncobject.c')
-rw-r--r-- | numpy/core/src/ufuncobject.c | 21 |
1 files changed, 16 insertions, 5 deletions
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) |