[pypy-commit] pypy dtypes-compatability: fix maxalign calclulation, apply to offsets

mattip noreply at buildbot.pypy.org
Fri Jul 10 09:10:11 CEST 2015


Author: mattip <matti.picus at gmail.com>
Branch: dtypes-compatability
Changeset: r78516:34d98db0437f
Date: 2015-07-02 22:53 -0400
http://bitbucket.org/pypy/pypy/changeset/34d98db0437f/

Log:	fix maxalign calclulation, apply to offsets

diff --git a/pypy/module/micronumpy/descriptor.py b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -604,8 +604,10 @@
         fields[fldname] = offsets[i], subdtype
         if title is not None:
             fields[title] = offsets[i], subdtype
-        maxalign = max(subdtype.elsize, maxalign)
-        delta = subdtype.elsize
+        maxalign = max(subdtype.alignment, maxalign)
+        if not subdtype.is_record():
+            maxalign = max(subdtype.elsize, maxalign)
+        delta = subdtype.alignment
         if  i + 1 < len(offsets) and offsets[i + 1] == 0:
             if alignment >= 0:
                 # Set offset to the next power-of-two above delta
@@ -613,15 +615,12 @@
                 if delta > offsets[i]:
                     for j in range(i):
                         offsets[j+1] = delta + offsets[j]
-            offsets[i + 1] = offsets[i] + delta
-        print maxalign, delta, subdtype, subdtype.alignment, alignment
+            offsets[i + 1] = offsets[i] + max(delta, subdtype.elsize)
         names.append((fldname, title))
-        if alignment >= 0:
-            total = len(offsets) * maxalign
-        else:
-            total += subdtype.elsize
+    total = offsets[-1] + max(maxalign, fields[names[-1][0]][1].elsize)
     retval = W_Dtype(types.RecordType(space), space.gettypefor(boxes.W_VoidBox),
                    names=names, fields=fields, elsize=total)
+    retval.alignment = maxalign
     retval.flags |= NPY.NEEDS_PYAPI
     return retval
 
@@ -722,8 +721,11 @@
             'numpy.core._internal', '_commastring', Arguments(space, [w_spec]))
     else:
         # handle only simple cases for testing
-        spec = [s.strip() for s in space.str_w(w_spec).split(',')]
-        w_lst = space.newlist([space.wrap(s) for s in spec]) 
+        if space.isinstance_w(w_spec, space.w_str):
+            spec = [s.strip() for s in space.str_w(w_spec).split(',')]
+            w_lst = space.newlist([space.wrap(s) for s in spec]) 
+        elif space.isinstance_w(w_spec, space.w_list):
+            w_lst = w_spec
     if not space.isinstance_w(w_lst, space.w_list) or space.len_w(w_lst) < 1:
         raise oefmt(space.w_RuntimeError,
                     "_commastring is not returning a list with len >= 1")
@@ -835,7 +837,7 @@
     elif space.isinstance_w(w_dtype, space.w_tuple):
         w_dtype0 = space.getitem(w_dtype, space.wrap(0))
         w_dtype1 = space.getitem(w_dtype, space.wrap(1))
-        subdtype = make_new_dtype(space, w_subtype, w_dtype0, align, copy)
+        subdtype = make_new_dtype(space, w_subtype, w_dtype0, alignment, copy)
         assert isinstance(subdtype, W_Dtype)
         if subdtype.elsize == 0:
             name = "%s%d" % (subdtype.kind, space.int_w(w_dtype1))


More information about the pypy-commit mailing list