[pypy-commit] pypy ndarray-promote: use jit.promote for arr.implementation and other attributes

mattip noreply at buildbot.pypy.org
Tue Oct 20 19:19:25 EDT 2015


Author: mattip <matti.picus at gmail.com>
Branch: ndarray-promote
Changeset: r80363:085cd1fc6e97
Date: 2015-10-19 17:04 +0800
http://bitbucket.org/pypy/pypy/changeset/085cd1fc6e97/

Log:	use jit.promote for arr.implementation and other attributes

diff --git a/pypy/module/micronumpy/arrayops.py b/pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -150,7 +150,7 @@
         chunks[axis] = Chunk(axis_start, axis_start + arr.get_shape()[axis], 1,
                              arr.get_shape()[axis])
         view = new_view(space, res, chunks)
-        view.implementation.setslice(space, arr)
+        view.get_implementation().setslice(space, arr)
         axis_start += arr.get_shape()[axis]
     return res
 
@@ -166,7 +166,7 @@
         for i in range(repeats):
             chunks = [Chunk(i, shape[0] - repeats + i, repeats, orig_size)]
             view = new_view(space, w_res, chunks)
-            view.implementation.setslice(space, arr)
+            view.get_implementation().setslice(space, arr)
     else:
         axis = space.int_w(w_axis)
         shape = arr.get_shape()[:]
@@ -178,7 +178,7 @@
             chunks[axis] = Chunk(i, shape[axis] - repeats + i, repeats,
                                  orig_size)
             view = new_view(space, w_res, chunks)
-            view.implementation.setslice(space, arr)
+            view.get_implementation().setslice(space, arr)
     return w_res
 
 
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
@@ -1,6 +1,7 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
 from rpython.tool.pairtype import extendabletype
+from rpython.rlib import jit
 from rpython.rlib.rarithmetic import ovfcheck
 from pypy.module.micronumpy import support
 from pypy.module.micronumpy import constants as NPY
@@ -122,8 +123,8 @@
     def new_slice(space, offset, strides, backstrides, shape, parent, w_arr, dtype=None):
         from pypy.module.micronumpy import concrete
         w_base = w_arr
-        if w_arr.implementation.base() is not None:
-            w_base = w_arr.implementation.base()
+        if w_arr.get_implementation().base() is not None:
+            w_base = w_arr.get_implementation().base()
         impl = concrete.SliceArray(offset, strides, backstrides, shape, parent,
                                    w_base, dtype)
         return wrap_impl(space, space.type(w_arr), w_arr, impl)
@@ -145,19 +146,30 @@
         return w_arr
 
     def get_shape(self):
-        return self.implementation.get_shape()
+        return self.get_implementation().get_shape()
+
+    def get_implementation(self):
+        implementation = self.implementation
+        jit.hint(implementation, promote=True)
+        return implementation
 
     def get_dtype(self, space=None):
-        return self.implementation.dtype
+        dtype = self.get_implementation().dtype
+        jit.hint(dtype, promote=True)
+        return dtype
 
     def get_order(self):
-        return self.implementation.order
+        order = self.get_implementation().order
+        jit.hint(order, promote=True)
+        return order
 
     def get_start(self):
-        return self.implementation.start
+        start = self.get_implementation().start
+        jit.hint(start, promote=True)
+        return start
 
     def get_flags(self):
-        return self.implementation.flags
+        return self.get_implementation().get_flags()
 
     def ndims(self):
         return len(self.get_shape())
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
@@ -57,7 +57,9 @@
         return backstrides
 
     def get_flags(self):
-        return self.flags
+        flags = self.flags
+        jit.hint(flags, promote=True)
+        return flags
 
     def getitem(self, index):
         return self.dtype.read(self, index, 0)
@@ -84,7 +86,7 @@
                     ','.join([str(x) for x in self.get_shape()]),
                     )
         shape = shape_agreement(space, self.get_shape(), arr)
-        impl = arr.implementation
+        impl = arr.get_implementation()
         if impl.storage == self.storage:
             impl = impl.copy(space)
         loop.setslice(space, shape, self, impl)
@@ -293,7 +295,7 @@
             w_value = convert_to_array(space, w_value)
             chunks = self._prepare_slice_args(space, w_index)
             view = new_view(space, orig_arr, chunks)
-            view.implementation.setslice(space, w_value)
+            view.get_implementation().setslice(space, w_value)
 
     def transpose(self, orig_array, axes=None):
         if len(self.get_shape()) < 2:
@@ -347,7 +349,7 @@
         nd = len(self.get_shape()) or 1
         w_res = W_NDimArray.from_shape(space, [s, nd], index_type)
         loop.nonzero(w_res, self, box)
-        w_res = w_res.implementation.swapaxes(space, w_res, 0, 1)
+        w_res = w_res.get_implementation().swapaxes(space, w_res, 0, 1)
         l_w = [w_res.descr_getitem(space, space.wrap(d)) for d in range(nd)]
         return space.newtuple(l_w)
 
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -77,7 +77,7 @@
     shape = w_res.get_shape()
     if len(shape) < ndmin:
         shape = [1] * (ndmin - len(shape)) + shape
-        impl = w_res.implementation.set_shape(space, w_res, shape)
+        impl = w_res.get_implementation().set_shape(space, w_res, shape)
         if w_res is w_object:
             return W_NDimArray(impl)
         else:
@@ -127,12 +127,12 @@
             w_arr = W_NDimArray.from_shape(space, shape, dtype, order=npy_order)
             if support.product(shape) == 1:
                 w_arr.set_scalar_value(dtype.coerce(space,
-                        w_object.implementation.getitem(0)))
+                        w_object.get_implementation().getitem(0)))
             else:
-                loop.setslice(space, shape, w_arr.implementation, w_object.implementation)
+                loop.setslice(space, shape, w_arr.get_implementation(), w_object.implementation)
             return w_arr
         else:
-            imp = w_object.implementation
+            imp = w_object.get_implementation()
             w_base = w_object
             if imp.base() is not None:
                 w_base = imp.base()
@@ -302,7 +302,7 @@
             dtype = descriptor.variable_dtype(space, dtype.char + '1')
     if npy_order in (NPY.KEEPORDER, NPY.ANYORDER):
         # Try to copy the stride pattern
-        impl = w_a.implementation.astype(space, dtype, NPY.KEEPORDER)
+        impl = w_a.get_implementation().astype(space, dtype, NPY.KEEPORDER)
         if subok:
             w_type = space.type(w_a)
         else:
diff --git a/pypy/module/micronumpy/flatiter.py b/pypy/module/micronumpy/flatiter.py
--- a/pypy/module/micronumpy/flatiter.py
+++ b/pypy/module/micronumpy/flatiter.py
@@ -15,7 +15,7 @@
         self._base = base
         self.dtype = base.get_dtype()
         self.shape = [base.get_size()]
-        self.storage = self._base.implementation.storage
+        self.storage = self._base.get_implementation().storage
 
     def base(self):
         return self._base
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
@@ -358,7 +358,7 @@
     out_iter.track_index = False
     shape = w_arr.get_shape()
     shapelen = len(shape)
-    inner_iter, outer_iter = split_iter(w_arr.implementation, axis_flags)
+    inner_iter, outer_iter = split_iter(w_arr.get_implementation(), axis_flags)
     assert outer_iter.size == out_iter.size
 
     if identity is not None:
@@ -423,7 +423,7 @@
     arr_shape = w_arr.get_shape()
     temp_shape = arr_shape[:axis] + arr_shape[axis + 1:]
     temp = W_NDimArray.from_shape(space, temp_shape, calc_dtype, w_instance=w_arr)
-    temp_iter = AxisIter(temp.implementation, w_arr.get_shape(), axis)
+    temp_iter = AxisIter(temp.get_implementation(), w_arr.get_shape(), axis)
     temp_state = temp_iter.reset()
     arr_iter, arr_state = w_arr.create_iter()
     arr_iter.track_index = False
@@ -521,7 +521,7 @@
         shapelen = len(w_arr.get_shape())
         axis_flags = [False] * shapelen
         axis_flags[axis] = True
-        inner_iter, outer_iter = split_iter(w_arr.implementation, axis_flags)
+        inner_iter, outer_iter = split_iter(w_arr.get_implementation(), axis_flags)
         outer_state = outer_iter.reset()
         out_iter, out_state = w_out.create_iter()
         while not outer_iter.done(outer_state):
@@ -590,8 +590,8 @@
     '''
     left_shape = left.get_shape()
     right_shape = right.get_shape()
-    left_impl = left.implementation
-    right_impl = right.implementation
+    left_impl = left.get_implementation()
+    right_impl = right.get_implementation()
     assert left_shape[-1] == right_shape[right_critical_dim]
     assert result.get_dtype() == dtype
     outi, outs = result.create_iter()
@@ -644,7 +644,7 @@
     if arr.is_scalar():
         return arr.get_dtype().itemtype.bool(arr.get_scalar_value())
     else:
-        return count_all_true_concrete(arr.implementation)
+        return count_all_true_concrete(arr.get_implementation())
 
 nonzero_driver = jit.JitDriver(name = 'numpy_nonzero',
                                greens = ['shapelen', 'dims', 'dtype'],
@@ -784,11 +784,11 @@
     iter, state = arr.create_iter()
     w_res_str = W_NDimArray.from_shape(space, [1], arr.get_dtype())
     itemsize = arr.get_dtype().elsize
-    with w_res_str.implementation as storage:
+    with w_res_str.get_implementation() as storage:
         res_str_casted = rffi.cast(rffi.CArrayPtr(lltype.Char),
                                support.get_storage_as_int(storage))
         while not iter.done(state):
-            w_res_str.implementation.setitem(0, iter.getitem(state))
+            w_res_str.get_implementation().setitem(0, iter.getitem(state))
             for i in range(itemsize):
                 builder.append(res_str_casted[i])
             state = iter.next(state)
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
@@ -57,7 +57,7 @@
 
     def descr_set_shape(self, space, w_new_shape):
         shape = get_shape_from_iterable(space, self.get_size(), w_new_shape)
-        self.implementation = self.implementation.set_shape(space, self, shape)
+        self.implementation = self.get_implementation().set_shape(space, self, shape)
         w_cls = space.type(self)
         if not space.is_w(w_cls, space.gettypefor(W_NDimArray)):
             # numpy madness - allow __array_finalize__(self, obj)
@@ -65,11 +65,11 @@
             wrap_impl(space, w_cls, self, self.implementation)
 
     def descr_get_strides(self, space):
-        strides = self.implementation.get_strides()
+        strides = self.get_implementation().get_strides()
         return space.newtuple([space.wrap(i) for i in strides])
 
     def descr_get_dtype(self, space):
-        return self.implementation.dtype
+        return self.get_dtype()
 
     def descr_set_dtype(self, space, w_dtype):
         dtype = space.interp_w(descriptor.W_Dtype, space.call_function(
@@ -104,7 +104,7 @@
         order = support.get_order_as_CF(self.get_order(), order)
         arr = self
         if order != arr.get_order():
-            arr = W_NDimArray(self.implementation.transpose(self, None))
+            arr = W_NDimArray(self.get_implementation().transpose(self, None))
         return space.wrap(loop.tostring(space, arr))
 
     def getitem_filter(self, space, arr):
@@ -186,7 +186,7 @@
             self._prepare_array_index(space, w_index)
         if iter_shape is None:
             # w_index is a list of slices, return a view
-            chunks = self.implementation._prepare_slice_args(space, w_index)
+            chunks = self.get_implementation()._prepare_slice_args(space, w_index)
             return new_view(space, self, chunks)
         shape = res_shape + self.get_shape()[len(indexes):]
         w_res = W_NDimArray.from_shape(space, shape, self.get_dtype(),
@@ -202,9 +202,9 @@
             self._prepare_array_index(space, w_index)
         if iter_shape is None:
             # w_index is a list of slices
-            chunks = self.implementation._prepare_slice_args(space, w_index)
+            chunks = self.get_implementation()._prepare_slice_args(space, w_index)
             view = new_view(space, self, chunks)
-            view.implementation.setslice(space, val_arr)
+            view.get_implementation().setslice(space, val_arr)
             return
         if support.product(iter_shape) == 0:
             return
@@ -227,7 +227,7 @@
                         "interpreted as a valid boolean index")
         else:
             try:
-                w_ret = self.implementation.descr_getitem(space, self, w_idx)
+                w_ret = self.get_implementation().descr_getitem(space, self, w_idx)
             except ArrayArgumentException:
                 w_ret = self.getitem_array_int(space, w_idx)
         if isinstance(w_ret, boxes.W_ObjectBox):
@@ -236,10 +236,10 @@
         return w_ret
 
     def getitem(self, space, index_list):
-        return self.implementation.getitem_index(space, index_list)
+        return self.get_implementation().getitem_index(space, index_list)
 
     def setitem(self, space, index_list, w_value):
-        self.implementation.setitem_index(space, index_list, w_value)
+        self.get_implementation().setitem_index(space, index_list, w_value)
 
     def descr_setitem(self, space, w_idx, w_value):
         if self.get_dtype().is_record():
@@ -247,10 +247,10 @@
                 idx = space.str_w(w_idx)
                 view = self.getfield(space, idx)
                 w_value = convert_to_array(space, w_value)
-                view.implementation.setslice(space, w_value)
+                view.get_implementation().setslice(space, w_value)
                 return
         if space.is_w(w_idx, space.w_Ellipsis):
-            self.implementation.setslice(space, convert_to_array(space, w_value))
+            self.get_implementation().setslice(space, convert_to_array(space, w_value))
             return
         # TODO: multiarray/mapping.c calls a subclass's __getitem__ here, which
         # is a big performance hit but necessary for the matrix class. The original
@@ -271,7 +271,7 @@
             self.setitem_filter(space, w_idx, convert_to_array(space, w_value))
             return
         try:
-            self.implementation.descr_setitem(space, self, w_idx, w_value)
+            self.get_implementation().descr_setitem(space, self, w_idx, w_value)
         except ArrayArgumentException:
             self.setitem_array_int(space, w_idx, w_value)
 
@@ -279,7 +279,7 @@
         dtype = self.get_dtype()
         if field not in dtype.fields:
             raise oefmt(space.w_ValueError, "field named %s not found", field)
-        arr = self.implementation
+        arr = self.get_implementation()
         ofs, subdtype = arr.dtype.fields[field][:2]
         # ofs only changes start
         # create a view of the original array by extending
@@ -345,28 +345,28 @@
         return s.build()
 
     def create_iter(self, shape=None, backward_broadcast=False):
-        assert isinstance(self.implementation, BaseConcreteArray)
-        return self.implementation.create_iter(
+        assert isinstance(self.get_implementation(), BaseConcreteArray)
+        return self.get_implementation().create_iter(
             shape=shape, backward_broadcast=backward_broadcast)
 
     def is_scalar(self):
         return self.ndims() == 0
 
     def set_scalar_value(self, w_val):
-        return self.implementation.setitem(self.implementation.start, w_val)
+        return self.get_implementation().setitem(self.implementation.start, w_val)
 
     def fill(self, space, box):
-        self.implementation.fill(space, box)
+        self.get_implementation().fill(space, box)
 
     def descr_get_size(self, space):
         return space.wrap(self.get_size())
 
     def get_size(self):
-        return self.implementation.get_size()
+        return self.get_implementation().get_size()
 
     def get_scalar_value(self):
         assert self.get_size() == 1
-        return self.implementation.getitem(self.implementation.start)
+        return self.get_implementation().getitem(self.implementation.start)
 
     def descr_copy(self, space, w_order=None):
         if w_order is None:
@@ -375,45 +375,45 @@
             order = space.int_w(w_order)
         else:
             order = order_converter(space, w_order, NPY.KEEPORDER)
-        copy = self.implementation.copy(space, order)
+        copy = self.get_implementation().copy(space, order)
         w_subtype = space.type(self)
         return wrap_impl(space, w_subtype, self, copy)
 
     def descr_get_real(self, space):
-        ret = self.implementation.get_real(space, self)
+        ret = self.get_implementation().get_real(space, self)
         return wrap_impl(space, space.type(self), self, ret)
 
     def descr_get_imag(self, space):
-        ret = self.implementation.get_imag(space, self)
+        ret = self.get_implementation().get_imag(space, self)
         return wrap_impl(space, space.type(self), self, ret)
 
     def descr_set_real(self, space, w_value):
         # copy (broadcast) values into self
-        self.implementation.set_real(space, self, w_value)
+        self.get_implementation().set_real(space, self, w_value)
 
     def descr_set_imag(self, space, w_value):
         # if possible, copy (broadcast) values into self
         if not self.get_dtype().is_complex():
             raise oefmt(space.w_TypeError,
                         'array does not have imaginary part to set')
-        self.implementation.set_imag(space, self, w_value)
+        self.get_implementation().set_imag(space, self, w_value)
 
     def reshape(self, space, w_shape, order):
         new_shape = get_shape_from_iterable(space, self.get_size(), w_shape)
-        new_impl = self.implementation.reshape(self, new_shape, order)
+        new_impl = self.get_implementation().reshape(self, new_shape, order)
         if new_impl is not None:
             return wrap_impl(space, space.type(self), self, new_impl)
         # Create copy with contiguous data
         arr = self.descr_copy(space, space.wrap(order))
         if arr.get_size() > 0:
-            new_implementation = arr.implementation.reshape(self, new_shape, order)
+            new_implementation = arr.get_implementation().reshape(self, new_shape, order)
             if new_implementation is None:
                 raise oefmt(space.w_ValueError,
                             'could not reshape array of size %d to shape %s',
                             arr.get_size(), str(new_shape))
             arr.implementation = new_implementation
         else:
-            arr.implementation.shape = new_shape
+            arr.get_implementation().shape = new_shape
         return arr
 
     def descr_reshape(self, space, __args__):
@@ -449,7 +449,7 @@
         return self.reshape(space, w_shape, order)
 
     def descr_get_transpose(self, space, axes=None):
-        return W_NDimArray(self.implementation.transpose(self, axes))
+        return W_NDimArray(self.get_implementation().transpose(self, axes))
 
     def descr_transpose(self, space, args_w):
         if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple):
@@ -501,11 +501,11 @@
             raise oefmt(space.w_ValueError, "bad axis1 argument to swapaxes")
         if axis2 < 0 or axis2 >= n:
             raise oefmt(space.w_ValueError, "bad axis2 argument to swapaxes")
-        return self.implementation.swapaxes(space, self, axis1, axis2)
+        return self.get_implementation().swapaxes(space, self, axis1, axis2)
 
     def descr_nonzero(self, space):
         index_type = get_dtype_cache(space).w_int64dtype
-        return self.implementation.nonzero(space, index_type)
+        return self.get_implementation().nonzero(space, index_type)
 
     def descr_tolist(self, space):
         if self.ndims() == 0:
@@ -542,7 +542,7 @@
             # scalars have no storage
             return self.reshape(space, space.wrap(1), order)
         w_res = self.descr_ravel(space, w_order)
-        if w_res.implementation.storage == self.implementation.storage:
+        if w_res.get_implementation().storage == self.get_implementation().storage:
             return w_res.descr_copy(space)
         return w_res
 
@@ -555,7 +555,7 @@
         dtype = self.get_dtype()
         w_arr = convert_to_array(space, w_obj)
         if dtype.is_record():
-            return self.implementation.setslice(space, w_arr)
+            return self.get_implementation().setslice(space, w_arr)
         loop.flatiter_setitem(space, dtype, w_arr, iter, state, 1, iter.size)
 
     def descr_get_flatiter(self, space):
@@ -607,7 +607,7 @@
         # sz cannot overflow since self is valid
         sz = support.product(self.get_shape()) * self.get_dtype().elsize
         return W_NDimArray.from_shape_and_storage(
-            space, self.get_shape(), self.implementation.storage,
+            space, self.get_shape(), self.get_implementation().storage,
             self.get_dtype(), storage_bytes=sz, w_base=self)
 
     def descr_array_iface(self, space):
@@ -615,7 +615,7 @@
         Note: arr.__array__.data[0] is a pointer so arr must be kept alive
               while it is in use
         '''
-        with self.implementation as storage:
+        with self.get_implementation() as storage:
             addr = support.get_storage_as_int(storage, self.get_start())
             # will explode if it can't
             w_d = space.newdict()
@@ -623,7 +623,7 @@
                               space.newtuple([space.wrap(addr), space.w_False]))
             space.setitem_str(w_d, 'shape', self.descr_get_shape(space))
             space.setitem_str(w_d, 'typestr', self.get_dtype().descr_get_str(space))
-            if self.implementation.order == NPY.CORDER:
+            if self.get_order() == NPY.CORDER:
                 # Array is contiguous, no strides in the interface.
                 strides = space.w_None
             else:
@@ -657,7 +657,7 @@
         if self.is_scalar():
             return space.wrap(0)
         dtype = self.get_dtype().descr_newbyteorder(space, NPY.NATIVE)
-        contig = self.implementation.astype(space, dtype, self.get_order())
+        contig = self.get_implementation().astype(space, dtype, self.get_order())
         return contig.argsort(space, w_axis)
 
     @unwrap_spec(order=str, casting=str, subok=bool, copy=bool)
@@ -673,7 +673,7 @@
             elsize = 0
             itype = cur_dtype.itemtype
             for i in range(self.get_size()):
-                elsize = max(elsize, len(itype.str_format(self.implementation.getitem(i), add_quotes=False)))
+                elsize = max(elsize, len(itype.str_format(self.get_implementation().getitem(i), add_quotes=False)))
             new_dtype = descriptor.variable_dtype(
                     space, 'S' + str(elsize))
 
@@ -687,7 +687,7 @@
                 and (order in (NPY.KEEPORDER, NPY.ANYORDER) or order == self.get_order())
                 and (subok or type(self) is W_NDimArray)):
             return self
-        impl = self.implementation
+        impl = self.get_implementation()
         new_impl = impl.astype(space, new_dtype, order)
         if new_impl is None:
             return self
@@ -698,7 +698,7 @@
         return wrap_impl(space, w_type, self, new_impl)
 
     def descr_get_base(self, space):
-        impl = self.implementation
+        impl = self.get_implementation()
         ret = impl.base()
         if ret is None:
             return space.w_None
@@ -707,7 +707,7 @@
     @unwrap_spec(inplace=bool)
     def descr_byteswap(self, space, inplace=False):
         if inplace:
-            loop.byteswap(self.implementation, self.implementation)
+            loop.byteswap(self.get_implementation(), self.get_implementation())
             return self
         else:
             w_res = W_NDimArray.from_shape(space, self.get_shape(),
@@ -748,19 +748,19 @@
         return w_result
 
     def buffer_w(self, space, flags):
-        return self.implementation.get_buffer(space, True)
+        return self.get_implementation().get_buffer(space, True)
 
     def readbuf_w(self, space):
-        return self.implementation.get_buffer(space, True)
+        return self.get_implementation().get_buffer(space, True)
 
     def writebuf_w(self, space):
-        return self.implementation.get_buffer(space, False)
+        return self.get_implementation().get_buffer(space, False)
 
     def charbuf_w(self, space):
-        return self.implementation.get_buffer(space, True).as_str()
+        return self.get_implementation().get_buffer(space, True).as_str()
 
     def descr_get_data(self, space):
-        return space.newbuffer(self.implementation.get_buffer(space, False))
+        return space.newbuffer(self.get_implementation().get_buffer(space, False))
 
     @unwrap_spec(offset=int, axis1=int, axis2=int)
     def descr_diagonal(self, space, offset=0, axis1=0, axis2=1):
@@ -775,7 +775,7 @@
         if axis1 == axis2:
             raise OperationError(space.w_ValueError, space.wrap(
                 "axis1 and axis2 cannot be the same"))
-        return arrayops.diagonal(space, self.implementation, offset, axis1, axis2)
+        return arrayops.diagonal(space, self.get_implementation(), offset, axis1, axis2)
 
     @unwrap_spec(offset=int, axis1=int, axis2=int)
     def descr_trace(self, space, offset=0, axis1=0, axis2=1,
@@ -884,7 +884,7 @@
         # modify the array in-place
         if self.is_scalar():
             return
-        return self.implementation.sort(space, w_axis, w_order)
+        return self.get_implementation().sort(space, w_axis, w_order)
 
     def descr_squeeze(self, space, w_axis=None):
         cur_shape = self.get_shape()
@@ -905,7 +905,7 @@
             return self
         # XXX need to call __array_wrap__
         return wrap_impl(space, space.type(self), self,
-                         self.implementation.get_view(
+                         self.get_implementation().get_view(
                              space, self, self.get_dtype(), new_shape))
 
     def descr_strides(self, space):
@@ -935,7 +935,7 @@
             dtype = self.get_dtype()
         old_itemsize = self.get_dtype().elsize
         new_itemsize = dtype.elsize
-        impl = self.implementation
+        impl = self.get_implementation()
         if new_itemsize == 0:
             raise OperationError(space.w_TypeError, space.wrap(
                 "data-type must not be 0-sized"))
@@ -1129,7 +1129,7 @@
             matches = True
             if dtype != out.get_dtype():
                 matches = False
-            elif not out.implementation.order == NPY.CORDER:
+            elif not out.get_order() == NPY.CORDER:
                 matches = False
             elif out.ndims() != len(out_shape):
                 matches = False
@@ -1306,16 +1306,16 @@
         if self.get_dtype().is_object():
             raise oefmt(space.w_NotImplementedError,
                     "reduce for 'object' dtype not supported yet")
-        if isinstance(self.implementation, SliceArray):
-            iter, state = self.implementation.create_iter()
+        if isinstance(self.get_implementation(), SliceArray):
+            iter, state = self.get_implementation().create_iter()
             while not iter.done(state):
                 box = iter.getitem(state)
                 builder.append(box.raw_str())
                 state = iter.next(state)
         else:
-            with self.implementation as storage:
+            with self.get_implementation() as storage:
                 builder.append_charpsize(storage,
-                                     self.implementation.get_storage_size())
+                                     self.get_implementation().get_storage_size())
 
         state = space.newtuple([
             space.wrap(1),      # version
@@ -1349,7 +1349,7 @@
         self.implementation = W_NDimArray.from_shape_and_storage(
             space, [space.int_w(i) for i in space.listview(shape)],
             rffi.str2charp(space.str_w(storage), track_allocation=False),
-            dtype, storage_bytes=space.len_w(storage), owning=True).implementation
+            dtype, storage_bytes=space.len_w(storage), owning=True).get_implementation()
 
     def descr___array_finalize__(self, space, w_obj):
         pass
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,7 +460,7 @@
         if self.tracked_index != "":
             order = self.order
             if order == NPY.KEEPORDER:
-                order = self.seq[0].implementation.order
+                order = self.seq[0].get_order()
             if self.tracked_index == "multi":
                 backward = False
             else:
@@ -477,7 +477,7 @@
                 if not self_d:
                     self.dtypes[i] = seq_d
                 elif self_d != seq_d:
-                        impl = self.seq[i].implementation
+                        impl = self.seq[i].get_implementation()
                         if self.buffered or 'r' in self.op_flags[i].tmp_copy:
                             if not can_cast_array(
                                     space, self.seq[i], self_d, self.casting):
@@ -527,7 +527,7 @@
 
     def get_iter(self, space, i):
         arr = self.seq[i]
-        imp = arr.implementation
+        imp = arr.get_implementation()
         if arr.is_scalar():
             return ConcreteIter(imp, 1, [], [], [], self.op_flags[i], self)
         shape = self.shape
diff --git a/pypy/module/micronumpy/selection.py b/pypy/module/micronumpy/selection.py
--- a/pypy/module/micronumpy/selection.py
+++ b/pypy/module/micronumpy/selection.py
@@ -134,7 +134,7 @@
         # create array of indexes
         dtype = descriptor.get_dtype_cache(space).w_longdtype
         index_arr = W_NDimArray.from_shape(space, arr.get_shape(), dtype)
-        with index_arr.implementation as storage, arr as arr_storage:
+        with index_arr.get_implementation() as storage, arr as arr_storage:
             if len(arr.get_shape()) == 1:
                 for i in range(arr.get_size()):
                     raw_storage_setitem(storage, i * INT_SIZE, i)
@@ -149,7 +149,7 @@
                     raise oefmt(space.w_IndexError, "Wrong axis %d", axis)
                 arr_iter = AllButAxisIter(arr, axis)
                 arr_state = arr_iter.reset()
-                index_impl = index_arr.implementation
+                index_impl = index_arr.get_implementation()
                 index_iter = AllButAxisIter(index_impl, axis)
                 index_state = index_iter.reset()
                 stride_size = arr.strides[axis]
diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -79,7 +79,7 @@
 
 
 def new_view(space, w_arr, chunks):
-    arr = w_arr.implementation
+    arr = w_arr.get_implementation()
     r = calculate_slice_strides(space, arr.shape, arr.start, arr.get_strides(),
                                 arr.get_backstrides(), chunks)
     shape, start, strides, backstrides = r
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -305,12 +305,12 @@
             if keepdims:
                 shape = [1] * len(obj_shape)
                 out = W_NDimArray.from_shape(space, shape, dtype, w_instance=obj)
-                out.implementation.setitem(0, res)
+                out.get_implementation().setitem(0, res)
                 res = out
             elif not space.is_w(space.type(w_obj), space.gettypefor(W_NDimArray)):
                 # subtypes return a ndarray subtype, not a scalar
                 out = W_NDimArray.from_shape(space, [1], dtype, w_instance=obj)
-                out.implementation.setitem(0, res)
+                out.get_implementation().setitem(0, res)
                 res = out
             if call__array_wrap__:
                 res = space.call_method(obj, '__array_wrap__', res, space.w_None)
@@ -869,7 +869,7 @@
                 _arg = allargs[i]
                 assert isinstance(_arg, W_NDimArray)
                 start_dim = len(iter_shape)
-                steps += _arg.implementation.strides[start_dim:]
+                steps += _arg.get_implementation().strides[start_dim:]
             func.set_dims_and_steps(space, dims, steps)
         else:
             # it is a function, ready to be called by the iterator,
@@ -1042,7 +1042,7 @@
             if len(arg_shapes[i]) != curarg.ndims():
                 # reshape
                 sz = product(curarg.get_shape()) * curarg.get_dtype().elsize
-                with curarg.implementation as storage:
+                with curarg.get_implementation() as storage:
                     inargs[i] = W_NDimArray.from_shape_and_storage(
                         space, arg_shapes[i], storage,
                         curarg.get_dtype(), storage_bytes=sz, w_base=curarg)
@@ -1056,7 +1056,7 @@
             elif len(arg_shapes[i]) != curarg.ndims():
                 # reshape
                 sz = product(curarg.get_shape()) * curarg.get_dtype().elsize
-                with curarg.implementation as storage:
+                with curarg.get_implementation() as storage:
                     outargs[i] = W_NDimArray.from_shape_and_storage(
                         space, arg_shapes[i], storage,
                         curarg.get_dtype(), storage_bytes=sz, w_base=curarg)
@@ -1541,7 +1541,7 @@
                     raise OperationError(space.w_NotImplementedError,
                          space.wrap("cannot mix ndarray and %r (arg %d) in call to ufunc" % (
                                     arg_i, i)))
-                with arg_i.implementation as storage:
+                with arg_i.get_implementation() as storage:
                     addr = get_storage_as_int(storage, arg_i.get_start())
                     raw_storage_setitem(dataps, CCHARP_SIZE * i, rffi.cast(rffi.CCHARP, addr))
                 #This assumes we iterate over the whole array (it should be a view...)
@@ -1551,7 +1551,7 @@
             for i in range(len(args_w)):
                 arg_i = args_w[i]
                 assert isinstance(arg_i, W_NDimArray)
-                with arg_i.implementation as storage:
+                with arg_i.get_implementation() as storage:
                     addr = get_storage_as_int(storage, arg_i.get_start())
                 raw_storage_setitem(dataps, CCHARP_SIZE * i, rffi.cast(rffi.CCHARP, addr))
         try:


More information about the pypy-commit mailing list