[pypy-commit] pypy numpy-back-to-applevel: item, basic support

fijal noreply at buildbot.pypy.org
Thu Jan 26 20:55:24 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-back-to-applevel
Changeset: r51808:b1cb2bf3f898
Date: 2012-01-26 21:40 +0200
http://bitbucket.org/pypy/pypy/changeset/b1cb2bf3f898/

Log:	item, basic support

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
@@ -101,6 +101,9 @@
 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_ = ()
 
@@ -108,6 +111,9 @@
     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
 
@@ -150,6 +156,9 @@
 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")
 
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
@@ -5,7 +5,7 @@
 from pypy.module.micronumpy import interp_ufuncs, interp_dtype, signature
 from pypy.module.micronumpy.strides import calculate_slice_strides,\
      shape_agreement, find_shape_and_elems, get_shape_from_iterable,\
-     calc_new_strides
+     calc_new_strides, to_coords
 from pypy.rlib import jit
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.tool.sourcetools import func_with_new_name
@@ -650,6 +650,11 @@
             if not isinstance(self, Scalar):
                 raise OperationError(space.w_ValueError, space.wrap("index out of bounds"))
             return self.value.wrap(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]))
         xxx
 
 def convert_to_array(space, w_obj):
@@ -671,6 +676,7 @@
     Intermediate class representing a literal.
     """
     size = 1
+    order = 'C'
     _attrs_ = ["dtype", "value", "shape"]
 
     def __init__(self, dtype, value):
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
@@ -1481,7 +1481,6 @@
         assert type(array(3.5).item()) is float
         raises((ValueError, IndexError), "array(3).item(15)")
         raises(ValueError, "array([1, 2, 3]).item()")
-        xxx
 
 class AppTestSupport(BaseNumpyAppTest):
     def setup_class(cls):


More information about the pypy-commit mailing list