summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-02-06 10:58:28 +0200
committerGitHub <noreply@github.com>2020-02-06 10:58:28 +0200
commit55cce7d30aa5d86cc1d5aa62ea6dc89f808ab7b9 (patch)
treeeae8dea23f35432aabb84a37d714ab83a1bd887b /numpy
parente682fc21b20a58f5665a78fdd7d9785320a03ab7 (diff)
parent851692ced06c0073cded98ca52e56d4424b18975 (diff)
downloadnumpy-55cce7d30aa5d86cc1d5aa62ea6dc89f808ab7b9.tar.gz
Merge pull request #15521 from eric-wieser/tidy-descr-compare
MAINT: Simplify arraydescr_richcompare
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