[pypy-svn] pypy numpy-exp: A bit more rpythonic

fijal commits-noreply at bitbucket.org
Fri Feb 11 09:34:48 CET 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-exp
Changeset: r41809:6b18ac4a698f
Date: 2011-02-09 21:47 +0200
http://bitbucket.org/pypy/pypy/changeset/6b18ac4a698f/

Log:	A bit more rpythonic

diff --git a/pypy/module/micronumpy/numarray.py b/pypy/module/micronumpy/numarray.py
--- a/pypy/module/micronumpy/numarray.py
+++ b/pypy/module/micronumpy/numarray.py
@@ -54,6 +54,7 @@
                 raise NotImplementedError
             bytecode_pos -= 1
     return result
+
     
 class BaseArray(Wrappable):
     def force(self):
@@ -61,11 +62,17 @@
         return compute(bytecode, stack)
     force.unwrap_spec = ['self']
 
+    def descr_add(self, space, w_other):
+        return space.wrap(Add(self, w_other))
+    descr_add.unwrap_spec = ['self', ObjSpace, W_Root]
+
     def compile(self):
         raise NotImplementedError("abstract base class")
 
 class Add(BaseArray):
     def __init__(self, left, right):
+        assert isinstance(left, BaseArray)
+        assert isinstance(right, BaseArray)
         self.left = left
         self.right = right
 
@@ -77,6 +84,7 @@
 BaseArray.typedef = TypeDef(
     'Operation',
     force=interp2app(BaseArray.force),
+    __add__ = interp2app(BaseArray.descr_add),
 )
 
 class SingleDimArray(BaseArray):
@@ -107,10 +115,6 @@
         self.storage[item] = value
     descr_setitem.unwrap_spec = ['self', ObjSpace, int, float]
 
-    def descr_add(self, space, w_other):
-        return space.wrap(Add(self, w_other))
-    descr_add.unwrap_spec = ['self', ObjSpace, W_Root]
-
     def force(self):
         return self
 
@@ -132,7 +136,7 @@
     __new__ = interp2app(descr_new_numarray),
     __getitem__ = interp2app(SingleDimArray.descr_getitem),
     __setitem__ = interp2app(SingleDimArray.descr_setitem),
-    __add__ = interp2app(SingleDimArray.descr_add),
+    __add__ = interp2app(BaseArray.descr_add),
     force = interp2app(SingleDimArray.force),
 )
 


More information about the Pypy-commit mailing list