Commits

David Schneider committed c036361 Merge

merge default

  • Participants
  • Parent commits d8b1b0c, b89a1dc
  • Branches armhf-singlefloat

Comments (0)

Files changed (14)

File pypy/doc/windows.rst

 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

File pypy/module/micronumpy/arrayimpl/concrete.py

             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):

File pypy/module/micronumpy/interp_boxes.py

 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
 
 
 class W_GenericBox(W_Root):
-    _attrs_ = []
+    _attrs_ = ['w_flags']
 
     def descr__new__(space, w_subtype, __args__):
         raise operationerrfmt(space.w_TypeError,
     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")
 
     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,

File pypy/module/micronumpy/interp_dtype.py

     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),

File pypy/module/micronumpy/interp_flagsobj.py

+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),
+)

File pypy/module/micronumpy/interp_numarray.py

 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
 
     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:]
 
     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):
                                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)
         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)
 
         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
         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):
         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),
     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),
     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),

File pypy/module/micronumpy/interp_ufuncs.py

 
 
 W_Ufunc.typedef = TypeDef("ufunc",
-    __module__ = "numpypy",
+    __module__ = "numpy",
 
     __call__ = interp2app(W_Ufunc.descr_call),
     __repr__ = interp2app(W_Ufunc.descr_repr),

File pypy/module/micronumpy/loop.py

                                                 '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:
                                               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()

File pypy/module/micronumpy/test/test_dtypes.py

         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'

File pypy/module/micronumpy/test/test_flagsobj.py

+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

File pypy/module/micronumpy/test/test_numarray.py

         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)
         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)
 
     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))
         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])

File pypy/module/micronumpy/test/test_ufuncs.py

 
         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

File pypy/module/test_lib_pypy/test_grp_extra.py

 
 
 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',
 
     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

File rpython/jit/metainterp/logger.py

         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):