[pypy-commit] pypy numpy-refactor: pass 3 more tests

fijal noreply at buildbot.pypy.org
Fri Sep 7 17:21:08 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57219:a55df0b30e4b
Date: 2012-09-07 16:53 +0200
http://bitbucket.org/pypy/pypy/changeset/a55df0b30e4b/

Log:	pass 3 more tests

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -6,6 +6,7 @@
      calculate_broadcast_strides, calculate_dot_strides
 from pypy.module.micronumpy.iter import Chunk, Chunks, NewAxisChunk, RecordChunk
 from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.rlib import jit
 from pypy.rlib.rawstorage import free_raw_storage
 
@@ -336,6 +337,9 @@
         return W_NDimArray.new_slice(self.start, strides, 
                                      backstrides, shape, self)
 
+    def get_storage_as_int(self, space):
+        return rffi.cast(lltype.Signed, self.storage)
+
 class ConcreteArray(BaseConcreteArray):
     def __init__(self, shape, dtype, order, strides, backstrides):
         self.shape = shape
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
@@ -81,3 +81,10 @@
 
     def swapaxes(self, axis1, axis2):
         return self
+
+    def fill(self, w_value):
+        self.value = w_value
+
+    def get_storage_as_int(self, space):
+        raise OperationError(space.w_ValueError,
+                             space.wrap("scalars have no address"))
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
@@ -55,6 +55,9 @@
     def descr_get_nbytes(self, space):
         return space.wrap(self.get_size() * self.get_dtype().itemtype.get_element_size())
 
+    def descr_fill(self, space, w_value):
+        self.fill(self.get_dtype().coerce(space, w_value))
+
     def getitem_filter(self, space, arr):
         if arr.get_size() > self.get_size():
             raise OperationError(space.w_IndexError,
@@ -224,6 +227,15 @@
     def descr_get_flatiter(self, space):
         return space.wrap(W_FlatIterator(self))
 
+    def descr_array_iface(self, space):
+        addr = self.implementation.get_storage_as_int(space)
+        # will explode if it can't
+        w_d = space.newdict()
+        space.setitem_str(w_d, 'data', space.newtuple([space.wrap(addr),
+                                                       space.w_False]))
+        return w_d
+
+
     # --------------------- operations ----------------------------
 
     def _unaryop_impl(ufunc_name):
@@ -452,6 +464,7 @@
     size = GetSetProperty(W_NDimArray.descr_get_size),
     itemsize = GetSetProperty(W_NDimArray.descr_get_itemsize),
     nbytes = GetSetProperty(W_NDimArray.descr_get_nbytes),
+    fill = interp2app(W_NDimArray.descr_fill),
 
     mean = interp2app(W_NDimArray.descr_mean),
     sum = interp2app(W_NDimArray.descr_sum),
@@ -476,6 +489,8 @@
     repeat = interp2app(W_NDimArray.descr_repeat),
     swapaxes = interp2app(W_NDimArray.descr_swapaxes),
     flat = GetSetProperty(W_NDimArray.descr_get_flatiter),
+
+    __array_interface__ = GetSetProperty(W_NDimArray.descr_array_iface),
 )
 
 @unwrap_spec(ndmin=int, copy=bool, subok=bool)


More information about the pypy-commit mailing list