summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/descriptor.c81
1 files changed, 25 insertions, 56 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 0ecac6720..215c8b0ab 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -3149,72 +3149,41 @@ arraydescr_str(PyArray_Descr *dtype)
static PyObject *
arraydescr_richcompare(PyArray_Descr *self, PyObject *other, int cmp_op)
{
- PyArray_Descr *new = NULL;
- PyObject *result = Py_NotImplemented;
- if (!PyArray_DescrCheck(other)) {
- new = _convert_from_any(other, 0);
- if (new == NULL) {
- return NULL;
- }
- }
- else {
- new = (PyArray_Descr *)other;
- Py_INCREF(new);
+ PyArray_Descr *new = _convert_from_any(other, 0);
+ if (new == NULL) {
+ return NULL;
}
+
+ npy_bool ret;
switch (cmp_op) {
case Py_LT:
- if (!PyArray_EquivTypes(self, new) && PyArray_CanCastTo(self, new)) {
- result = Py_True;
- }
- else {
- result = Py_False;
- }
- break;
+ ret = !PyArray_EquivTypes(self, new) && PyArray_CanCastTo(self, new);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
case Py_LE:
- if (PyArray_CanCastTo(self, new)) {
- result = Py_True;
- }
- else {
- result = Py_False;
- }
- break;
+ ret = PyArray_CanCastTo(self, new);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
case Py_EQ:
- if (PyArray_EquivTypes(self, new)) {
- result = Py_True;
- }
- else {
- result = Py_False;
- }
- break;
+ ret = PyArray_EquivTypes(self, new);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
case Py_NE:
- if (PyArray_EquivTypes(self, new))
- result = Py_False;
- else
- result = Py_True;
- break;
+ ret = !PyArray_EquivTypes(self, new);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
case Py_GT:
- if (!PyArray_EquivTypes(self, new) && PyArray_CanCastTo(new, self)) {
- result = Py_True;
- }
- else {
- result = Py_False;
- }
- break;
+ ret = !PyArray_EquivTypes(self, new) && PyArray_CanCastTo(new, self);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
case Py_GE:
- if (PyArray_CanCastTo(new, self)) {
- result = Py_True;
- }
- else {
- result = Py_False;
- }
- break;
+ ret = PyArray_CanCastTo(new, self);
+ Py_DECREF(new);
+ return PyBool_FromLong(ret);
default:
- result = Py_NotImplemented;
+ Py_DECREF(new);
+ Py_RETURN_NOTIMPLEMENTED;
}
-
- Py_XDECREF(new);
- Py_INCREF(result);
- return result;
}
static int