diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index c1e2dc1c5..c3abd02f8 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -2562,27 +2562,60 @@ NPY_NO_EXPORT void /**begin repeat * #kind = equal, not_equal, greater, greater_equal, less, less_equal# * #OP = EQ, NE, GT, GE, LT, LE# + * #identity = NPY_TRUE, NPY_FALSE, NPY_FALSE, NPY_TRUE, NPY_FALSE, NPY_TRUE# */ NPY_NO_EXPORT void OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { BINARY_LOOP { PyObject *in1 = *(PyObject **)ip1; PyObject *in2 = *(PyObject **)ip2; + in1 = in1 ? in1 : Py_None; + in2 = in2 ? in2 : Py_None; /* * Do not use RichCompareBool because it includes an identity check. * But this is wrong for elementwise behaviour, since i.e. it says * that NaN can be equal to NaN, and an array is equal to itself. */ - PyObject *ret_obj = PyObject_RichCompare( - in1 ? in1 : Py_None, - in2 ? in2 : Py_None, Py_@OP@); + PyObject *ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@); if (ret_obj == NULL) { + if (in1 == in2) { + PyErr_Clear(); + if (DEPRECATE("numpy @kind@ will not check object identity " + "in the future. The comparison error will " + "be raised.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } return; } int ret = PyObject_IsTrue(ret_obj); if (ret == -1) { + if (in1 == in2) { + PyErr_Clear(); + if (DEPRECATE("numpy @kind@ will not check object identity " + "in the future. The error trying to get the " + "boolean value of the comparison result will " + "be raised.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } return; } + if ((in1 == in2) && ((npy_bool)ret != @identity@)) { + if (DEPRECATE_FUTUREWARNING( + "numpy @kind@ will not check object identity " + "in the future. The comparison did not return the " + "same result as suggested by the identity " + "and will change.") < 0) { + return; + } + *((npy_bool *)op1) = @identity@; + continue; + } *((npy_bool *)op1) = (npy_bool)ret; } } |