[pypy-commit] pypy default: allow only C, F in concrete type order

mattip noreply at buildbot.pypy.org
Sun Jun 7 17:16:59 CEST 2015


Author: mattip <matti.picus at gmail.com>
Branch: 
Changeset: r77938:ccf856368ecd
Date: 2015-06-07 16:10 +0300
http://bitbucket.org/pypy/pypy/changeset/ccf856368ecd/

Log:	allow only C, F in concrete type order

diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -338,23 +338,21 @@
         # but make the array storage contiguous in memory
         shape = self.get_shape()
         strides = self.get_strides()
-        if len(strides) > 0:
+        if order not in ('C', 'F'):
+            raise oefmt(space.w_ValueError, "Unknown order %s in astype", order)
+        if len(strides) == 0:
+            t_strides = []
+            backstrides = []
+        elif order != self.order:
+            t_strides, backstrides = calc_strides(shape, dtype, order)
+        else:
             mins = strides[0]
             t_elsize = dtype.elsize
             for s in strides:
                 if s < mins:
                     mins = s
             t_strides = [s * t_elsize / mins for s in strides]
-            if order == 'K':
-                pass
-            elif order not in ('C', 'F'):
-                raise oefmt(space.w_ValueError, "Unknown order %s in astype", order)
-            elif order != self.order:
-                t_strides.reverse()
             backstrides = calc_backstrides(t_strides, shape)
-        else:
-            t_strides = []
-            backstrides = []
         impl = ConcreteArray(shape, dtype, order, t_strides, backstrides)
         loop.setslice(space, impl.get_shape(), impl, self)
         return impl
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -44,16 +44,6 @@
         raise oefmt(space.w_ValueError, "objects are not aligned")
     return out_shape, right_critical_dim
 
-def get_order(proto_order, order):
-    if order == 'C':
-        return 'C'
-    elif order == 'F':
-        return 'F'
-    elif order == 'K':
-        return proto_order
-    elif order == 'A':
-        return proto_order
-
 class __extend__(W_NDimArray):
     @jit.unroll_safe
     def descr_get_shape(self, space):
@@ -620,10 +610,10 @@
                     space, 'S' + str(cur_dtype.elsize))
         if not can_cast_array(space, self, new_dtype, casting):
             raise oefmt(space.w_TypeError, "Cannot cast array from %s to %s"
-                        "according to the rule %s", 
+                        "according to the rule %s",
                         space.str_w(self.get_dtype().descr_repr(space)),
                         space.str_w(new_dtype.descr_repr(space)), casting)
-        order  = get_order(self.get_order(), order)
+        order  = support.get_order_as_CF(self.get_order(), order)
         if (not copy and new_dtype == self.get_dtype() and order == self.get_order()
                 and (subok or type(self) is W_NDimArray)):
             return self
diff --git a/pypy/module/micronumpy/nditer.py b/pypy/module/micronumpy/nditer.py
--- a/pypy/module/micronumpy/nditer.py
+++ b/pypy/module/micronumpy/nditer.py
@@ -460,17 +460,18 @@
         # handle w_op_dtypes part 2: copy where needed if possible
         if len(self.dtypes) > 0:
             for i in range(len(self.seq)):
-                selfd = self.dtypes[i]
+                self_d = self.dtypes[i]
                 seq_d = self.seq[i].get_dtype()
-                if not selfd:
+                if not self_d:
                     self.dtypes[i] = seq_d
-                elif selfd != seq_d:
+                elif self_d != seq_d:
                     if not 'r' in self.op_flags[i].tmp_copy:
                         raise oefmt(space.w_TypeError,
                                     "Iterator operand required copying or "
                                     "buffering for operand %d", i)
                     impl = self.seq[i].implementation
-                    new_impl = impl.astype(space, selfd, self.order)
+                    order = support.get_order_as_CF(impl.order, self.order)
+                    new_impl = impl.astype(space, self_d, order)
                     self.seq[i] = W_NDimArray(new_impl)
         else:
             #copy them from seq
diff --git a/pypy/module/micronumpy/support.py b/pypy/module/micronumpy/support.py
--- a/pypy/module/micronumpy/support.py
+++ b/pypy/module/micronumpy/support.py
@@ -161,3 +161,14 @@
     w_priority_r = space.findattr(w_rhs, space.wrap('__array_priority__')) or w_zero
     # XXX what is better, unwrapping values or space.gt?
     return space.is_true(space.gt(w_priority_r, w_priority_l))
+
+def get_order_as_CF(proto_order, req_order):
+    if req_order == 'C':
+        return 'C'
+    elif req_order == 'F':
+        return 'F'
+    elif req_order == 'K':
+        return proto_order
+    elif req_order == 'A':
+        return proto_order
+


More information about the pypy-commit mailing list