diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2011-08-23 17:40:43 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-08-27 07:27:00 -0600 |
commit | 32b32c2ac6b25f6ca867d72f23f2bb5b66d1cbee (patch) | |
tree | 681e74b3beea447e5e09de7d887623dda761c1e8 /numpy/core | |
parent | 4b157933641dc3b0241b9f1d68851a6661fa6604 (diff) | |
download | numpy-32b32c2ac6b25f6ca867d72f23f2bb5b66d1cbee.tar.gz |
BUG: umath: Make the ufunc follow the actual priority for __r<op>__
Previously it returned not implemented just based on the existence
of the array priority, it didn't actually check the priority value.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 46513cda1..ae82f6130 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -1941,19 +1941,21 @@ PyUFunc_GeneralizedFunction(PyUFuncObject *ufunc, /* * FAIL with NotImplemented if the other object has - * the __r<op>__ method and has __array_priority__ as - * an attribute (signalling it can handle ndarray's) - * and is not already an ndarray or a subtype of the same type. + * the __r<op>__ method and has a higher priority than + * the current op (signalling it can handle ndarray's). */ if (nin == 2 && nout == 1 && dtypes[1]->type_num == NPY_OBJECT) { PyObject *_obj = PyTuple_GET_ITEM(args, 1); - if (!PyArray_CheckExact(_obj) - /* If both are same subtype of object arrays, then proceed */ - && !(Py_TYPE(_obj) == Py_TYPE(PyTuple_GET_ITEM(args, 0))) - && PyObject_HasAttrString(_obj, "__array_priority__") - && _has_reflected_op(_obj, ufunc_name)) { - retval = -2; - goto fail; + if (!PyArray_CheckExact(_obj)) { + double self_prio, other_prio; + self_prio = PyArray_GetPriority(PyTuple_GET_ITEM(args, 0), + NPY_SCALAR_PRIORITY); + other_prio = PyArray_GetPriority(_obj, NPY_SCALAR_PRIORITY); + if (self_prio < other_prio && + _has_reflected_op(_obj, ufunc_name)) { + retval = -2; + goto fail; + } } } @@ -2305,17 +2307,19 @@ PyUFunc_GenericFunction(PyUFuncObject *ufunc, */ if (nin == 2 && nout == 1 && dtypes[1]->type_num == NPY_OBJECT) { PyObject *_obj = PyTuple_GET_ITEM(args, 1); - if (!PyArray_CheckExact(_obj) - /* If both are same subtype of object arrays, then proceed */ - && !(Py_TYPE(_obj) == Py_TYPE(PyTuple_GET_ITEM(args, 0))) - && PyObject_HasAttrString(_obj, "__array_priority__") - && _has_reflected_op(_obj, ufunc_name)) { - retval = -2; - goto fail; + if (!PyArray_CheckExact(_obj)) { + double self_prio, other_prio; + self_prio = PyArray_GetPriority(PyTuple_GET_ITEM(args, 0), + NPY_SCALAR_PRIORITY); + other_prio = PyArray_GetPriority(_obj, NPY_SCALAR_PRIORITY); + if (self_prio < other_prio && + _has_reflected_op(_obj, ufunc_name)) { + retval = -2; + goto fail; + } } } - #if NPY_UF_DBG_TRACING printf("input types:\n"); for (i = 0; i < nin; ++i) { |