summaryrefslogtreecommitdiff
path: root/numpy/core/src/arrayobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r--numpy/core/src/arrayobject.c62
1 files changed, 44 insertions, 18 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index aef04b4c7..eaed75f14 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -6918,27 +6918,53 @@ _array_find_python_scalar_type(PyObject *op)
{
if (PyFloat_Check(op)) {
return PyArray_DescrFromType(PyArray_DOUBLE);
- } else if (PyComplex_Check(op)) {
- return PyArray_DescrFromType(PyArray_CDOUBLE);
- } else if (PyInt_Check(op)) {
- /* bools are a subclass of int */
- if (PyBool_Check(op)) {
- return PyArray_DescrFromType(PyArray_BOOL);
- } else {
- return PyArray_DescrFromType(PyArray_LONG);
- }
- } else if (PyLong_Check(op)) {
- /* if integer can fit into a longlong then return that
- */
- if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
- PyErr_Clear();
- return PyArray_DescrFromType(PyArray_OBJECT);
- }
- return PyArray_DescrFromType(PyArray_LONGLONG);
+ }
+ else if (PyComplex_Check(op)) {
+ return PyArray_DescrFromType(PyArray_CDOUBLE);
+ }
+ else if (PyInt_Check(op)) {
+ /* bools are a subclass of int */
+ if (PyBool_Check(op)) {
+ return PyArray_DescrFromType(PyArray_BOOL);
+ } else {
+ return PyArray_DescrFromType(PyArray_LONG);
+ }
+ }
+ else if (PyLong_Check(op)) {
+ /* if integer can fit into a longlong then return that
+ */
+ if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {
+ PyErr_Clear();
+ return PyArray_DescrFromType(PyArray_OBJECT);
+ }
+ return PyArray_DescrFromType(PyArray_LONGLONG);
}
return NULL;
}
+static PyArray_Descr *
+_use_default_type(PyObject *op)
+{
+ int typenum, l;
+ PyObject *type;
+
+ typenum = -1;
+ l = 0;
+ type = (PyObject *)op->ob_type;
+ while (l < PyArray_NUMUSERTYPES) {
+ if (type == (PyObject *)(userdescrs[l]->typeobj)) {
+ typenum = l + PyArray_USERDEF;
+ break;
+ }
+ l++;
+ }
+ if (typenum == -1) {
+ typenum = PyArray_OBJECT;
+ }
+ return PyArray_DescrFromType(typenum);
+}
+
+
/* op is an object to be converted to an ndarray.
minitype is the minimum type-descriptor needed.
@@ -7086,7 +7112,7 @@ _array_find_type(PyObject *op, PyArray_Descr *minitype, int max)
deflt:
- chktype = PyArray_DescrFromType(PyArray_OBJECT);
+ chktype = _use_default_type(op);
finish: