diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-25 03:59:57 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-25 03:59:57 +0000 |
commit | b4e76e3499cb660e6d8e64688bab66c668d0d6c9 (patch) | |
tree | 61cd882103ebb736a57d750845d8d187e5461e16 | |
parent | 93d2d8f20cb9904f33384a0c26bc082b27ecd1eb (diff) | |
download | numpy-b4e76e3499cb660e6d8e64688bab66c668d0d6c9.tar.gz |
Fix coercion in multiarray to be like ufunc coercion.
-rw-r--r-- | numpy/core/src/arrayobject.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 42eada99d..13a5ef12f 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -6751,11 +6751,24 @@ static PyArray_Descr * _array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype) { PyArray_Descr *outtype; - - if (chktype->type_num > mintype->type_num) outtype = chktype; - else outtype = mintype; - - Py_INCREF(outtype); + int outtype_num, save_num; + + if (chktype->type_num > mintype->type_num) + outtype_num = chktype->type_num; + else + outtype_num = mintype->type_num; + + save_num = outtype_num; + while(outtype_num < PyArray_NTYPES && + !(PyArray_CanCastSafely(chktype->type_num, outtype_num) + && PyArray_CanCastSafely(mintype->type_num, outtype_num))) + outtype_num++; + if (outtype_num == PyArray_NTYPES) { + outtype = PyArray_DescrFromType(save_num); + } + else { + outtype = PyArray_DescrFromType(outtype_num); + } if (PyTypeNum_ISEXTENDED(outtype->type_num) && \ (PyTypeNum_ISEXTENDED(mintype->type_num) || \ mintype->type_num==0)) { |