Author: mattip <matti.pi...@gmail.com>
Branch: missing-ndarray-attributes
Changeset: r59935:81224797e9f1
Date: 2013-01-11 00:02 +0200
http://bitbucket.org/pypy/pypy/changeset/81224797e9f1/

Log:    progress towards translation

diff --git a/pypy/module/micronumpy/arrayimpl/base.py 
b/pypy/module/micronumpy/arrayimpl/base.py
--- a/pypy/module/micronumpy/arrayimpl/base.py
+++ b/pypy/module/micronumpy/arrayimpl/base.py
@@ -3,6 +3,12 @@
     def is_scalar(self):
         return False
 
+    def base(self):
+        raise NotImplementedError
+
+    def create_iter(self, shape=None):
+        raise NotImplementedError
+
 class BaseArrayIterator(object):
     def next(self):
         raise NotImplementedError # purely abstract base class
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py 
b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -86,7 +86,7 @@
     def create_axis_iter(self, shape, dim, cum):
         raise Exception("axis iter should not happen on scalar")
 
-    def swapaxes(self, axis1, axis2):
+    def swapaxes(self, orig_array, axis1, axis2):
         raise Exception("should not be called")
 
     def fill(self, w_value):
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
@@ -2,6 +2,7 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.tool.pairtype import extendabletype
 from pypy.module.micronumpy.support import calc_strides
+from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation
 
 def issequence_w(space, w_obj):
     return (space.isinstance_w(w_obj, space.w_tuple) or
@@ -15,6 +16,7 @@
     __metaclass__ = extendabletype
 
     def __init__(self, implementation):
+        assert isinstance(implementation, BaseArrayImplementation)
         self.implementation = implementation
     
     @staticmethod
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
@@ -9,6 +9,7 @@
     like a real array for descr_eq and friends
     """
     def __init__(self, base):
+        assert isinstance(base, BaseArrayImplementation)
         self.base = base
         self.dtype = base.get_dtype()
         self.shape = [base.get_size()]
@@ -17,6 +18,7 @@
         return self.shape
 
     def create_iter(self, shape=None):
+        assert isinstance(self.base, BaseArrayImplementation)
         return self.base.create_iter()
 
 class W_FlatIterator(W_NDimArray):
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
@@ -18,6 +18,7 @@
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib import jit
 from pypy.rlib.rstring import StringBuilder
+from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation
 
 def _find_shape(space, w_size):
     if space.is_none(w_size):
@@ -208,6 +209,7 @@
         return s.build()
 
     def create_iter(self, shape=None):
+        assert isinstance(self.implementation, BaseArrayImplementation)
         return self.implementation.create_iter(shape)
 
     def create_axis_iter(self, shape, dim, cum):
@@ -414,7 +416,11 @@
         return self.implementation.astype(space, dtype)
 
     def descr_get_base(self, space):
-        return self.implementation.base()
+        impl = self.implementation
+        ret = impl.base()
+        if ret is None:
+            return space.w_None
+        return ret    
 
     @unwrap_spec(inplace=bool)
     def descr_byteswap(self, space, inplace=False):
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
@@ -602,17 +602,27 @@
 def diagonal_array(space, arr, out, offset, axis1, axis2, shape):
     out_iter = out.create_iter()
     iter = PureShapeIterator(shape, [])
-    shapelen = len(shape)
+    shapelen_minus_1 = len(shape) - 1
+    assert shapelen_minus_1 >= 0
+    if axis1 < axis2:
+        a = axis1
+        b = axis2 - 1
+    else:
+        a = axis2
+        b = axis1 - 1
+    assert a >= 0
+    assert b >= 0
     while not iter.done():
         last_index = iter.indexes[-1]
         if axis1 < axis2:
-            indexes = (iter.indexes[:axis1] + [last_index] +
-                       iter.indexes[axis1:axis2 - 1] + [last_index + offset] +
-                       iter.indexes[axis2 - 1:shapelen - 1])
+            indexes = (iter.indexes[:a] + [last_index] +
+                       iter.indexes[a:b] + [last_index + offset] +
+                       iter.indexes[b:shapelen_minus_1])
         else:
-            indexes = (iter.indexes[:axis2] + [last_index + offset] +
-                       iter.indexes[axis2:axis1 - 1] + [last_index] +
-                       iter.indexes[axis1 - 1:shapelen - 1])
+            indexes = (iter.indexes[:a] + [last_index + offset] +
+                       iter.indexes[a:b] + [last_index] +
+                       iter.indexes[b:shapelen_minus_1])
         out_iter.setitem(arr.getitem_index(space, indexes))
         iter.next()
         out_iter.next()
+       
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to