[pypy-commit] pypy refactor-signature: simplify and remove ForcedSignature alltogether

fijal noreply at buildbot.pypy.org
Mon Dec 19 13:37:52 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: refactor-signature
Changeset: r50704:3dbc54249ed3
Date: 2011-12-19 14:37 +0200
http://bitbucket.org/pypy/pypy/changeset/3dbc54249ed3/

Log:	simplify and remove ForcedSignature alltogether

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
@@ -708,10 +708,11 @@
     def descr_debug_repr(self, space):
         return space.wrap(self.find_sig().debug_repr())
 
-    def find_sig(self):
+    def find_sig(self, res_shape=None):
         """ find a correct signature for the array
         """
-        return signature.find_sig(self.create_sig(), self)
+        res_shape = res_shape or self.shape
+        return signature.find_sig(self.create_sig(res_shape), self)
 
 def convert_to_array(space, w_obj):
     if isinstance(w_obj, BaseArray):
@@ -762,7 +763,7 @@
         # so in order to have a consistent API, let it go through.
         pass
 
-    def create_sig(self):
+    def create_sig(self, res_shape):
         return signature.ScalarSignature(self.dtype)
 
 class VirtualArray(BaseArray):
@@ -839,10 +840,11 @@
     def _find_dtype(self):
         return self.res_dtype
 
-    def create_sig(self):
+    def create_sig(self, res_shape):
         if self.forced_result is not None:
-            return signature.ForcedSignature(self.forced_result.dtype)
-        return signature.Call1(self.ufunc, self.name, self.values.create_sig())
+            return signature.ArraySignature(self.forced_result.dtype)
+        return signature.Call1(self.ufunc, self.name,
+                               self.values.create_sig(res_shape))
 
 class Call2(VirtualArray):
     """
@@ -865,12 +867,12 @@
     def _find_size(self):
         return self.size
 
-    def create_sig(self):
+    def create_sig(self, res_shape):
         if self.forced_result is not None:
-            return signature.ForcedSignature(self.forced_result.dtype)
+            return signature.ArraySignature(self.forced_result.dtype)
         return signature.Call2(self.ufunc, self.name, self.calc_dtype,
-                               self.left.create_sig(),
-                               self.right.create_sig())
+                               self.left.create_sig(res_shape),
+                               self.right.create_sig(res_shape))
 
 class ConcreteArray(BaseArray):
     """ An array that have actual storage, whether owned or not
@@ -946,7 +948,7 @@
         self._sliceloop(w_value, res_shape)
 
     def _sliceloop(self, source, res_shape):
-        sig = source.find_sig()
+        sig = source.find_sig(res_shape)
         frame = sig.create_frame(source)
         res_iter = ViewIterator(self)
         shapelen = len(res_shape)
@@ -971,7 +973,7 @@
             a_iter = a_iter.next(len(array.shape))
         return array
 
-    def create_sig(self):
+    def create_sig(self, res_shape):
         return signature.ViewSignature(self.dtype)
 
     def setshape(self, space, new_shape):
@@ -1025,7 +1027,7 @@
         self.shape = new_shape
         self.calc_strides(new_shape)
 
-    def create_sig(self):
+    def create_sig(self, res_shape):
         return signature.ArraySignature(self.dtype)
 
     def __del__(self):
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
@@ -70,7 +70,7 @@
         shapelen = len(obj.shape)
         sig = find_sig(ReduceSignature(self.func, self.name, dtype,
                                        ScalarSignature(dtype),
-                                       obj.create_sig()), obj)
+                                       obj.create_sig(obj.shape)), obj)
         frame = sig.create_frame(obj)
         if shapelen > 1 and not multidim:
             raise OperationError(space.w_NotImplementedError,
diff --git a/pypy/module/micronumpy/signature.py b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -117,53 +117,23 @@
         return 'Array'
 
     def _invent_array_numbering(self, arr, cache):
-        from pypy.module.micronumpy.interp_numarray import ConcreteArray
-        assert isinstance(arr, ConcreteArray)
-        self.array_no = _add_ptr_to_cache(arr.storage, cache)
+        storage = arr.get_concrete().storage
+        self.array_no = _add_ptr_to_cache(storage, cache)
 
     def _create_iter(self, iterlist, arraylist, arr):
-        from pypy.module.micronumpy.interp_numarray import ConcreteArray
-        assert isinstance(arr, ConcreteArray)
+        storage = arr.get_concrete().storage
         if self.iter_no >= len(iterlist):
             iterlist.append(self.allocate_iter(arr))
         if self.array_no >= len(arraylist):
-            arraylist.append(arr.storage)
+            arraylist.append(storage)
 
     def allocate_iter(self, arr):
         return ArrayIterator(arr.size)
 
     def eval(self, frame, arr):
-        from pypy.module.micronumpy.interp_numarray import ConcreteArray
-        assert isinstance(arr, ConcreteArray)
         iter = frame.iterators[self.iter_no]
         return self.dtype.getitem(frame.arrays[self.array_no], iter.offset)
 
-class ForcedSignature(ArraySignature):
-    def debug_repr(self):
-        return 'ForcedArray'
-
-    def _invent_array_numbering(self, arr, cache):
-        from pypy.module.micronumpy.interp_numarray import VirtualArray
-        assert isinstance(arr, VirtualArray)
-        arr = arr.forced_result
-        self.array_no = _add_ptr_to_cache(arr.storage, cache)
-
-    def _create_iter(self, iterlist, arraylist, arr):
-        from pypy.module.micronumpy.interp_numarray import VirtualArray
-        assert isinstance(arr, VirtualArray)
-        arr = arr.forced_result
-        if self.iter_no >= len(iterlist):
-            iterlist.append(ArrayIterator(arr.size))
-        if self.array_no >= len(arraylist):
-            arraylist.append(arr.storage)
-
-    def eval(self, frame, arr):
-        from pypy.module.micronumpy.interp_numarray import VirtualArray
-        assert isinstance(arr, VirtualArray)
-        arr = arr.forced_result
-        iter = frame.iterators[self.iter_no]
-        return self.dtype.getitem(frame.arrays[self.array_no], iter.offset)    
-
 class ScalarSignature(ConcreteSignature):
     def debug_repr(self):
         return 'Scalar'


More information about the pypy-commit mailing list