Author: Matti Picus <[email protected]>
Branch: ndarray-subtype
Changeset: r65446:416b328ff61a
Date: 2013-07-17 20:06 +0300
http://bitbucket.org/pypy/pypy/changeset/416b328ff61a/

Log:    fixes from review (amaury)

diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -33,7 +33,7 @@
         self.implementation = implementation
 
     @staticmethod
-    def from_shape(space, shape, dtype, order='C', w_subtype=None):
+    def from_shape(space, shape, dtype, order='C', w_instance=None):
         from pypy.module.micronumpy.arrayimpl import concrete, scalar
 
         if not shape:
@@ -42,12 +42,8 @@
             strides, backstrides = calc_strides(shape, dtype.base, order)
             impl = concrete.ConcreteArray(shape, dtype.base, order, strides,
                                       backstrides)
-        if w_subtype:
-            w_ret = space.allocate_instance(W_NDimArray, space.type(w_subtype))
-            W_NDimArray.__init__(w_ret, impl)
-            assert isinstance(w_ret, W_NDimArray)
-            space.call_method(w_ret, '__array_finalize__', w_subtype)
-            return w_ret
+        if w_instance:
+            return wrap_impl(space, space.type(w_instance), w_instance, impl)
         return W_NDimArray(impl)
 
     @staticmethod
diff --git a/pypy/module/micronumpy/interp_arrayops.py 
b/pypy/module/micronumpy/interp_arrayops.py
--- a/pypy/module/micronumpy/interp_arrayops.py
+++ b/pypy/module/micronumpy/interp_arrayops.py
@@ -151,7 +151,7 @@
         arr = arr.descr_flatten(space)
         orig_size = arr.get_shape()[0]
         shape = [arr.get_shape()[0] * repeats]
-        w_res = W_NDimArray.from_shape(space, shape, arr.get_dtype(), 
w_subtype=arr)
+        w_res = W_NDimArray.from_shape(space, shape, arr.get_dtype(), 
w_instance=arr)
         for i in range(repeats):
             Chunks([Chunk(i, shape[0] - repeats + i, repeats,
                  orig_size)]).apply(space, 
w_res).implementation.setslice(space, arr)
@@ -161,7 +161,7 @@
         chunks = [Chunk(0, i, 1, i) for i in shape]
         orig_size = shape[axis]
         shape[axis] *= repeats
-        w_res = W_NDimArray.from_shape(space, shape, arr.get_dtype(), 
w_subtype=arr)
+        w_res = W_NDimArray.from_shape(space, shape, arr.get_dtype(), 
w_instance=arr)
         for i in range(repeats):
             chunks[axis] = Chunk(i, shape[axis] - repeats + i, repeats,
                                  orig_size)
diff --git a/pypy/module/micronumpy/interp_flatiter.py 
b/pypy/module/micronumpy/interp_flatiter.py
--- a/pypy/module/micronumpy/interp_flatiter.py
+++ b/pypy/module/micronumpy/interp_flatiter.py
@@ -65,7 +65,7 @@
         if length == 1:
             return base_iter.getitem()
         res = W_NDimArray.from_shape(space, [length], base.get_dtype(),
-                                     base.get_order(), w_subtype=base)
+                                     base.get_order(), w_instance=base)
         return loop.flatiter_getitem(res, base_iter, step)
 
     def descr_setitem(self, space, w_idx, w_value):
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
@@ -85,7 +85,7 @@
             res_shape = [size] + self.get_shape()[1:]
         else:
             res_shape = [size]
-        w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(), 
w_subtype=self)
+        w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(), 
w_instance=self)
         return loop.getitem_filter(w_res, self, arr)
 
     def setitem_filter(self, space, idx, val):
@@ -148,7 +148,7 @@
             return chunks.apply(space, self)
         shape = res_shape + self.get_shape()[len(indexes):]
         w_res = W_NDimArray.from_shape(space, shape, self.get_dtype(),
-                                     self.get_order(), w_subtype=self)
+                                     self.get_order(), w_instance=self)
         if not w_res.get_size():
             return w_res
         return loop.getitem_array_int(space, self, w_res, iter_shape, indexes,
@@ -482,7 +482,7 @@
             loop.byteswap(self.implementation, self.implementation)
             return self
         else:
-            w_res = W_NDimArray.from_shape(space, self.get_shape(), 
self.get_dtype(), w_subtype=self)
+            w_res = W_NDimArray.from_shape(space, self.get_shape(), 
self.get_dtype(), w_instance=self)
             loop.byteswap(self.implementation, w_res.implementation)
             return w_res
 
@@ -778,7 +778,7 @@
             return W_NDimArray.new_scalar(space, dtype, space.wrap(0))
         # Do the dims match?
         out_shape, other_critical_dim = match_dot_shapes(space, self, other)
-        w_res = W_NDimArray.from_shape(space, out_shape, dtype, w_subtype=self)
+        w_res = W_NDimArray.from_shape(space, out_shape, dtype, 
w_instance=self)
         # This is the place to add fpypy and blas
         return loop.multidim_dot(space, self, other,  w_res, dtype,
                                  other_critical_dim)
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -182,7 +182,7 @@
                 if out:
                     dtype = out.get_dtype()
                 temp = W_NDimArray.from_shape(space, temp_shape, dtype,
-                                                w_subtype=obj)
+                                                w_instance=obj)
             elif keepdims:
                 shape = obj_shape[:axis] + [1] + obj_shape[axis + 1:]
             else:
@@ -208,7 +208,7 @@
                         )
                 dtype = out.get_dtype()
             else:
-                out = W_NDimArray.from_shape(space, shape, dtype, 
w_subtype=obj)
+                out = W_NDimArray.from_shape(space, shape, dtype, 
w_instance=obj)
             return loop.do_axis_reduce(shape, self.func, obj, dtype, axis, out,
                                        self.identity, cumultative, temp)
         if cumultative:
@@ -217,7 +217,7 @@
                     raise OperationError(space.w_ValueError, space.wrap(
                         "out of incompatible size"))
             else:
-                out = W_NDimArray.from_shape(space, [obj.get_size()], dtype, 
w_subtype=obj)
+                out = W_NDimArray.from_shape(space, [obj.get_size()], dtype, 
w_instance=obj)
             loop.compute_reduce_cumultative(obj, out, dtype, self.func,
                                             self.identity)
             return out
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -47,7 +47,7 @@
 
     if out is None:
         out = W_NDimArray.from_shape(space, shape, res_dtype,
-                                     w_subtype=lhs_for_subtype)
+                                     w_instance=lhs_for_subtype)
     left_iter = w_lhs.create_iter(shape)
     right_iter = w_rhs.create_iter(shape)
     out_iter = out.create_iter(shape)
@@ -76,7 +76,7 @@
 
 def call1(space, shape, func, calc_dtype, res_dtype, w_obj, out):
     if out is None:
-        out = W_NDimArray.from_shape(space, shape, res_dtype, w_subtype=w_obj)
+        out = W_NDimArray.from_shape(space, shape, res_dtype, w_instance=w_obj)
     obj_iter = w_obj.create_iter(shape)
     out_iter = out.create_iter(shape)
     shapelen = len(shape)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to