Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r69946:25f71fd3b631 Date: 2014-03-13 21:12 -0700 http://bitbucket.org/pypy/pypy/changeset/25f71fd3b631/
Log: merge default diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py --- a/_pytest/resultlog.py +++ b/_pytest/resultlog.py @@ -51,16 +51,22 @@ self.config = config self.logfile = logfile # preferably line buffered - def write_log_entry(self, testpath, lettercode, longrepr): + def write_log_entry(self, testpath, lettercode, longrepr, sections=[]): py.builtin.print_("%s %s" % (lettercode, testpath), file=self.logfile) for line in longrepr.splitlines(): py.builtin.print_(" %s" % line, file=self.logfile) + for key, text in sections: + py.builtin.print_(" ", file=self.logfile) + py.builtin.print_(" -------------------- %s --------------------" + % key.rstrip(), file=self.logfile) + py.builtin.print_(" %s" % (text.rstrip().replace('\n', '\n '),), + file=self.logfile) def log_outcome(self, report, lettercode, longrepr): testpath = getattr(report, 'nodeid', None) if testpath is None: testpath = report.fspath - self.write_log_entry(testpath, lettercode, longrepr) + self.write_log_entry(testpath, lettercode, longrepr, report.sections) def pytest_runtest_logreport(self, report): if report.when != "call" and report.passed: diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst --- a/pypy/doc/faq.rst +++ b/pypy/doc/faq.rst @@ -187,7 +187,7 @@ No, we found no way of doing that. The JIT generates machine code containing a large number of constant addresses --- constant at the time -the machine code is written. The vast majority is probably not at all +the machine code is generated. The vast majority is probably not at all constants that you find in the executable, with a nice link name. E.g. the addresses of Python classes are used all the time, but Python classes don't come statically from the executable; they are created anew @@ -212,12 +212,16 @@ garbage collection, implementation of various things like arbitrarily long integers, etc. -Currently, we have preliminary versions of a JavaScript interpreter -(Leonardo Santagada as his Summer of PyPy project), a `Prolog interpreter`_ -(Carl Friedrich Bolz as his Bachelor thesis), and a `SmallTalk interpreter`_ +Currently, we have `Topaz`_, a Ruby interpreter; `Hippy`_, a PHP +interpreter; preliminary versions of a `JavaScript interpreter`_ +(Leonardo Santagada as his Summer of PyPy project); a `Prolog interpreter`_ +(Carl Friedrich Bolz as his Bachelor thesis); and a `SmallTalk interpreter`_ (produced during a sprint). On the `PyPy bitbucket page`_ there is also a Scheme and an Io implementation; both of these are unfinished at the moment. +.. _`Topaz`: http://topazruby.com/ +.. _`Hippy`: http://morepypy.blogspot.ch/2012/07/hello-everyone.html +.. _`JavaScript interpreter`: https://bitbucket.org/pypy/lang-js/ .. _`Prolog interpreter`: https://bitbucket.org/cfbolz/pyrolog/ .. _`SmallTalk interpreter`: http://dx.doi.org/10.1007/978-3-540-89275-5_7 .. _`PyPy bitbucket page`: https://bitbucket.org/pypy/ diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py --- a/pypy/module/micronumpy/__init__.py +++ b/pypy/module/micronumpy/__init__.py @@ -24,7 +24,7 @@ 'set_string_function': 'appbridge.set_string_function', 'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo', } - for c in ['CLIP', 'WRAP', 'RAISE']: + for c in ['MAXDIMS', 'CLIP', 'WRAP', 'RAISE']: interpleveldefs[c] = 'space.wrap(constants.%s)' % c diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py --- a/pypy/module/micronumpy/base.py +++ b/pypy/module/micronumpy/base.py @@ -58,10 +58,10 @@ elif owning: # Will free storage when GCd impl = concrete.ConcreteArray(shape, dtype, order, strides, - backstrides, storage=storage) + backstrides, storage=storage) else: impl = concrete.ConcreteArrayNotOwning(shape, dtype, order, strides, - backstrides, storage) + backstrides, storage) if w_subtype: w_ret = space.allocate_instance(W_NDimArray, w_subtype) W_NDimArray.__init__(w_ret, impl) diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py --- a/pypy/module/micronumpy/boxes.py +++ b/pypy/module/micronumpy/boxes.py @@ -87,7 +87,8 @@ value[0] = self.value builder = StringBuilder() - builder.append_charpsize(rffi.cast(rffi.CCHARP, value), rffi.sizeof(lltype.typeOf(self.value))) + builder.append_charpsize(rffi.cast(rffi.CCHARP, value), + rffi.sizeof(lltype.typeOf(self.value))) ret = builder.build() lltype.free(value, flavor="raw") @@ -117,7 +118,8 @@ value[1] = self.imag builder = StringBuilder() - builder.append_charpsize(rffi.cast(rffi.CCHARP, value), rffi.sizeof(lltype.typeOf(self.real)) * 2) + builder.append_charpsize(rffi.cast(rffi.CCHARP, value), + rffi.sizeof(lltype.typeOf(self.real)) * 2) ret = builder.build() lltype.free(value, flavor="raw") @@ -179,27 +181,27 @@ dtype = self.get_dtype(space) return space.wrap(dtype.itemtype.bool(self)) + def _unaryop_impl(ufunc_name): + def impl(self, space, w_out=None): + from pypy.module.micronumpy import ufuncs + return getattr(ufuncs.get(space), ufunc_name).call( + space, [self, w_out]) + return func_with_new_name(impl, "unaryop_%s_impl" % ufunc_name) + def _binop_impl(ufunc_name): def impl(self, space, w_other, w_out=None): from pypy.module.micronumpy import ufuncs - return getattr(ufuncs.get(space), ufunc_name).call(space, - [self, w_other, w_out]) + return getattr(ufuncs.get(space), ufunc_name).call( + space, [self, w_other, w_out]) return func_with_new_name(impl, "binop_%s_impl" % ufunc_name) def _binop_right_impl(ufunc_name): def impl(self, space, w_other, w_out=None): from pypy.module.micronumpy import ufuncs - return getattr(ufuncs.get(space), ufunc_name).call(space, - [w_other, self, w_out]) + return getattr(ufuncs.get(space), ufunc_name).call( + space, [w_other, self, w_out]) return func_with_new_name(impl, "binop_right_%s_impl" % ufunc_name) - def _unaryop_impl(ufunc_name): - def impl(self, space, w_out=None): - from pypy.module.micronumpy import ufuncs - return getattr(ufuncs.get(space), ufunc_name).call(space, - [self, w_out]) - return func_with_new_name(impl, "unaryop_%s_impl" % ufunc_name) - descr_add = _binop_impl("add") descr_sub = _binop_impl("subtract") descr_mul = _binop_impl("multiply") diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py --- a/pypy/module/micronumpy/concrete.py +++ b/pypy/module/micronumpy/concrete.py @@ -368,13 +368,10 @@ class ConcreteArray(ConcreteArrayNotOwning): def __init__(self, shape, dtype, order, strides, backstrides, storage=lltype.nullptr(RAW_STORAGE)): - null_storage = lltype.nullptr(RAW_STORAGE) + if storage == lltype.nullptr(RAW_STORAGE): + storage = dtype.itemtype.malloc(support.product(shape) * dtype.elsize) ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, backstrides, - null_storage) - if storage == lltype.nullptr(RAW_STORAGE): - self.storage = dtype.itemtype.malloc(self.size) - else: - self.storage = storage + storage) def __del__(self): free_raw_storage(self.storage, track_allocation=False) diff --git a/pypy/module/micronumpy/constants.py b/pypy/module/micronumpy/constants.py --- a/pypy/module/micronumpy/constants.py +++ b/pypy/module/micronumpy/constants.py @@ -1,3 +1,5 @@ +MAXDIMS = 32 + BOOL = 0 BYTE = 1 UBYTE = 2 diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py --- a/pypy/module/micronumpy/ctors.py +++ b/pypy/module/micronumpy/ctors.py @@ -5,7 +5,6 @@ from pypy.module.micronumpy import descriptor, loop, ufuncs from pypy.module.micronumpy.base import W_NDimArray, convert_to_array from pypy.module.micronumpy.converters import shape_converter -from pypy.module.micronumpy.strides import find_shape_and_elems def build_scalar(space, w_dtype, w_state): @@ -27,6 +26,8 @@ @unwrap_spec(ndmin=int, copy=bool, subok=bool) def array(space, w_object, w_dtype=None, copy=True, w_order=None, subok=False, ndmin=0): + from pypy.module.micronumpy import strides + # for anything that isn't already an array, try __array__ method first if not isinstance(w_object, W_NDimArray): w___array__ = space.lookup(w_object, "__array__") @@ -68,12 +69,9 @@ return w_ret # not an array or incorrect dtype - shape, elems_w = find_shape_and_elems(space, w_object, dtype) + shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype) if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1): - for w_elem in elems_w: - if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar(): - w_elem = w_elem.get_scalar_value() - dtype = ufuncs.find_dtype_for_scalar(space, w_elem, dtype) + dtype = strides.find_dtype_for_seq(space, elems_w, dtype) if dtype is None: dtype = descriptor.get_dtype_cache(space).w_float64dtype elif dtype.is_str_or_unicode() and dtype.elsize < 1: @@ -83,10 +81,10 @@ if ndmin > len(shape): shape = [1] * (ndmin - len(shape)) + shape w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order) - arr_iter = w_arr.create_iter() - for w_elem in elems_w: - arr_iter.setitem(dtype.coerce(space, w_elem)) - arr_iter.next() + if len(elems_w) == 1: + w_arr.set_scalar_value(dtype.coerce(space, elems_w[0])) + else: + loop.assign(space, w_arr, elems_w) return w_arr 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 @@ -164,6 +164,13 @@ arr_iter.setitem(box) arr_iter.next() +def assign(space, arr, seq): + arr_iter = arr.create_iter() + arr_dtype = arr.get_dtype() + for item in seq: + arr_iter.setitem(arr_dtype.coerce(space, item)) + arr_iter.next() + where_driver = jit.JitDriver(name='numpy_where', greens = ['shapelen', 'dtype', 'arr_dtype'], reds = 'auto') diff --git a/pypy/module/micronumpy/strides.py b/pypy/module/micronumpy/strides.py --- a/pypy/module/micronumpy/strides.py +++ b/pypy/module/micronumpy/strides.py @@ -181,6 +181,10 @@ return [], [w_iterable] if isinstance(w_iterable, W_NDimArray) and w_iterable.is_scalar(): return [], [w_iterable] + return _find_shape_and_elems(space, w_iterable, is_rec_type) + + +def _find_shape_and_elems(space, w_iterable, is_rec_type): shape = [space.len_w(w_iterable)] batch = space.listview(w_iterable) while True: @@ -210,6 +214,25 @@ batch = new_batch +def find_dtype_for_seq(space, elems_w, dtype): + from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar + if len(elems_w) == 1: + w_elem = elems_w[0] + if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar(): + w_elem = w_elem.get_scalar_value() + return find_dtype_for_scalar(space, w_elem, dtype) + return _find_dtype_for_seq(space, elems_w, dtype) + + +def _find_dtype_for_seq(space, elems_w, dtype): + from pypy.module.micronumpy.ufuncs import find_dtype_for_scalar + for w_elem in elems_w: + if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar(): + w_elem = w_elem.get_scalar_value() + dtype = find_dtype_for_scalar(space, w_elem, dtype) + return dtype + + def to_coords(space, shape, size, order, w_item_or_slice): '''Returns a start coord, step, and length. ''' diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -248,6 +248,7 @@ def test_constants(self): import numpy as np + assert np.MAXDIMS is 32 assert np.CLIP is 0 assert np.WRAP is 1 assert np.RAISE is 2 diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py --- a/rpython/rtyper/lltypesystem/rstr.py +++ b/rpython/rtyper/lltypesystem/rstr.py @@ -108,6 +108,8 @@ copy_string_to_raw = func_with_new_name(copy_string_to_raw, 'copy_%s_to_raw' % name) @jit.dont_look_inside + @signature(types.any(), types.any(), types.int(), types.int(), + returns=types.none()) def copy_raw_to_string(ptrsrc, dst, dststart, length): # xxx Warning: same note as above apply: don't do this at home assert length >= 0 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit