summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/ctors.c8
-rw-r--r--numpy/core/src/umath/ufunc_object.c14
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.c2
3 files changed, 15 insertions, 9 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 872f4e284..49a4723ed 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1798,6 +1798,14 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)
oldtype = PyArray_DESCR(arr);
if (newtype == NULL) {
+ /*
+ * Check if object is of array dimension zero with Null newtype.
+ * If so return it directly instead of calling PyArray_FromAny.
+ */
+ if (PyArray_NDIM(arr) == 0 && flags == 0) {
+ Py_INCREF(arr);
+ return (PyObject *)arr;
+ }
newtype = oldtype;
Py_INCREF(oldtype);
}
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 1d003842c..2b5f38d25 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -754,15 +754,11 @@ static int get_ufunc_arguments(PyUFuncObject *ufunc,
for (i = 0; i < nin; ++i) {
obj = PyTuple_GET_ITEM(args, i);
- /*
- * If obj is array of dimension zero. PyArray_FromAny(obj,NULL,0,0,0,NULL) calls
- * PyArray_FromArray(obj,NULL,0) which return original obj
- */
- if(PyArray_IsZeroDim(obj) && PyArray_Check(obj)){
- Py_INCREF(obj);
- out_op[i] = (PyArrayObject *)obj;
- }else{
- if (!PyArray_Check(obj) && !PyArray_IsScalar(obj, Generic)) {
+ if (PyArray_Check(obj)) {
+ out_op[i] = (PyArrayObject *)PyArray_FromArray(obj,NULL,0);
+ }
+ else {
+ if (!PyArray_IsScalar(obj, Generic)) {
/*
* TODO: There should be a comment here explaining what
* context does.
diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c
index 6a16692b0..3a08f2d55 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.c
+++ b/numpy/core/src/umath/ufunc_type_resolution.c
@@ -422,6 +422,7 @@ PyUFunc_SimpleBinaryOperationTypeResolver(PyUFuncObject *ufunc,
*/
type_num1 = PyArray_DESCR(operands[0])->type_num;
type_num2 = PyArray_DESCR(operands[1])->type_num;
+
if (type_num1 >= NPY_NTYPES || type_num2 >= NPY_NTYPES ||
type_num1 == NPY_OBJECT || type_num2 == NPY_OBJECT) {
return PyUFunc_DefaultTypeResolver(ufunc, casting, operands,
@@ -431,6 +432,7 @@ PyUFunc_SimpleBinaryOperationTypeResolver(PyUFuncObject *ufunc,
if (type_tup == NULL) {
/* Input types are the result type */
out_dtypes[0] = PyArray_ResultType(2, operands, 0, NULL);
+
if (out_dtypes[0] == NULL) {
return -1;
}