Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68009:b9b04c08e3d3
Date: 2013-11-13 20:28 -0500
http://bitbucket.org/pypy/pypy/changeset/b9b04c08e3d3/
Log: support eq/ne for array.flags
diff --git a/pypy/module/micronumpy/interp_flagsobj.py
b/pypy/module/micronumpy/interp_flagsobj.py
--- a/pypy/module/micronumpy/interp_flagsobj.py
+++ b/pypy/module/micronumpy/interp_flagsobj.py
@@ -7,6 +7,7 @@
class W_FlagsObject(W_Root):
def __init__(self, arr):
self.arr = arr
+ self.flags = 0
def descr_get_contiguous(self, space):
return space.w_True
@@ -32,10 +33,23 @@
raise OperationError(space.w_KeyError, space.wrap(
"Unknown flag"))
+ def eq(self, space, w_other):
+ if not isinstance(w_other, W_FlagsObject):
+ return False
+ return self.flags == w_other.flags
+
+ def descr_eq(self, space, w_other):
+ return space.wrap(self.eq(space, w_other))
+
+ def descr_ne(self, space, w_other):
+ return space.wrap(not self.eq(space, w_other))
+
W_FlagsObject.typedef = TypeDef("flagsobj",
__module__ = "numpy",
__getitem__ = interp2app(W_FlagsObject.descr_getitem),
__setitem__ = interp2app(W_FlagsObject.descr_setitem),
+ __eq__ = interp2app(W_FlagsObject.descr_eq),
+ __ne__ = interp2app(W_FlagsObject.descr_ne),
contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous),
c_contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous),
diff --git a/pypy/module/micronumpy/test/test_flagsobj.py
b/pypy/module/micronumpy/test/test_flagsobj.py
--- a/pypy/module/micronumpy/test/test_flagsobj.py
+++ b/pypy/module/micronumpy/test/test_flagsobj.py
@@ -20,3 +20,10 @@
import numpy as np
a = np.int32(2)
assert a.flags.c_contiguous == True
+
+ def test_compare(self):
+ import numpy as np
+ a = np.array([1,2,3])
+ b = np.array([4,5,6,7])
+ assert a.flags == b.flags
+ assert not a.flags != b.flags
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit