[pypy-commit] pypy numpy-refactor: fix some more tests

fijal noreply at buildbot.pypy.org
Fri Sep 7 18:42:34 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57226:10caf3ac720e
Date: 2012-09-07 18:42 +0200
http://bitbucket.org/pypy/pypy/changeset/10caf3ac720e/

Log:	fix some more tests

diff --git a/pypy/module/micronumpy/arrayimpl/voidbox.py b/pypy/module/micronumpy/arrayimpl/voidbox.py
--- a/pypy/module/micronumpy/arrayimpl/voidbox.py
+++ b/pypy/module/micronumpy/arrayimpl/voidbox.py
@@ -3,8 +3,9 @@
 from pypy.rlib.rawstorage import free_raw_storage, alloc_raw_storage
 
 class VoidBoxStorage(BaseArrayImplementation):
-    def __init__(self, size):
+    def __init__(self, size, dtype):
         self.storage = alloc_raw_storage(size)
+        self.dtype = dtype
 
     def __del__(self):
         free_raw_storage(self.storage)
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -8,7 +8,7 @@
 from pypy.objspace.std.inttype import int_typedef
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
-from pypy.module.micronumpy.base import W_NDimArray
+from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage
 
 MIXIN_32 = (int_typedef,) if LONG_BIT == 32 else ()
 MIXIN_64 = (int_typedef,) if LONG_BIT == 64 else ()
@@ -250,7 +250,7 @@
         from pypy.module.micronumpy.interp_dtype import new_string_dtype
 
         arg = space.str_w(space.str(w_arg))
-        arr = W_NDimArray.from_shape([1], new_string_dtype(space, len(arg)))
+        arr = VoidBoxStorage(len(arg), new_string_dtype(space, len(arg)))
         for i in range(len(arg)):
             arr.storage[i] = arg[i]
         return W_StringBox(arr, 0, arr.dtype)
@@ -261,7 +261,8 @@
         from pypy.module.micronumpy.interp_dtype import new_unicode_dtype
 
         arg = space.unicode_w(unicode_from_object(space, w_arg))
-        arr = W_NDimArray.from_shape([1], new_unicode_dtype(space, len(arg)))
+        # XXX size computations, we need tests anyway
+        arr = VoidBoxStorage(len(arg), new_unicode_dtype(space, len(arg)))
         # XXX not this way, we need store
         #for i in range(len(arg)):
         #    arr.storage[i] = arg[i]
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
@@ -240,7 +240,7 @@
             if not isinstance(out, W_NDimArray):
                 raise OperationError(space.w_TypeError, space.wrap(
                                                 'output must be an array'))
-            res_dtype = out.find_dtype()
+            res_dtype = out.get_dtype()
         elif self.bool_result:
             res_dtype = interp_dtype.get_dtype_cache(space).w_booldtype
         else:
@@ -253,7 +253,7 @@
             if out.is_scalar():
                 out.set_scalar_value(w_val)
             else:
-                out.fill(space, w_val)
+                out.fill(res_dtype.coerce(space, w_val))
             return out
         shape =  shape_agreement(space, w_obj.get_shape(), out)
         return loop.call1(shape, self.func, self.name, calc_dtype, res_dtype,
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -576,14 +576,16 @@
     def setup_class(cls):
         BaseNumpyAppTest.setup_class.im_func(cls)
         def check_non_native(w_obj, w_obj2):
-            assert w_obj.storage[0] == w_obj2.storage[1]
-            assert w_obj.storage[1] == w_obj2.storage[0]
-            if w_obj.storage[0] == '\x00':
-                assert w_obj2.storage[1] == '\x00'
-                assert w_obj2.storage[0] == '\x01'
+            stor1 = w_obj.implementation.storage
+            stor2 = w_obj2.implementation.storage
+            assert stor1[0] == stor2[1]
+            assert stor1[1] == stor2[0]
+            if stor1[0] == '\x00':
+                assert stor2[1] == '\x00'
+                assert stor2[0] == '\x01'
             else:
-                assert w_obj2.storage[1] == '\x01'
-                assert w_obj2.storage[0] == '\x00'
+                assert stor2[1] == '\x01'
+                assert stor2[0] == '\x00'
         cls.w_check_non_native = cls.space.wrap(interp2app(check_non_native))
         if option.runappdirect:
             py.test.skip("not a direct test")
@@ -599,7 +601,7 @@
     def setup_class(cls):
         if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
             py.test.skip("pypy only test")
-        BaseNumpyAppTest.setup_class(cls)
+        BaseNumpyAppTest.setup_class.im_func(cls)
 
     def test_typeinfo(self):
         from _numpypy import typeinfo, void, number, int64, bool_
diff --git a/pypy/module/micronumpy/test/test_iter.py b/pypy/module/micronumpy/test/test_iter.py
--- a/pypy/module/micronumpy/test/test_iter.py
+++ b/pypy/module/micronumpy/test/test_iter.py
@@ -1,5 +1,8 @@
 from pypy.module.micronumpy.arrayimpl.concrete import MultiDimViewIterator
 
+class MockArray(object):
+    size = 1
+
 class TestIterDirect(object):
     def test_C_viewiterator(self):
         #Let's get started, simple iteration in C order with
@@ -9,7 +12,7 @@
         strides = [5, 1]
         backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
         assert backstrides == [10, 4]
-        i = MultiDimViewIterator(None, start, strides, backstrides, shape)
+        i = MultiDimViewIterator(MockArray, start, strides, backstrides, shape)
         i.next()
         i.next()
         i.next()
@@ -27,7 +30,7 @@
         strides = [1, 3]
         backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
         assert backstrides == [2, 12]
-        i = MultiDimViewIterator(None, start, strides, backstrides, shape)
+        i = MultiDimViewIterator(MockArray, start, strides, backstrides, shape)
         i.next()
         i.next()
         i.next()
@@ -48,7 +51,7 @@
         strides = [5, 1]
         backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
         assert backstrides == [10, 4]
-        i = MultiDimViewIterator(None, start, strides, backstrides, shape)
+        i = MultiDimViewIterator(MockArray, start, strides, backstrides, shape)
         i.next_skip_x(2)
         i.next_skip_x(2)
         i.next_skip_x(2)
@@ -71,7 +74,7 @@
         strides = [1, 3]
         backstrides = [x * (y - 1) for x,y in zip(strides, shape)]
         assert backstrides == [2, 12]
-        i = MultiDimViewIterator(None, start, strides, backstrides, shape)
+        i = MultiDimViewIterator(MockArray, start, strides, backstrides, shape)
         i.next_skip_x(2)
         i.next_skip_x(2)
         i.next_skip_x(2)
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -2222,23 +2222,8 @@
     def setup_class(cls):
         if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
             py.test.skip("pypy only test")
-        BaseNumpyAppTest.setup_class(cls)
+        BaseNumpyAppTest.setup_class.im_func(cls)
     
-    def test_debug_repr(self):
-        from _numpypy import zeros, sin
-        from _numpypy.pypy import debug_repr
-        a = zeros(1)
-        assert debug_repr(a) == 'Array'
-        assert debug_repr(a + a) == 'Call2(add, Array, Array)'
-        assert debug_repr(a[::2]) == 'Slice'
-        assert debug_repr(a + 2) == 'Call2(add, Array, Scalar)'
-        assert debug_repr(a + a.flat) == 'Call2(add, Array, Flat)'
-        assert debug_repr(sin(a)) == 'Call1(sin, Array)'
-
-        b = a + a
-        b[0] = 3
-        assert debug_repr(b) == 'Array'
-
     def test_init_2(self):
         # this test is pypy only since in numpy it becomes an object dtype
         import _numpypy
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -943,7 +943,7 @@
             raise OperationError(space.w_ValueError, space.wrap(
                 "wrong length"))
         items_w = space.fixedview(w_item)
-        arr = VoidBoxStorage(self.size)
+        arr = VoidBoxStorage(self.size, dtype)
         for i in range(len(items_w)):
             subdtype = dtype.fields[dtype.fieldnames[i]][1]
             ofs, itemtype = self.offsets_and_fields[i]


More information about the pypy-commit mailing list