Author: Antonio Cuni <[email protected]>
Branch:
Changeset: r62618:26d70090eda4
Date: 2013-03-21 22:52 +0100
http://bitbucket.org/pypy/pypy/changeset/26d70090eda4/
Log: implement .all() and .any() for numpy.bool_ objects
diff --git a/pypy/module/micronumpy/interp_boxes.py
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -175,6 +175,12 @@
class W_BoolBox(W_GenericBox, PrimitiveBox):
descr__new__, _get_dtype = new_dtype_getter("bool")
+ def descr_any(self, space):
+ return self
+
+ def descr_all(self, space):
+ return self
+
class W_NumberBox(W_GenericBox):
_attrs_ = ()
@@ -422,8 +428,9 @@
W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
__module__ = "numpypy",
__new__ = interp2app(W_BoolBox.descr__new__.im_func),
-
__index__ = interp2app(descr_index),
+ any = interp2app(W_BoolBox.descr_any),
+ all = interp2app(W_BoolBox.descr_all),
)
W_NumberBox.typedef = TypeDef("number", W_GenericBox.typedef,
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -335,6 +335,15 @@
assert X(True) is numpy.True_
assert numpy.bool_("False") is numpy.True_
+ def test_bool_any_all(self):
+ import numpypy as numpy
+ x = numpy.bool_(True)
+ assert x.any()
+ assert x.all()
+ x = numpy.bool_(False)
+ assert not x.any()
+ assert not x.all()
+
def test_int8(self):
import numpypy as numpy
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit