[pypy-commit] pypy numpy-record-dtypes: make repr work

fijal noreply at buildbot.pypy.org
Fri Feb 17 15:17:41 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-record-dtypes
Changeset: r52586:087544142212
Date: 2012-02-17 16:17 +0200
http://bitbucket.org/pypy/pypy/changeset/087544142212/

Log:	make repr work

diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -88,6 +88,9 @@
     def box(self, value):
         return self.BoxType(rffi.cast(self.T, value))
 
+    def str_format(self, box):
+        return self._str_format(self.unbox(box))
+
     def unbox(self, box):
         assert isinstance(box, self.BoxType)
         return box.value
@@ -269,8 +272,7 @@
     def to_builtin_type(self, space, w_item):
         return space.wrap(self.unbox(w_item))
 
-    def str_format(self, box):
-        value = self.unbox(box)
+    def _str_format(self, value):
         return "True" if value else "False"
 
     def for_computation(self, v):
@@ -301,8 +303,7 @@
     def _coerce(self, space, w_item):
         return self._base_coerce(space, w_item)
 
-    def str_format(self, box):
-        value = self.unbox(box)
+    def _str_format(self, value):
         return str(self.for_computation(value))
 
     def for_computation(self, v):
@@ -473,9 +474,9 @@
     def _coerce(self, space, w_item):
         return self.box(space.float_w(space.call_function(space.w_float, w_item)))
 
-    def str_format(self, box):
-        value = self.unbox(box)
-        return float2string(self.for_computation(value), "g", rfloat.DTSF_STR_PRECISION)
+    def _str_format(self, value):
+        return float2string(self.for_computation(value), "g",
+                            rfloat.DTSF_STR_PRECISION)
 
     def for_computation(self, v):
         return float(v)
@@ -680,6 +681,20 @@
         for k in range(self.get_element_size()):
             arr.storage[k + i] = box.arr.storage[k + box.ofs]
 
+    @jit.unroll_safe
+    def str_format(self, box):
+        pieces = ["("]
+        first = True
+        for ofs, tp in self.offsets_and_fields:
+            if first:
+                first = False
+            else:
+                pieces.append(", ")
+            pieces.append(tp._str_format(tp._read(box.arr.storage, 1, box.ofs,
+                                                  ofs)))
+        pieces.append(")")
+        return "".join(pieces)
+
 for tp in [Int32, Int64]:
     if tp.T == lltype.Signed:
         IntP = tp


More information about the pypy-commit mailing list