From aa7a04741146c44ab1735782a89a60b038028bf2 Mon Sep 17 00:00:00 2001 From: Frederic Date: Fri, 10 May 2013 16:58:55 -0400 Subject: Make comparison function (gt, ge, ...) respect __array_priority__. --- numpy/core/src/multiarray/arrayobject.c | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index ad196e010..1c8c4803f 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1266,6 +1266,50 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) PyObject *result = NULL; PyArray_Descr *dtype = NULL; + // If other is of different type and the type priority is higher + // use its comparison function. + if (Py_TYPE(other) != Py_TYPE(self)) { + double prior1, prior2; + prior2 = PyArray_GetPriority((PyObject *)other, 0.0); + prior1 = PyArray_GetPriority((PyObject *)self, 0.0); + if (prior2 > prior1) { + PyObject *attr; + char * str = NULL; + switch (cmp_op) { + case Py_LT: + str = "__gt__"; + break; + case Py_LE: + str = "__ge__"; + break; + case Py_EQ: + str = "__eq__"; + break; + case Py_NE: + str = "__ne__"; + break; + case Py_GT: + str = "__lt__"; + break; + case Py_GE: + str = "__le__"; + break; + } + + if (str != NULL) { + attr = PyObject_GetAttrString(other, str); + + if (attr != NULL && PyCallable_Check(attr)) { + PyObject * ret; + ret = PyObject_CallFunctionObjArgs(attr, (PyObject *)self, NULL); + Py_DECREF(attr); + return ret; + } + Py_XDECREF(attr); + } + } + } + switch (cmp_op) { case Py_LT: result = PyArray_GenericBinaryFunction(self, other, -- cgit v1.2.1 From 3a09d96c9e95f56c1ce31d328a93c9dc4e2bc909 Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 15 May 2013 11:59:34 -0400 Subject: Revert "Make comparison function (gt, ge, ...) respect __array_priority__." This reverts commit aa7a04741146c44ab1735782a89a60b038028bf2. --- numpy/core/src/multiarray/arrayobject.c | 44 --------------------------------- 1 file changed, 44 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 1c8c4803f..ad196e010 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1266,50 +1266,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) PyObject *result = NULL; PyArray_Descr *dtype = NULL; - // If other is of different type and the type priority is higher - // use its comparison function. - if (Py_TYPE(other) != Py_TYPE(self)) { - double prior1, prior2; - prior2 = PyArray_GetPriority((PyObject *)other, 0.0); - prior1 = PyArray_GetPriority((PyObject *)self, 0.0); - if (prior2 > prior1) { - PyObject *attr; - char * str = NULL; - switch (cmp_op) { - case Py_LT: - str = "__gt__"; - break; - case Py_LE: - str = "__ge__"; - break; - case Py_EQ: - str = "__eq__"; - break; - case Py_NE: - str = "__ne__"; - break; - case Py_GT: - str = "__lt__"; - break; - case Py_GE: - str = "__le__"; - break; - } - - if (str != NULL) { - attr = PyObject_GetAttrString(other, str); - - if (attr != NULL && PyCallable_Check(attr)) { - PyObject * ret; - ret = PyObject_CallFunctionObjArgs(attr, (PyObject *)self, NULL); - Py_DECREF(attr); - return ret; - } - Py_XDECREF(attr); - } - } - } - switch (cmp_op) { case Py_LT: result = PyArray_GenericBinaryFunction(self, other, -- cgit v1.2.1 From 595022111ab025cc74a6238241097874a54f1795 Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 15 May 2013 12:59:14 -0400 Subject: Commit from @seberg to make comparison use respect __array_priority__ --- numpy/core/src/multiarray/arrayobject.c | 4 ++-- numpy/core/src/umath/ufunc_object.c | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index ad196e010..a380a4806 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1298,7 +1298,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) } result = PyArray_GenericBinaryFunction(self, - (PyObject *)array_other, + (PyObject *)other, n_ops.equal); if ((result == Py_NotImplemented) && (PyArray_TYPE(self) == NPY_VOID)) { @@ -1354,7 +1354,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return Py_NotImplemented; } - result = PyArray_GenericBinaryFunction(self, (PyObject *)array_other, + result = PyArray_GenericBinaryFunction(self, (PyObject *)other, n_ops.not_equal); if ((result == Py_NotImplemented) && (PyArray_TYPE(self) == NPY_VOID)) { diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index 7cdcf304e..c9cc18aff 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -492,6 +492,13 @@ _has_reflected_op(PyObject *op, char *name) _GETATTR_(bitwise_and, rand); _GETATTR_(bitwise_xor, rxor); _GETATTR_(bitwise_or, ror); + /* Comparisons */ + _GETATTR_(equal, eq); + _GETATTR_(not_equal, ne); + _GETATTR_(greater, lt); + _GETATTR_(less, gt); + _GETATTR_(greater_equal, le); + _GETATTR_(less_equal, ge); return 0; } -- cgit v1.2.1 From 1d3fa042225ac18f505bd2e37b47b3ed0af3a67a Mon Sep 17 00:00:00 2001 From: Frederic Date: Wed, 15 May 2013 13:00:04 -0400 Subject: Add test for the array_priority for comparison function. --- numpy/core/tests/test_multiarray.py | 146 ++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index e3520f123..7ca4ab5cf 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2934,6 +2934,152 @@ class TestMapIter(TestCase): assert_equal(b, [ 100.1, 51., 6., 3., 4., 5. ]) +class PriorityNdarray(): + __array_priority__ = 1000 + + def __init__(self, array): + self.array = array + + def __lt__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array < array) + + def __gt__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array > array) + + def __le__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array <= array) + + def __ge__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array >= array) + + def __eq__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array == array) + + def __ne__(self, array): + if isinstance(array, PriorityNdarray): + array = array.array + return PriorityNdarray(self.array != array) + + +class TestArrayPriority(TestCase): + def test_lt(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l < r + res2 = l < rp + res3 = lp < r + res4 = lp < rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + + def test_gt(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l > r + res2 = l > rp + res3 = lp > r + res4 = lp > rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + + def test_le(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l <= r + res2 = l <= rp + res3 = lp <= r + res4 = lp <= rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + + def test_ge(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l >= r + res2 = l >= rp + res3 = lp >= r + res4 = lp >= rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + + def test_eq(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l == r + res2 = l == rp + res3 = lp == r + res4 = lp == rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + + def test_ne(self): + l = np.asarray([0., -1., 1.], dtype=dtype) + r = np.asarray([0., 1., -1.], dtype=dtype) + lp = PriorityNdarray(l) + rp = PriorityNdarray(r) + res1 = l != r + res2 = l != rp + res3 = lp != r + res4 = lp != rp + + assert np.allclose(res1, res2.array) + assert np.allclose(res1, res3.array) + assert np.allclose(res1, res4.array) + assert isinstance(res1, np.ndarray) + assert isinstance(res2, PriorityNdarray) + assert isinstance(res3, PriorityNdarray) + assert isinstance(res4, PriorityNdarray) + if __name__ == "__main__": run_module_suite() -- cgit v1.2.1 From 90ea64b027a4868c47f169b4dd88c239e720bc25 Mon Sep 17 00:00:00 2001 From: Frederic Date: Thu, 16 May 2013 14:49:43 -0400 Subject: reorder code to remove not needed computation in some cases. --- numpy/core/src/multiarray/arrayobject.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index a380a4806..60ea87954 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1280,6 +1280,16 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) Py_INCREF(Py_False); return Py_False; } + result = PyArray_GenericBinaryFunction(self, + (PyObject *)other, + n_ops.equal); + if (result && result != Py_NotImplemented) + break; + + // I have been told that the rest of this case is probably an + // hack to support a few cases of structured arrays since + // ufuncs cannot handle general structured arrays. + /* Make sure 'other' is an array */ if (PyArray_TYPE(self) == NPY_OBJECT) { dtype = PyArray_DTYPE(self); @@ -1297,9 +1307,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return Py_NotImplemented; } - result = PyArray_GenericBinaryFunction(self, - (PyObject *)other, - n_ops.equal); if ((result == Py_NotImplemented) && (PyArray_TYPE(self) == NPY_VOID)) { int _res; @@ -1337,6 +1344,15 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) Py_INCREF(Py_True); return Py_True; } + result = PyArray_GenericBinaryFunction(self, (PyObject *)other, + n_ops.not_equal); + if (result && result != Py_NotImplemented) + break; + + // I have been told that the rest of this case is probably an + // hack to support a few cases of structured arrays since + // ufuncs cannot handle general structured arrays. + /* Make sure 'other' is an array */ if (PyArray_TYPE(self) == NPY_OBJECT) { dtype = PyArray_DTYPE(self); @@ -1354,8 +1370,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return Py_NotImplemented; } - result = PyArray_GenericBinaryFunction(self, (PyObject *)other, - n_ops.not_equal); if ((result == Py_NotImplemented) && (PyArray_TYPE(self) == NPY_VOID)) { int _res; -- cgit v1.2.1 From fa3919ca825d15ef98cc0afdfecb1ced1c74c3af Mon Sep 17 00:00:00 2001 From: Frederic Date: Thu, 16 May 2013 15:52:54 -0400 Subject: fix comment style. --- numpy/core/src/multiarray/arrayobject.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 60ea87954..9c08b3c15 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1286,9 +1286,11 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) if (result && result != Py_NotImplemented) break; - // I have been told that the rest of this case is probably an - // hack to support a few cases of structured arrays since - // ufuncs cannot handle general structured arrays. + /* + * I have been told that the rest of this case is probably an + * hack to support a few cases of structured arrays since + * ufuncs cannot handle general structured arrays. + */ /* Make sure 'other' is an array */ if (PyArray_TYPE(self) == NPY_OBJECT) { @@ -1349,9 +1351,11 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) if (result && result != Py_NotImplemented) break; - // I have been told that the rest of this case is probably an - // hack to support a few cases of structured arrays since - // ufuncs cannot handle general structured arrays. + /* + * I have been told that the rest of this case is probably an + * hack to support a few cases of structured arrays since + * ufuncs cannot handle general structured arrays. + */ /* Make sure 'other' is an array */ if (PyArray_TYPE(self) == NPY_OBJECT) { -- cgit v1.2.1 From 61977a3a65d61af8ccdef5986c7751c5073c344b Mon Sep 17 00:00:00 2001 From: Frederic Date: Thu, 16 May 2013 16:38:52 -0400 Subject: remove comparison not needed as this is check above and we break in that case. --- numpy/core/src/multiarray/arrayobject.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 9c08b3c15..2a2d0e54f 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1309,8 +1309,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return Py_NotImplemented; } - if ((result == Py_NotImplemented) && - (PyArray_TYPE(self) == NPY_VOID)) { + if (PyArray_TYPE(self) == NPY_VOID) { int _res; _res = PyObject_RichCompareBool @@ -1374,8 +1373,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return Py_NotImplemented; } - if ((result == Py_NotImplemented) && - (PyArray_TYPE(self) == NPY_VOID)) { + if (PyArray_TYPE(self) == NPY_VOID) { int _res; _res = PyObject_RichCompareBool( -- cgit v1.2.1 From 1c0a8fbc804594d7db0a452d9dfb491b06250105 Mon Sep 17 00:00:00 2001 From: Frederic Date: Thu, 16 May 2013 16:51:12 -0400 Subject: Move computation inside an if to speed it up. --- numpy/core/src/multiarray/arrayobject.c | 71 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 2a2d0e54f..f6dd58905 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1292,24 +1292,25 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) * ufuncs cannot handle general structured arrays. */ - /* Make sure 'other' is an array */ - if (PyArray_TYPE(self) == NPY_OBJECT) { - dtype = PyArray_DTYPE(self); - Py_INCREF(dtype); - } - array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, - NULL); - /* - * If not successful, indicate that the items cannot be compared - * this way. - */ - if (array_other == NULL) { - PyErr_Clear(); - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - if (PyArray_TYPE(self) == NPY_VOID) { + /* Make sure 'other' is an array */ + if (PyArray_TYPE(self) == NPY_OBJECT) { + dtype = PyArray_DTYPE(self); + Py_INCREF(dtype); + } + + array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, + NULL); + /* + * If not successful, indicate that the items cannot be compared + * this way. + */ + if (array_other == NULL) { + PyErr_Clear(); + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + int _res; _res = PyObject_RichCompareBool @@ -1333,7 +1334,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) * two array objects can not be compared together; * indicate that */ - Py_DECREF(array_other); if (result == NULL) { PyErr_Clear(); Py_INCREF(Py_NotImplemented); @@ -1356,24 +1356,24 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) * ufuncs cannot handle general structured arrays. */ - /* Make sure 'other' is an array */ - if (PyArray_TYPE(self) == NPY_OBJECT) { - dtype = PyArray_DTYPE(self); - Py_INCREF(dtype); - } - array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, - NULL); - /* - * If not successful, indicate that the items cannot be compared - * this way. - */ - if (array_other == NULL) { - PyErr_Clear(); - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - if (PyArray_TYPE(self) == NPY_VOID) { + /* Make sure 'other' is an array */ + if (PyArray_TYPE(self) == NPY_OBJECT) { + dtype = PyArray_DTYPE(self); + Py_INCREF(dtype); + } + array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, + NULL); + /* + * If not successful, indicate that the items cannot be compared + * this way. + */ + if (array_other == NULL) { + PyErr_Clear(); + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + int _res; _res = PyObject_RichCompareBool( @@ -1393,7 +1393,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) return result; } - Py_DECREF(array_other); if (result == NULL) { PyErr_Clear(); Py_INCREF(Py_NotImplemented); -- cgit v1.2.1 From 1aca67fcc689b66737b39862e517e821be0c4767 Mon Sep 17 00:00:00 2001 From: Frederic Date: Fri, 17 May 2013 11:45:16 -0400 Subject: use assert function instead of python keyword --- numpy/core/tests/test_multiarray.py | 84 ++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 7ca4ab5cf..2f6716c23 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -2982,13 +2982,13 @@ class TestArrayPriority(TestCase): res3 = lp < r res4 = lp < rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) def test_gt(self): l = np.asarray([0., -1., 1.], dtype=dtype) @@ -3000,13 +3000,13 @@ class TestArrayPriority(TestCase): res3 = lp > r res4 = lp > rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) def test_le(self): l = np.asarray([0., -1., 1.], dtype=dtype) @@ -3018,13 +3018,13 @@ class TestArrayPriority(TestCase): res3 = lp <= r res4 = lp <= rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) def test_ge(self): l = np.asarray([0., -1., 1.], dtype=dtype) @@ -3036,13 +3036,13 @@ class TestArrayPriority(TestCase): res3 = lp >= r res4 = lp >= rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) def test_eq(self): l = np.asarray([0., -1., 1.], dtype=dtype) @@ -3054,13 +3054,13 @@ class TestArrayPriority(TestCase): res3 = lp == r res4 = lp == rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) def test_ne(self): l = np.asarray([0., -1., 1.], dtype=dtype) @@ -3072,13 +3072,13 @@ class TestArrayPriority(TestCase): res3 = lp != r res4 = lp != rp - assert np.allclose(res1, res2.array) - assert np.allclose(res1, res3.array) - assert np.allclose(res1, res4.array) - assert isinstance(res1, np.ndarray) - assert isinstance(res2, PriorityNdarray) - assert isinstance(res3, PriorityNdarray) - assert isinstance(res4, PriorityNdarray) + assert_array_equal(res1, res2.array) + assert_array_equal(res1, res3.array) + assert_array_equal(res1, res4.array) + assert_(isinstance(res1, np.ndarray)) + assert_(isinstance(res2, PriorityNdarray)) + assert_(isinstance(res3, PriorityNdarray)) + assert_(isinstance(res4, PriorityNdarray)) if __name__ == "__main__": -- cgit v1.2.1 From 87801b98ff8317c05197e945416982ef712ff3e5 Mon Sep 17 00:00:00 2001 From: Frederic Date: Fri, 17 May 2013 11:47:20 -0400 Subject: updated the comment. --- numpy/core/src/multiarray/arrayobject.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index f6dd58905..706cd4574 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1287,9 +1287,8 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) break; /* - * I have been told that the rest of this case is probably an - * hack to support a few cases of structured arrays since - * ufuncs cannot handle general structured arrays. + * The ufunc does not support void/structured types, so these + * need to be handled specifically. Only a few cases are supported. */ if (PyArray_TYPE(self) == NPY_VOID) { @@ -1351,9 +1350,8 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) break; /* - * I have been told that the rest of this case is probably an - * hack to support a few cases of structured arrays since - * ufuncs cannot handle general structured arrays. + * The ufunc does not support void/structured types, so these + * need to be handled specifically. Only a few cases are supported. */ if (PyArray_TYPE(self) == NPY_VOID) { -- cgit v1.2.1 From c098283224215d656ce259ab7b852a9bf27523e7 Mon Sep 17 00:00:00 2001 From: Frederic Date: Thu, 23 May 2013 11:45:40 -0400 Subject: code clean up. Remove code that was never executed. @seberg saw this. --- numpy/core/src/multiarray/arrayobject.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 706cd4574..dbbabbc99 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -1264,7 +1264,6 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) { PyArrayObject *array_other; PyObject *result = NULL; - PyArray_Descr *dtype = NULL; switch (cmp_op) { case Py_LT: @@ -1292,13 +1291,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) */ if (PyArray_TYPE(self) == NPY_VOID) { - /* Make sure 'other' is an array */ - if (PyArray_TYPE(self) == NPY_OBJECT) { - dtype = PyArray_DTYPE(self); - Py_INCREF(dtype); - } - - array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, + array_other = (PyArrayObject *)PyArray_FromAny(other, NULL, 0, 0, 0, NULL); /* * If not successful, indicate that the items cannot be compared @@ -1355,12 +1348,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) */ if (PyArray_TYPE(self) == NPY_VOID) { - /* Make sure 'other' is an array */ - if (PyArray_TYPE(self) == NPY_OBJECT) { - dtype = PyArray_DTYPE(self); - Py_INCREF(dtype); - } - array_other = (PyArrayObject *)PyArray_FromAny(other, dtype, 0, 0, 0, + array_other = (PyArrayObject *)PyArray_FromAny(other, NULL, 0, 0, 0, NULL); /* * If not successful, indicate that the items cannot be compared -- cgit v1.2.1