[pypy-commit] pypy default: Kill a bunch of duplicate code.
alex_gaynor
noreply at buildbot.pypy.org
Wed Jul 20 05:54:27 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r45757:fabe4fc0dc08
Date: 2011-07-19 20:54 -0700
http://bitbucket.org/pypy/pypy/changeset/fabe4fc0dc08/
Log: Kill a bunch of duplicate code.
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
@@ -240,6 +240,24 @@
else:
return self.descr_mul(space, w_other)
+ def _getnums(self, comma):
+ if self.find_size() > 1000:
+ nums = [
+ float2string(self.getitem(index))
+ for index in range(3)
+ ]
+ nums.append("..." + "," * comma)
+ nums.extend([
+ float2string(self.getitem(index))
+ for index in range(self.find_size() - 3, self.find_size())
+ ])
+ else:
+ nums = [
+ float2string(self.getitem(index))
+ for index in range(self.find_size())
+ ]
+ return nums
+
def get_concrete(self):
raise NotImplementedError
@@ -250,10 +268,14 @@
return self.get_concrete().descr_len(space)
def descr_repr(self, space):
- return self.get_concrete()._repr(space)
+ # Simple implementation so that we can see the array. Needs work.
+ concrete = self.get_concrete()
+ return space.wrap("array([" + ", ".join(concrete._getnums(False)) + "])")
def descr_str(self, space):
- return self.get_concrete()._str(space)
+ # Simple implementation so that we can see the array. Needs work.
+ concrete = self.get_concrete()
+ return space.wrap("[" + " ".join(concrete._getnums(True)) + "]")
def descr_getitem(self, space, w_idx):
# TODO: indexing by tuples
@@ -444,32 +466,6 @@
def calc_index(self, item):
return (self.start + item * self.step)
- def _getnums(self, comma):
- if self.find_size() > 1000:
- nums = [
- float2string(self.getitem(index))
- for index in range(3)
- ]
- nums.append("..." + "," * comma)
- nums.extend([
- float2string(self.getitem(index))
- for index in range(self.find_size() - 3, self.find_size())
- ])
- else:
- nums = [
- float2string(self.getitem(index))
- for index in range(self.find_size())
- ]
- return nums
-
- def _repr(self, space):
- # Simple implementation so that we can see the array. Needs work.
- return space.wrap("array([" + ", ".join(self._getnums(False)) + "])")
-
- def _str(self,space):
- # Simple implementation so that we can see the array. Needs work.
- return space.wrap("[" + " ".join(self._getnums(True)) + "]")
-
class SingleDimArray(BaseArray):
signature = Signature()
@@ -507,32 +503,6 @@
def getitem(self, item):
return self.storage[item]
- def _getnums(self, comma):
- if self.find_size() > 1000:
- nums = [
- float2string(self.getitem(index))
- for index in range(3)
- ]
- nums.append("..." + "," * comma)
- nums.extend([
- float2string(self.getitem(index))
- for index in range(self.find_size() - 3, self.find_size())
- ])
- else:
- nums = [
- float2string(self.getitem(index))
- for index in range(self.find_size())
- ]
- return nums
-
- def _repr(self, space):
- # Simple implementation so that we can see the array. Needs work.
- return space.wrap("array([" + ", ".join(self._getnums(False)) + "])")
-
- def _str(self,space):
- # Simple implementation so that we can see the array. Needs work.
- return space.wrap("[" + " ".join(self._getnums(True)) + "]")
-
@unwrap_spec(item=int, value=float)
def descr_setitem(self, space, item, value):
item = self.getindex(space, item)
More information about the pypy-commit
mailing list