Commits

Maciej Fijalkowski committed 96b51ed

progress on take

Comments (0)

Files changed (4)

pypy/module/micronumpy/interp_boxes.py

 from pypy.objspace.std.inttype import int_typedef
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
-
+from pypy.rpython.lltypesystem import rffi, lltype
 
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
 
     _attrs_ = ()
 
 class W_IntegerBox(W_NumberBox):
-    pass
+    def int_w(self, space):
+        return rffi.cast(lltype.Signed, self.value)
 
 class W_SignedIntegerBox(W_IntegerBox):
     pass

pypy/module/micronumpy/interp_numarray.py

     def supports_fast_slicing(self):
         return False
 
+    def descr_take(self, space, w_obj):
+        index = convert_to_array(space, w_obj).get_concrete()
+        if len(self.shape) > 1:
+            xxx
+        index_i = index.create_iter()
+        res_shape = index.shape
+        size = 1
+        for elem in res_shape:
+            size *= elem
+        res = W_NDimArray(size, res_shape[:], self.dtype, self.order)
+        res_i = res.create_iter()
+        longdtype = interp_dtype.get_dtype_cache(space).w_longdtype
+        while not index_i.done():
+            w_item = index.getitem(index_i.offset).convert_to(longdtype)
+            import pdb
+            pdb.set_trace()
+            res.setitem(res_i.offset, self.descr_getitem(space, w_item))
+            index_i = index_i.next()
+            res_i = res_i.next()
+        return res
+
 def convert_to_array(space, w_obj):
     if isinstance(w_obj, BaseArray):
         return w_obj
     flatten = interp2app(BaseArray.descr_flatten),
     reshape = interp2app(BaseArray.descr_reshape),
     tolist = interp2app(BaseArray.descr_tolist),
+    take = interp2app(BaseArray.descr_take),
 )
 
 

pypy/module/micronumpy/test/test_dtypes.py

         b = X(10)
         assert type(b) is X
         assert b.m() == 12
+
+    def test_long_as_index(self):
+        from _numpypy import int_
+        assert (1, 2, 3)[int_(1)] == 2

pypy/module/micronumpy/test/test_numarray.py

         assert (arange(6).reshape(2, 3).ravel() == arange(6)).all()
         print arange(6).reshape(2, 3).T.ravel()
         assert (arange(6).reshape(2, 3).T.ravel() == [0, 3, 1, 4, 2, 5]).all()
-        
+
+    def test_take(self):
+        from _numpypy import arange
+        assert(arange(10).take([1, 2, 1, 1]) == [1, 2, 1, 1])
 
 class AppTestSupport(BaseNumpyAppTest):
     def setup_class(cls):