Commits

Maciej Fijalkowski committed 244ef5a

support item() on 1-d 1-elem arrays. I could not care less about the performance of this

Comments (0)

Files changed (2)

pypy/module/micronumpy/interp_numarray.py

 
     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"))

pypy/module/micronumpy/test/test_numarray.py

         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):