From 32b32c2ac6b25f6ca867d72f23f2bb5b66d1cbee Mon Sep 17 00:00:00 2001 From: Mark Wiebe Date: Tue, 23 Aug 2011 17:40:43 -0700 Subject: BUG: umath: Make the ufunc follow the actual priority for __r__ Previously it returned not implemented just based on the existence of the array priority, it didn't actually check the priority value. --- numpy/core/src/umath/ufunc_object.c | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'numpy/core') 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__ 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__ 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) { -- cgit v1.2.1