summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/loops.c.src25
1 files changed, 18 insertions, 7 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index c3abd02f8..d0374fc0a 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -2562,22 +2562,28 @@ 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#
+ * #identity = NPY_TRUE, NPY_FALSE, -1*4#
*/
NPY_NO_EXPORT void
OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) {
BINARY_LOOP {
+ int ret;
+ PyObject *ret_obj;
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.
+ * Do not use RichCompareBool because it includes an identity check
+ * (for == and !=).
+ * This is wrong for elementwise behaviour, since it means
+ * that NaN can be equal to NaN and an array is equal to itself.
*/
- PyObject *ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@);
+ ret_obj = PyObject_RichCompare(in1, in2, Py_@OP@);
if (ret_obj == NULL) {
+#if @identity@ != -1
if (in1 == in2) {
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
@@ -2588,10 +2594,12 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
return;
}
- int ret = PyObject_IsTrue(ret_obj);
+ ret = PyObject_IsTrue(ret_obj);
if (ret == -1) {
+#if @identity@ != -1
if (in1 == in2) {
PyErr_Clear();
if (DEPRECATE("numpy @kind@ will not check object identity "
@@ -2603,19 +2611,22 @@ OBJECT_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUS
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
return;
}
+#if @identity@ != -1
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 "
+ "same result as suggested by the identity (`is`)) "
"and will change.") < 0) {
return;
}
*((npy_bool *)op1) = @identity@;
continue;
}
+#endif
*((npy_bool *)op1) = (npy_bool)ret;
}
}