Author: Maciej Fijalkowski <fij...@gmail.com> Branch: Changeset: r61127:a7dd6ebe1122 Date: 2013-02-12 13:09 +0200 http://bitbucket.org/pypy/pypy/changeset/a7dd6ebe1122/
Log: Backed out changeset dcc4f89c3872 diff --git a/lib-python/2.7/urllib.py b/lib-python/2.7/urllib.py --- a/lib-python/2.7/urllib.py +++ b/lib-python/2.7/urllib.py @@ -1205,16 +1205,15 @@ # fastpath if len(res) == 1: return s - res_list = [res[0]] + s = res[0] for item in res[1:]: try: - x = _hextochr[item[:2]] + item[2:] + s += _hextochr[item[:2]] + item[2:] except KeyError: - x = '%' + item + s += '%' + item except UnicodeDecodeError: - x = unichr(int(item[:2], 16)) + item[2:] - res_list.append(x) - return ''.join(res_list) + s += unichr(int(item[:2], 16)) + item[2:] + return s def unquote_plus(s): """unquote('%7e/abc+def') -> '~/abc def'""" diff --git a/lib-python/2.7/urlparse.py b/lib-python/2.7/urlparse.py --- a/lib-python/2.7/urlparse.py +++ b/lib-python/2.7/urlparse.py @@ -321,16 +321,15 @@ # fastpath if len(res) == 1: return s - res_list = [res[0]] + s = res[0] for item in res[1:]: try: - x = _hextochr[item[:2]] + item[2:] + s += _hextochr[item[:2]] + item[2:] except KeyError: - x = '%' + item + s += '%' + item except UnicodeDecodeError: - x = unichr(int(item[:2], 16)) + item[2:] - res_list.append(x) - return ''.join(res_list) + s += unichr(int(item[:2], 16)) + item[2:] + return s def parse_qs(qs, keep_blank_values=0, strict_parsing=0): """Parse a query given as a string argument. diff --git a/pypy/doc/config/translation.lldebug.txt b/pypy/doc/config/translation.lldebug.txt new file mode 100644 --- /dev/null +++ b/pypy/doc/config/translation.lldebug.txt @@ -0,0 +1,1 @@ +Run make lldebug when source is ready diff --git a/pypy/goal/__init__.py b/pypy/goal/__init__.py new file mode 100644 --- /dev/null +++ b/pypy/goal/__init__.py @@ -0,0 +1,1 @@ +#empty diff --git a/pypy/module/cpyext/include/ceval.h b/pypy/module/cpyext/include/ceval.h new file mode 100644 --- /dev/null +++ b/pypy/module/cpyext/include/ceval.h @@ -0,0 +1,1 @@ +/* empty */ diff --git a/pypy/module/micronumpy/arrayimpl/sort.py b/pypy/module/micronumpy/arrayimpl/sort.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/arrayimpl/sort.py @@ -0,0 +1,195 @@ + +""" This is the implementation of various sorting routines in numpy. It's here +because it only makes sense on a concrete array +""" + +from rpython.rtyper.lltypesystem import rffi, lltype +from rpython.rlib.listsort import make_timsort_class +from rpython.rlib.rawstorage import raw_storage_getitem, raw_storage_setitem, \ + free_raw_storage, alloc_raw_storage +from rpython.rlib.unroll import unrolling_iterable +from rpython.rlib.rarithmetic import intmask +from rpython.rlib.objectmodel import specialize +from pypy.interpreter.error import OperationError +from pypy.module.micronumpy.base import W_NDimArray +from pypy.module.micronumpy import interp_dtype, types +from pypy.module.micronumpy.iter import AxisIterator + +INT_SIZE = rffi.sizeof(lltype.Signed) + +def make_sort_function(space, itemtype, comp_type, count=1): + TP = itemtype.T + step = rffi.sizeof(TP) + + class Repr(object): + def __init__(self, index_stride_size, stride_size, size, values, + indexes, index_start, start): + self.index_stride_size = index_stride_size + self.stride_size = stride_size + self.index_start = index_start + self.start = start + self.size = size + self.values = values + self.indexes = indexes + + def getitem(self, item): + if count < 2: + v = raw_storage_getitem(TP, self.values, item * self.stride_size + + self.start) + else: + v = [] + for i in range(count): + _v = raw_storage_getitem(TP, self.values, item * self.stride_size + + self.start + step * i) + v.append(_v) + if comp_type == 'int': + v = intmask(v) + elif comp_type == 'float': + v = float(v) + elif comp_type == 'complex': + v = [float(v[0]),float(v[1])] + else: + raise NotImplementedError('cannot reach') + return (v, raw_storage_getitem(lltype.Signed, self.indexes, + item * self.index_stride_size + + self.index_start)) + + def setitem(self, idx, item): + if count < 2: + raw_storage_setitem(self.values, idx * self.stride_size + + self.start, rffi.cast(TP, item[0])) + else: + i = 0 + for val in item[0]: + raw_storage_setitem(self.values, idx * self.stride_size + + self.start + i*step, rffi.cast(TP, val)) + i += 1 + raw_storage_setitem(self.indexes, idx * self.index_stride_size + + self.index_start, item[1]) + + class ArgArrayRepWithStorage(Repr): + def __init__(self, index_stride_size, stride_size, size): + start = 0 + dtype = interp_dtype.get_dtype_cache(space).w_longdtype + self.indexes = dtype.itemtype.malloc(size*dtype.get_size()) + self.values = alloc_raw_storage(size * stride_size, + track_allocation=False) + Repr.__init__(self, index_stride_size, stride_size, + size, self.values, self.indexes, start, start) + + def __del__(self): + free_raw_storage(self.indexes, track_allocation=False) + free_raw_storage(self.values, track_allocation=False) + + def arg_getitem(lst, item): + return lst.getitem(item) + + def arg_setitem(lst, item, value): + lst.setitem(item, value) + + def arg_length(lst): + return lst.size + + def arg_getitem_slice(lst, start, stop): + retval = ArgArrayRepWithStorage(lst.index_stride_size, lst.stride_size, + stop-start) + for i in range(stop-start): + retval.setitem(i, lst.getitem(i+start)) + return retval + + if count < 2: + def arg_lt(a, b): + # Does numpy do <= ? + return a[0] < b[0] + else: + def arg_lt(a, b): + for i in range(count): + if a[0][i] < b[0][i]: + return True + elif a[0][i] > b[0][i]: + return False + # Does numpy do True? + return False + + ArgSort = make_timsort_class(arg_getitem, arg_setitem, arg_length, + arg_getitem_slice, arg_lt) + + def argsort(arr, space, w_axis, itemsize): + if w_axis is space.w_None: + # note that it's fine ot pass None here as we're not going + # to pass the result around (None is the link to base in slices) + arr = arr.reshape(space, None, [arr.get_size()]) + axis = 0 + elif w_axis is None: + axis = -1 + else: + axis = space.int_w(w_axis) + # create array of indexes + dtype = interp_dtype.get_dtype_cache(space).w_longdtype + index_arr = W_NDimArray.from_shape(arr.get_shape(), dtype) + storage = index_arr.implementation.get_storage() + if len(arr.get_shape()) == 1: + for i in range(arr.get_size()): + raw_storage_setitem(storage, i * INT_SIZE, i) + r = Repr(INT_SIZE, itemsize, arr.get_size(), arr.get_storage(), + storage, 0, arr.start) + ArgSort(r).sort() + else: + shape = arr.get_shape() + if axis < 0: + axis = len(shape) + axis - 1 + if axis < 0 or axis > len(shape): + raise OperationError(space.w_IndexError, space.wrap( + "Wrong axis %d" % axis)) + iterable_shape = shape[:axis] + [0] + shape[axis + 1:] + iter = AxisIterator(arr, iterable_shape, axis, False) + index_impl = index_arr.implementation + index_iter = AxisIterator(index_impl, iterable_shape, axis, False) + stride_size = arr.strides[axis] + index_stride_size = index_impl.strides[axis] + axis_size = arr.shape[axis] + while not iter.done(): + for i in range(axis_size): + raw_storage_setitem(storage, i * index_stride_size + + index_iter.offset, i) + r = Repr(index_stride_size, stride_size, axis_size, + arr.get_storage(), storage, index_iter.offset, iter.offset) + ArgSort(r).sort() + iter.next() + index_iter.next() + return index_arr + + return argsort + +def argsort_array(arr, space, w_axis): + cache = space.fromcache(SortCache) # that populates SortClasses + itemtype = arr.dtype.itemtype + for tp in all_types: + if isinstance(itemtype, tp[0]): + return cache._lookup(tp)(arr, space, w_axis, + itemtype.get_element_size()) + # XXX this should probably be changed + raise OperationError(space.w_NotImplementedError, + space.wrap("sorting of non-numeric types " + \ + "'%s' is not implemented" % arr.dtype.get_name(), )) + +all_types = (types.all_float_types + types.all_complex_types + + types.all_int_types) +all_types = [i for i in all_types if not '_mixin_' in i[0].__dict__] +all_types = unrolling_iterable(all_types) + +class SortCache(object): + built = False + + def __init__(self, space): + if self.built: + return + self.built = True + cache = {} + for cls, it in all_types._items: + if it == 'complex': + cache[cls] = make_sort_function(space, cls, it, 2) + else: + cache[cls] = make_sort_function(space, cls, it) + self.cache = cache + self._lookup = specialize.memo()(lambda tp : cache[tp[0]]) diff --git a/pypy/module/micronumpy/constants.py b/pypy/module/micronumpy/constants.py new file mode 100644 --- /dev/null +++ b/pypy/module/micronumpy/constants.py @@ -0,0 +1,4 @@ + +MODE_WRAP, MODE_RAISE, MODE_CLIP = range(3) + +MODES = {'wrap': MODE_WRAP, 'raise': MODE_RAISE, 'clip': MODE_CLIP} diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_shape_base.py b/pypy/module/test_lib_pypy/numpypy/core/test_shape_base.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/numpypy/core/test_shape_base.py @@ -0,0 +1,163 @@ +from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest + + +class AppTestShapeBase(BaseNumpyAppTest): + + def test_atleast_1d(self): + from numpypy import array, array_equal + import numpypy as np + a = np.atleast_1d(1.0) + assert np.array_equal(a, [1.]) + + x = np.arange(9.0).reshape(3, 3) + a = np.atleast_1d(x) + assert np.array_equal(a, [[0., 1., 2.], + [3., 4., 5.], + [6., 7., 8.]]) + assert np.atleast_1d(x) is x + + a = np.atleast_1d(1, [3, 4]) + assert len(a) == 2 + assert array_equal(a[0], [1]) + assert array_equal(a[1], [3, 4]) + + def test_atleast_2d(self): + import numpypy as np + a = np.atleast_2d(3.0) + assert np.array_equal(a, [[3.]]) + + x = np.arange(3.0) + a = np.atleast_2d(x) + assert np.array_equal(a, [[0., 1., 2.]]) + + a = np.atleast_2d(1, [1, 2], [[1, 2]]) + assert len(a) == 3 + assert np.array_equal(a[0], [[1]]) + assert np.array_equal(a[1], [[1, 2]]) + assert np.array_equal(a[2], [[1, 2]]) + + def test_atleast_3d(self): + import numpypy as np + + a = np.atleast_3d(3.0) + assert np.array_equal(a, [[[3.]]]) + + x = np.arange(3.0) + assert np.atleast_3d(x).shape == (1, 3, 1) + + x = np.arange(12.0).reshape(4, 3) + assert np.atleast_3d(x).shape == (4, 3, 1) + + a = np.atleast_3d([1, 2]) + assert np.array_equal(a, [[[1], + [2]]]) + assert a.shape == (1, 2, 1) + + a = np.atleast_3d([[1, 2]]) + assert np.array_equal(a, [[[1], + [2]]]) + assert a.shape == (1, 2, 1) + + a = np.atleast_3d([[[1, 2]]]) + assert np.array_equal(a, [[[1, 2]]]) + assert a.shape == (1, 1, 2) + + def test_vstack(self): + import numpypy as np + + a = np.array([1, 2, 3]) + b = np.array([2, 3, 4]) + c = np.vstack((a, b)) + assert np.array_equal(c, [[1, 2, 3], + [2, 3, 4]]) + + a = np.array([[1], [2], [3]]) + b = np.array([[2], [3], [4]]) + c = np.vstack((a, b)) + assert np.array_equal(c, [[1], + [2], + [3], + [2], + [3], + [4]]) + + for shape1, shape2 in [[(2, 1), (3, 1)], + [(2, 4), [3, 4]]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.vstack((a, b)) == + np.ones((a.shape[0] + b.shape[0], + a.shape[1]))) + + #skip("https://bugs.pypy.org/issue1394") + for shape1, shape2 in [[(3, 2, 4), (7, 2, 4)], + [(0, 2, 7), (10, 2, 7)], + [(0, 2, 7), (0, 2, 7)]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.vstack((a, b)) == + np.ones((a.shape[0] + b.shape[0], + a.shape[1], + a.shape[2]))) + + def test_hstack(self): + import numpypy as np + a = np.array((1, 2, 3)) + b = np.array((2, 3, 4)) + c = np.hstack((a, b)) + assert np.array_equal(c, [1, 2, 3, 2, 3, 4]) + + a = np.array([[1], [2], [3]]) + b = np.array([[2], [3], [4]]) + c = np.hstack((a, b)) + assert np.array_equal(c, [[1, 2], + [2, 3], + [3, 4]]) + + for shape1, shape2 in [[(1, 2), (1, 3)], + [(4, 2), (4, 3)]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.hstack((a, b)) == + np.ones((a.shape[0], + a.shape[1] + b.shape[1]))) + + #skip("https://bugs.pypy.org/issue1394") + for shape1, shape2 in [[(2, 3, 4), (2, 7, 4)], + [(1, 4, 7), (1, 10, 7)], + [(1, 4, 7), (1, 0, 7)], + [(1, 0, 7), (1, 0, 7)]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.hstack((a, b)) == + np.ones((a.shape[0], + a.shape[1] + b.shape[1], + a.shape[2]))) + + def test_dstack(self): + import numpypy as np + a = np.array((1, 2, 3)) + b = np.array((2, 3, 4)) + c = np.dstack((a, b)) + assert np.array_equal(c, [[[1, 2], [2, 3], [3, 4]]]) + + a = np.array([[1], [2], [3]]) + b = np.array([[2], [3], [4]]) + c = np.dstack((a, b)) + assert np.array_equal(c, [[[1, 2]], [[2, 3]], [[3, 4]]]) + + #skip("https://bugs.pypy.org/issue1394") + for shape1, shape2 in [[(4, 2, 3), (4, 2, 7)], + [(7, 2, 0), (7, 2, 10)], + [(7, 2, 0), (7, 2, 0)]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.dstack((a, b)) == + np.ones((a.shape[0], + a.shape[1], + a.shape[2] + b.shape[2]))) + + for shape1, shape2 in [[(4, 2, 3, 5), (4, 2, 7, 5)], + [(7, 2, 0, 5), (7, 2, 10, 5)], + [(7, 2, 0, 5), (7, 2, 0, 5)]]: + a, b = np.ones(shape1), np.ones(shape2) + assert np.all(np.dstack((a, b)) == + np.ones((a.shape[0], + a.shape[1], + a.shape[2] + b.shape[2], + a.shape[3]))) diff --git a/pypy/module/test_lib_pypy/pyrepl/test_keymap.py b/pypy/module/test_lib_pypy/pyrepl/test_keymap.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/pyrepl/test_keymap.py @@ -0,0 +1,10 @@ +from pyrepl.keymap import compile_keymap + + +def test_compile_keymap(): + k = compile_keymap({ + b'a': 'test', + b'bc': 'test2', + }) + + assert k == {b'a': 'test', b'b': {b'c': 'test2'}} diff --git a/pypy/module/test_lib_pypy/pyrepl/test_readline.py b/pypy/module/test_lib_pypy/pyrepl/test_readline.py new file mode 100644 --- /dev/null +++ b/pypy/module/test_lib_pypy/pyrepl/test_readline.py @@ -0,0 +1,15 @@ +from pyrepl.readline import _ReadlineWrapper +import os +import pty + + +def test_raw_input(): + master, slave = pty.openpty() + readline_wrapper = _ReadlineWrapper(slave, slave) + os.write(master, b'input\n') + + result = readline_wrapper.get_reader().readline() + #result = readline_wrapper.raw_input('prompt:') + assert result == 'input' + # A bytes string on python2, a unicode string on python3. + assert isinstance(result, str) diff --git a/pypy/sandbox/__init__.py b/pypy/sandbox/__init__.py new file mode 100644 --- /dev/null +++ b/pypy/sandbox/__init__.py @@ -0,0 +1,1 @@ +# empty \ No newline at end of file _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit