[pypy-commit] pypy default: support item() on 1-d 1-elem arrays. I could not care less about the performance of this
fijal
noreply at buildbot.pypy.org
Sun Jun 3 16:11:21 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r55286:244ef5a881e9
Date: 2012-06-03 16:10 +0200
http://bitbucket.org/pypy/pypy/changeset/244ef5a881e9/
Log: support item() on 1-d 1-elem arrays. I could not care less about the
performance of this
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -692,9 +692,14 @@
def descr_item(self, space, w_arg=None):
if space.is_w(w_arg, space.w_None):
- if not isinstance(self, Scalar):
- raise OperationError(space.w_ValueError, space.wrap("index out of bounds"))
- return self.value.item(space)
+ if isinstance(self, Scalar):
+ return self.value.item(space)
+ if support.product(self.shape) == 1:
+ return self.descr_getitem(space,
+ space.newtuple([space.wrap(0) for i
+ in range(len(self.shape))]))
+ raise OperationError(space.w_ValueError,
+ space.wrap("index out of bounds"))
if space.isinstance_w(w_arg, space.w_int):
if isinstance(self, Scalar):
raise OperationError(space.w_ValueError, space.wrap("index out of bounds"))
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -1999,6 +1999,7 @@
assert a[::2].item(1) == 3
assert (a + a).item(1) == 4
raises(ValueError, "array(5).item(1)")
+ assert array([1]).item() == 1
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
More information about the pypy-commit
mailing list