[pypy-commit] pypy numpy-singledim: implement numpy.array.__repr__ with test.
Timo Paulssen
noreply at buildbot.pypy.org
Thu Jul 14 03:25:41 CEST 2011
Author: Timo Paulssen <timonator at perpetuum-immobile.de>
Branch: numpy-singledim
Changeset: r45575:05c6eea4919f
Date: 2011-07-13 23:17 +0200
http://bitbucket.org/pypy/pypy/changeset/05c6eea4919f/
Log: implement numpy.array.__repr__ with test.
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
@@ -269,6 +269,12 @@
def descr_mean(self, space):
return space.wrap(space.float_w(self.descr_sum(space))/self.find_size())
+ def descr_repr(self, space):
+ concrete = self.get_concrete()
+ return space.wrap("array([" +
+ " ".join([str(concrete.getitem(index)) for index in range(concrete.find_size())]) +
+ "])")
+
def convert_to_array (space, w_obj):
if isinstance(w_obj, BaseArray):
return w_obj
@@ -540,6 +546,7 @@
__rdiv__ = interp2app(BaseArray.descr_rdiv),
__rpow__ = interp2app(BaseArray.descr_rpow),
__rmod__ = interp2app(BaseArray.descr_rmod),
+ __repr__ = interp2app(BaseArray.descr_repr),
mean = interp2app(BaseArray.descr_mean),
sum = interp2app(BaseArray.descr_sum),
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
@@ -43,6 +43,11 @@
a = array(range(5))
assert a[3] == 3
+ def test_repr(self):
+ from numpy import array
+ a = array(range(5))
+ assert repr(a) == "array([0.0 1.0 2.0 3.0 4.0])"
+
def test_getitem(self):
from numpy import array
a = array(range(5))
More information about the pypy-commit
mailing list