Author: David Schneider <david.schnei...@picle.org> Branch: armhf-singlefloat Changeset: r68004:c0363615e405 Date: 2013-11-13 11:34 +0100 http://bitbucket.org/pypy/pypy/changeset/c0363615e405/
Log: merge default diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst --- a/pypy/doc/windows.rst +++ b/pypy/doc/windows.rst @@ -118,14 +118,10 @@ The sqlite3 database library ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Download http://www.sqlite.org/2013/sqlite-amalgamation-3071601.zip and extract -it into a directory under the base directory. Also get -http://www.sqlite.org/2013/sqlite-dll-win32-x86-3071601.zip and extract the dll -into the bin directory, and the sqlite3.def into the sources directory. -Now build the import library so cffi can use the header and dll:: +PyPy uses cffi to interact with sqlite3.dll. Only the dll is needed, the cffi +wrapper is compiled when the module is imported for the first time. +The sqlite3.dll should be version 3.6.21 for CPython2.7 compatablility. - lib /DEF:sqlite3.def" /OUT:sqlite3.lib" - copy sqlite3.lib path\to\libs The expat XML parser 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 @@ -73,6 +73,8 @@ return SliceArray(self.start, new_strides, new_backstrides, new_shape, self, orig_array) else: + if self.get_size() == 1 and len(new_shape) == 0: + return scalar.Scalar(self.dtype, self.getitem(0)) return None def get_view(self, orig_array, dtype, new_shape): 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 @@ -11,6 +11,7 @@ from rpython.rtyper.lltypesystem import rffi from rpython.tool.sourcetools import func_with_new_name from pypy.module.micronumpy.arrayimpl.voidbox import VoidBoxStorage +from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject from pypy.interpreter.mixedmodule import MixedModule from rpython.rtyper.lltypesystem import lltype from rpython.rlib.rstring import StringBuilder @@ -113,7 +114,7 @@ class W_GenericBox(W_Root): - _attrs_ = [] + _attrs_ = ['w_flags'] def descr__new__(space, w_subtype, __args__): raise operationerrfmt(space.w_TypeError, @@ -292,6 +293,12 @@ def descr_copy(self, space): return self.convert_to(self.get_dtype(space)) + w_flags = None + def descr_get_flags(self, space): + if self.w_flags is None: + self.w_flags = W_FlagsObject(self) + return self.w_flags + class W_BoolBox(W_GenericBox, PrimitiveBox): descr__new__, _get_dtype, descr_reduce = new_dtype_getter("bool") @@ -550,6 +557,7 @@ strides = GetSetProperty(W_GenericBox.descr_get_shape), ndim = GetSetProperty(W_GenericBox.descr_get_ndim), T = GetSetProperty(W_GenericBox.descr_self), + flags = GetSetProperty(W_GenericBox.descr_get_flags), ) W_BoolBox.typedef = TypeDef("bool_", W_GenericBox.typedef, diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -401,7 +401,7 @@ raise operationerrfmt(space.w_TypeError, msg, w_dtype) W_Dtype.typedef = TypeDef("dtype", - __module__ = "numpypy", + __module__ = "numpy", __new__ = interp2app(descr__new__), __str__= interp2app(W_Dtype.descr_str), diff --git a/pypy/module/micronumpy/interp_flagsobj.py b/pypy/module/micronumpy/interp_flagsobj.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/interp_flagsobj.py @@ -0,0 +1,45 @@ +from pypy.interpreter.baseobjspace import W_Root +from pypy.interpreter.typedef import TypeDef, GetSetProperty +from pypy.interpreter.gateway import interp2app +from pypy.interpreter.error import OperationError + + +class W_FlagsObject(W_Root): + def __init__(self, arr): + self.arr = arr + + def descr_get_contiguous(self, space): + return space.w_True + + def descr_get_fortran(self, space): + return space.w_False + + def descr_get_writeable(self, space): + return space.w_True + + def descr_getitem(self, space, w_item): + key = space.str_w(w_item) + if key == "C" or key == "CONTIGUOUS" or key == "C_CONTIGUOUS": + return self.descr_get_contiguous(space) + if key == "F" or key == "FORTRAN" or key == "F_CONTIGUOUS": + return self.descr_get_fortran(space) + if key == "W" or key == "WRITEABLE": + return self.descr_get_writeable(space) + raise OperationError(space.w_KeyError, space.wrap( + "Unknown flag")) + + def descr_setitem(self, space, w_item, w_value): + raise OperationError(space.w_KeyError, space.wrap( + "Unknown flag")) + +W_FlagsObject.typedef = TypeDef("flagsobj", + __module__ = "numpy", + __getitem__ = interp2app(W_FlagsObject.descr_getitem), + __setitem__ = interp2app(W_FlagsObject.descr_setitem), + + contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous), + c_contiguous = GetSetProperty(W_FlagsObject.descr_get_contiguous), + f_contiguous = GetSetProperty(W_FlagsObject.descr_get_fortran), + fortran = GetSetProperty(W_FlagsObject.descr_get_fortran), + writeable = GetSetProperty(W_FlagsObject.descr_get_writeable), +) 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 @@ -9,6 +9,7 @@ from pypy.module.micronumpy.strides import find_shape_and_elems,\ get_shape_from_iterable, to_coords, shape_agreement, \ shape_agreement_multiple +from pypy.module.micronumpy.interp_flagsobj import W_FlagsObject from pypy.module.micronumpy.interp_flatiter import W_FlatIterator from pypy.module.micronumpy.appbridge import get_appbridge_cache from pypy.module.micronumpy import loop @@ -97,11 +98,11 @@ def getitem_filter(self, space, arr): if len(arr.get_shape()) > 1 and arr.get_shape() != self.get_shape(): - raise OperationError(space.w_ValueError, - space.wrap("boolean index array should have 1 dimension")) + raise OperationError(space.w_ValueError, space.wrap( + "boolean index array should have 1 dimension")) if arr.get_size() > self.get_size(): - raise OperationError(space.w_ValueError, - space.wrap("index out of range for array")) + raise OperationError(space.w_ValueError, space.wrap( + "index out of range for array")) size = loop.count_all_true(arr) if len(arr.get_shape()) == 1: res_shape = [size] + self.get_shape()[1:] @@ -112,18 +113,19 @@ def setitem_filter(self, space, idx, val): if len(idx.get_shape()) > 1 and idx.get_shape() != self.get_shape(): - raise OperationError(space.w_ValueError, - space.wrap("boolean index array should have 1 dimension")) + raise OperationError(space.w_ValueError, space.wrap( + "boolean index array should have 1 dimension")) if idx.get_size() > self.get_size(): - raise OperationError(space.w_ValueError, - space.wrap("index out of range for array")) + raise OperationError(space.w_ValueError, space.wrap( + "index out of range for array")) size = loop.count_all_true(idx) if size > val.get_size() and val.get_size() != 1: - raise OperationError(space.w_ValueError, space.wrap("NumPy boolean array indexing assignment " - "cannot assign %d input values to " - "the %d output values where the mask is true" % - (val.get_size(), size))) - loop.setitem_filter(self, idx, val, size) + raise OperationError(space.w_ValueError, space.wrap( + "NumPy boolean array indexing assignment " + "cannot assign %d input values to " + "the %d output values where the mask is true" % + (val.get_size(), size))) + loop.setitem_filter(space, self, idx, val, size) def _prepare_array_index(self, space, w_index): if isinstance(w_index, W_NDimArray): @@ -196,8 +198,7 @@ prefix) def descr_getitem(self, space, w_idx): - if (isinstance(w_idx, W_NDimArray) and - w_idx.get_dtype().is_bool_type()): + if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type(): return self.getitem_filter(space, w_idx) try: return self.implementation.descr_getitem(space, self, w_idx) @@ -211,9 +212,11 @@ self.implementation.setitem_index(space, index_list, w_value) def descr_setitem(self, space, w_idx, w_value): - if (isinstance(w_idx, W_NDimArray) and - w_idx.get_dtype().is_bool_type()): - self.setitem_filter(space, w_idx, convert_to_array(space, w_value)) + if isinstance(w_idx, W_NDimArray) and w_idx.get_dtype().is_bool_type(): + try: + self.setitem_filter(space, w_idx, convert_to_array(space, w_value)) + except ValueError, e: + raise OperationError(space.w_ValueError, space.wrap(str(e))) return try: self.implementation.descr_setitem(space, self, w_idx, w_value) @@ -338,11 +341,11 @@ Returns an array containing the same data with a new shape. - Refer to `numpypy.reshape` for full documentation. + Refer to `numpy.reshape` for full documentation. See Also -------- - numpypy.reshape : equivalent function + numpy.reshape : equivalent function """ args_w, kw_w = __args__.unpack() order = NPY_CORDER @@ -610,13 +613,11 @@ raise OperationError(space.w_NotImplementedError, space.wrap( "dumps not implemented yet")) + w_flags = None def descr_get_flags(self, space): - raise OperationError(space.w_NotImplementedError, space.wrap( - "getting flags not implemented yet")) - - def descr_set_flags(self, space, w_args): - raise OperationError(space.w_NotImplementedError, space.wrap( - "setting flags not implemented yet")) + if self.w_flags is None: + self.w_flags = W_FlagsObject(self) + return self.w_flags @unwrap_spec(offset=int) def descr_getfield(self, space, w_dtype, offset): @@ -1123,9 +1124,8 @@ return res """, filename=__file__).interphook('ptp') -W_NDimArray.typedef = TypeDef( - "ndarray", - __module__ = "numpypy", +W_NDimArray.typedef = TypeDef("ndarray", + __module__ = "numpy", __new__ = interp2app(descr_new_array), __len__ = interp2app(W_NDimArray.descr_len), @@ -1204,6 +1204,7 @@ size = GetSetProperty(W_NDimArray.descr_get_size), itemsize = GetSetProperty(W_NDimArray.descr_get_itemsize), nbytes = GetSetProperty(W_NDimArray.descr_get_nbytes), + flags = GetSetProperty(W_NDimArray.descr_get_flags), fill = interp2app(W_NDimArray.descr_fill), tostring = interp2app(W_NDimArray.descr_tostring), @@ -1391,8 +1392,8 @@ return box -W_FlatIterator.typedef = TypeDef( - 'flatiter', +W_FlatIterator.typedef = TypeDef("flatiter", + __module__ = "numpy", __iter__ = interp2app(W_FlatIterator.descr_iter), __getitem__ = interp2app(W_FlatIterator.descr_getitem), __setitem__ = interp2app(W_FlatIterator.descr_setitem), 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 @@ -413,7 +413,7 @@ W_Ufunc.typedef = TypeDef("ufunc", - __module__ = "numpypy", + __module__ = "numpy", __call__ = interp2app(W_Ufunc.descr_call), __repr__ = interp2app(W_Ufunc.descr_repr), 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 @@ -398,7 +398,7 @@ 'index_dtype'], reds = 'auto') -def setitem_filter(arr, index, value, size): +def setitem_filter(space, arr, index, value, size): arr_iter = arr.create_iter() shapelen = len(arr.get_shape()) if shapelen > 1 and len(index.get_shape()) < 2: @@ -414,7 +414,7 @@ arr_dtype=arr_dtype, ) if index_iter.getitem_bool(): - arr_iter.setitem(value_iter.getitem()) + arr_iter.setitem(arr_dtype.coerce(space, value_iter.getitem())) value_iter.next() arr_iter.next() index_iter.next() 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 @@ -26,6 +26,7 @@ assert d.kind == 'b' assert dtype(d) is d assert dtype('bool') is d + assert repr(type(d)) == "<type 'numpy.dtype'>" assert dtype('int8').num == 1 assert dtype('int8').name == 'int8' diff --git a/pypy/module/micronumpy/test/test_flagsobj.py b/pypy/module/micronumpy/test/test_flagsobj.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/test/test_flagsobj.py @@ -0,0 +1,22 @@ +from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest + + +class AppTestFlagsObj(BaseNumpyAppTest): + def test_repr(self): + import numpy as np + a = np.array([1,2,3]) + assert repr(type(a.flags)) == "<type 'numpy.flagsobj'>" + + def test_array_flags(self): + import numpy as np + a = np.array([1,2,3]) + assert a.flags.c_contiguous == True + assert a.flags['W'] == True + raises(KeyError, "a.flags['blah']") + raises(KeyError, "a.flags['C_CONTIGUOUS'] = False") + raises((TypeError, AttributeError), "a.flags.c_contiguous = False") + + def test_scalar_flags(self): + import numpy as np + a = np.int32(2) + assert a.flags.c_contiguous == True 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 @@ -249,9 +249,11 @@ return CustomIntObject(value) def test_ndarray(self): - from numpypy import ndarray, array, dtype + from numpy import ndarray, array, dtype, flatiter assert type(ndarray) is type + assert repr(ndarray) == "<type 'numpy.ndarray'>" + assert repr(flatiter) == "<type 'numpy.flatiter'>" assert type(array) is not type a = ndarray((2, 3)) assert a.shape == (2, 3) @@ -509,6 +511,13 @@ for i in xrange(5): assert a[i] == i + def test_setitem_array(self): + import numpy as np + a = np.array((-1., 0, 1))/0. + b = np.array([False, False, True], dtype=bool) + a[b] = 100 + assert a[2] == 100 + def test_setitem_obj_index(self): from numpypy import arange a = arange(10) @@ -701,7 +710,14 @@ def test_reshape(self): from numpypy import array, zeros + for a in [array(1), array([1])]: + for s in [(), (1,)]: + b = a.reshape(s) + assert b.shape == s + assert (b == [1]).all() a = array(range(12)) + exc = raises(ValueError, "b = a.reshape(())") + assert str(exc.value) == "total size of new array must be unchanged" exc = raises(ValueError, "b = a.reshape((3, 10))") assert str(exc.value) == "total size of new array must be unchanged" b = a.reshape((3, 4)) @@ -2445,6 +2461,23 @@ assert exc.value[0].find('cannot assign') >= 0 assert (a == [[0, 1], [2, 3], [4, 5]]).all() + def test_nonarray_assignment(self): + import numpypy as np + a = np.arange(10) + b = np.ones(10, dtype=bool) + r = np.arange(10) + def assign(a, b, c): + a[b] = c + raises(ValueError, assign, a, b, np.nan) + #raises(ValueError, assign, a, r, np.nan) # XXX + import sys + if '__pypy__' not in sys.builtin_module_names: + a[b] = np.array(np.nan) + #a[r] = np.array(np.nan) + else: + raises(ValueError, assign, a, b, np.array(np.nan)) + #raises(ValueError, assign, a, r, np.array(np.nan)) + def test_copy_kwarg(self): from numpypy import array x = array([1, 2, 3]) diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py --- a/pypy/module/micronumpy/test/test_ufuncs.py +++ b/pypy/module/micronumpy/test/test_ufuncs.py @@ -81,7 +81,7 @@ assert isinstance(add, ufunc) assert repr(add) == "<ufunc 'add'>" - assert repr(ufunc) == "<type 'numpypy.ufunc'>" or repr(ufunc) == "<type 'numpy.ufunc'>" + assert repr(ufunc) == "<type 'numpy.ufunc'>" def test_ufunc_attrs(self): from numpypy import add, multiply, sin diff --git a/pypy/module/test_lib_pypy/test_grp_extra.py b/pypy/module/test_lib_pypy/test_grp_extra.py --- a/pypy/module/test_lib_pypy/test_grp_extra.py +++ b/pypy/module/test_lib_pypy/test_grp_extra.py @@ -2,8 +2,7 @@ class AppTestGrp: - - spaceconfig = dict(usemodules=('_ffi', '_rawffi', 'itertools')) + spaceconfig = dict(usemodules=('binascii', '_ffi', '_rawffi', 'itertools')) def setup_class(cls): cls.w_grp = import_lib_pypy(cls.space, 'grp', @@ -11,14 +10,18 @@ def test_basic(self): raises(KeyError, self.grp.getgrnam, "dEkLofcG") - try: - g = self.grp.getgrnam("root") - except KeyError: - return # no 'root' group on OS/X? - assert g.gr_gid == 0 - assert g.gr_mem == ['root'] or g.gr_mem == [] - assert g.gr_name == 'root' - assert isinstance(g.gr_passwd, str) # usually just 'x', don't hope :-) + for name in ["root", "wheel"]: + try: + g = self.grp.getgrnam(name) + except KeyError: + continue + assert g.gr_gid == 0 + assert g.gr_mem == ['root'] or g.gr_mem == [] + assert g.gr_name == name + assert isinstance(g.gr_passwd, str) # usually just 'x', don't hope :-) + break + else: + raise def test_extra(self): grp = self.grp diff --git a/rpython/jit/metainterp/logger.py b/rpython/jit/metainterp/logger.py --- a/rpython/jit/metainterp/logger.py +++ b/rpython/jit/metainterp/logger.py @@ -103,7 +103,9 @@ elif isinstance(arg, BoxInt): return 'i' + str(mv) elif isinstance(arg, self.ts.ConstRef): - return 'ConstPtr(ptr' + str(mv) + ')' + if arg.value: + return 'ConstPtr(ptr' + str(mv) + ')' + return 'ConstPtr(null)' elif isinstance(arg, self.ts.BoxRef): return 'p' + str(mv) elif isinstance(arg, ConstFloat): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit