[pypy-commit] pypy numpy-back-to-applevel: rename wrap to item and merge with tolist. Improve item() and test
fijal
noreply at buildbot.pypy.org
Thu Jan 26 21:09:34 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51812:c3680933a008
Date: 2012-01-26 22:09 +0200
http://bitbucket.org/pypy/pypy/changeset/c3680933a008/
Log: rename wrap to item and merge with tolist. Improve item() and test
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
@@ -94,16 +94,13 @@
descr_neg = _unaryop_impl("negative")
descr_abs = _unaryop_impl("absolute")
- def descr_tolist(self, space):
+ def item(self, space):
return self.get_dtype(space).itemtype.to_builtin_type(space, self)
class W_BoolBox(W_GenericBox, PrimitiveBox):
descr__new__, get_dtype = new_dtype_getter("bool")
- def wrap(self, space):
- return space.wrap(self.value)
-
class W_NumberBox(W_GenericBox):
_attrs_ = ()
@@ -111,9 +108,6 @@
def int_w(self, space):
return rffi.cast(lltype.Signed, self.value)
- def wrap(self, space):
- return space.wrap(rffi.cast(lltype.Signed, self.value))
-
class W_SignedIntegerBox(W_IntegerBox):
pass
@@ -156,9 +150,6 @@
class W_FloatingBox(W_InexactBox):
_attrs_ = ()
- def wrap(self, space):
- return space.wrap(rffi.cast(lltype.Float, self.value))
-
class W_Float32Box(W_FloatingBox, PrimitiveBox):
descr__new__, get_dtype = new_dtype_getter("float32")
@@ -198,7 +189,7 @@
__neg__ = interp2app(W_GenericBox.descr_neg),
__abs__ = interp2app(W_GenericBox.descr_abs),
- tolist = interp2app(W_GenericBox.descr_tolist),
+ tolist = interp2app(W_GenericBox.item),
)
W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef,
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
@@ -649,12 +649,12 @@
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.wrap(space)
+ return self.value.item(space)
if space.isinstance_w(w_arg, space.w_int):
i = to_coords(space, self.shape, self.size, self.order, w_arg)[0]
# XXX a bit around
- return self.descr_getitem(space.newtuple([space.wrap(x)
- for x in i]))
+ return self.descr_getitem(space, space.newtuple([space.wrap(x)
+ for x in i])).item(space)
raise OperationError(space.w_NotImplementedError, space.wrap(
"non-int arg not supported"))
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
@@ -1484,6 +1484,9 @@
assert type(array(3.5).item()) is float
raises((ValueError, IndexError), "array(3).item(15)")
raises(ValueError, "array([1, 2, 3]).item()")
+ assert array([3]).item(0) == 3
+ assert type(array([3]).item(0)) is int
+ assert array([1, 2, 3]).item(-1) == 3
class AppTestSupport(BaseNumpyAppTest):
def setup_class(cls):
More information about the pypy-commit
mailing list