Author: Maciej Fijalkowski <[email protected]>
Branch: numpy-back-to-applevel
Changeset: r51754:96b51eda2096
Date: 2012-01-25 16:45 +0200
http://bitbucket.org/pypy/pypy/changeset/96b51eda2096/
Log: progress on take
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
@@ -6,7 +6,7 @@
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 ()
@@ -104,7 +104,8 @@
_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
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
@@ -613,6 +613,27 @@
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
@@ -1313,6 +1334,7 @@
flatten = interp2app(BaseArray.descr_flatten),
reshape = interp2app(BaseArray.descr_reshape),
tolist = interp2app(BaseArray.descr_tolist),
+ take = interp2app(BaseArray.descr_take),
)
diff --git a/pypy/module/micronumpy/test/test_dtypes.py
b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -376,3 +376,7 @@
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
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
@@ -1401,7 +1401,10 @@
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):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit