Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r50272:3d44c9c53444 Date: 2011-12-07 17:39 +0100 http://bitbucket.org/pypy/pypy/changeset/3d44c9c53444/
Log: merge heads 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 @@ -916,6 +916,15 @@ def descr_debug_repr(self, space): return space.wrap(self.debug_repr()) + def descr_array_iface(self, space): + concrete = self.get_concrete() + storage = concrete.get_storage(space) + addr = rffi.cast(lltype.Signed, storage) + w_d = space.newdict() + space.setitem_str(w_d, 'data', space.newtuple([space.wrap(addr), + space.w_False])) + return w_d + def convert_to_array(space, w_obj): if isinstance(w_obj, BaseArray): return w_obj @@ -976,6 +985,9 @@ # so in order to have a consistent API, let it go through. pass + def get_storage(self, space): + raise OperationError(space.w_TypeError, space.wrap("Cannot get array interface on scalars in pypy")) + class VirtualArray(BaseArray): """ Class for representing virtual arrays, such as binary ops or ufuncs @@ -1263,6 +1275,9 @@ a_iter = a_iter.next(len(array.shape)) return array + def get_storage(self, space): + return self.parent.get_storage(space) + class W_NDimArray(BaseArray): """ A class representing contiguous array. We know that each iteration by say ufunc will increase the data index by one @@ -1325,6 +1340,9 @@ def debug_repr(self): return 'Array' + def get_storage(self, space): + return self.storage + def __del__(self): lltype.free(self.storage, flavor='raw', track_allocation=False) @@ -1444,6 +1462,7 @@ __repr__ = interp2app(BaseArray.descr_repr), __str__ = interp2app(BaseArray.descr_str), __debug_repr__ = interp2app(BaseArray.descr_debug_repr), + __array_interface__ = GetSetProperty(BaseArray.descr_array_iface), dtype = GetSetProperty(BaseArray.descr_get_dtype), shape = GetSetProperty(BaseArray.descr_get_shape, 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 @@ -1114,6 +1114,16 @@ b = a[0].copy() assert (b == zeros(10)).all() + def test_array_interface(self): + from numpypy import array + a = array([1, 2, 3]) + i = a.__array_interface__ + assert isinstance(i['data'][0], int) + a = a[::2] + i = a.__array_interface__ + assert isinstance(i['data'][0], int) + raises(TypeError, getattr, array(3), '__array_interface__') + class AppTestSupport(BaseNumpyAppTest): def setup_class(cls): import struct diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py --- a/pypy/rlib/rmmap.py +++ b/pypy/rlib/rmmap.py @@ -420,7 +420,11 @@ low, high = _get_file_size(self.file_handle) if not high and low <= sys.maxint: return low + # not so sure if the signed/unsigned strictness is a good idea: + high = rffi.cast(lltype.Unsigned, high) + low = rffi.cast(lltype.Unsigned, low) size = (high << 32) + low + size = rffi.cast(lltype.Signed, size) elif _POSIX: st = os.fstat(self.fd) size = st[stat.ST_SIZE] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit