summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-09-16 22:27:38 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-09-16 22:27:38 +0000
commitae85925a0099ff9e814be8cc32fcf96ad230d602 (patch)
treec0138bce372376c69a989668590121a44a467df5
parentcf56f9470be546d5b80bbad4495623b056df8e2f (diff)
downloadnumpy-ae85925a0099ff9e814be8cc32fcf96ad230d602.tar.gz
Fix type-coercion for void-type arrays.
-rw-r--r--numpy/core/src/arrayobject.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index 4cfb02a4a..fb2eb3a8e 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -6785,6 +6785,11 @@ _array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)
PyArray_Descr *outtype;
int outtype_num, save_num;
+ if (PyArray_EquivTypes(chktype, mintype)) {
+ Py_INCREF(mintype);
+ return mintype;
+ }
+
if (chktype->type_num > mintype->type_num)
outtype_num = chktype->type_num;
else
@@ -6872,23 +6877,33 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
PyArray_Descr *chktype=NULL;
PyArray_Descr *outtype;
- if (minitype == NULL)
- minitype = PyArray_DescrFromType(PyArray_BOOL);
- else Py_INCREF(minitype);
-
- if (max < 0) goto deflt;
+ /* These need to come first because if op already carries
+ a descr structure, then we want it to be the result if minitype
+ is NULL.
+ */
if (PyArray_Check(op)) {
chktype = PyArray_DESCR(op);
Py_INCREF(chktype);
+ if (minitype == NULL) return chktype;
+ Py_INCREF(minitype);
goto finish;
}
if (PyArray_IsScalar(op, Generic)) {
chktype = PyArray_DescrFromScalar(op);
+ if (minitype == NULL) return chktype;
+ Py_INCREF(minitype);
goto finish;
}
+ if (minitype == NULL) {
+ minitype = PyArray_DescrFromType(PyArray_BOOL);
+ }
+ else Py_INCREF(minitype);
+
+ if (max < 0) goto deflt;
+
chktype = _array_find_python_scalar_type(op);
if (chktype) {
goto finish;
@@ -6999,8 +7014,10 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
outtype = _array_small_type(chktype, minitype);
Py_DECREF(chktype);
Py_DECREF(minitype);
- /* VOID Arrays should not occur by "default" */
- if (outtype->type_num == PyArray_VOID) {
+ /* VOID Arrays should not occur by "default"
+ unless intput was already a VOID */
+ if (outtype->type_num == PyArray_VOID && \
+ minitype->type_num != PyArray_VOID) {
Py_DECREF(outtype);
return PyArray_DescrFromType(PyArray_OBJECT);
}