Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r46976:3ffe8b85f014 Date: 2011-09-01 11:13 +0200 http://bitbucket.org/pypy/pypy/changeset/3ffe8b85f014/
Log: merge heads diff --git a/pypy/jit/backend/x86/test/test_runner.py b/pypy/jit/backend/x86/test/test_runner.py --- a/pypy/jit/backend/x86/test/test_runner.py +++ b/pypy/jit/backend/x86/test/test_runner.py @@ -433,7 +433,7 @@ ops_offset[operations[2]] <= ops_offset[None]) - def test_calling_convention(self): + def test_calling_convention(self, monkeypatch): if WORD != 4: py.test.skip("32-bit only test") from pypy.jit.backend.x86.regloc import eax, edx @@ -442,7 +442,7 @@ from pypy.rlib.libffi import types, clibffi had_stdcall = hasattr(clibffi, 'FFI_STDCALL') if not had_stdcall: # not running on Windows, but we can still test - clibffi.FFI_STDCALL = 12345 + monkeypatch.setattr(clibffi, 'FFI_STDCALL', 12345, raising=False) # for ffi in [clibffi.FFI_DEFAULT_ABI, clibffi.FFI_STDCALL]: cpu = self.cpu @@ -514,9 +514,6 @@ assert self.cpu.get_latest_value_int(2) == 42 assert self.cpu.get_latest_value_int(3) == 42 - if not had_stdcall: - del clibffi.FFI_STDCALL - class TestDebuggingAssembler(object): def setup_method(self, meth): 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 @@ -53,7 +53,9 @@ VOID_TP = lltype.Ptr(lltype.Array(lltype.Void, hints={'nolength': True, "uncast_on_llgraph": True})) -def create_low_level_dtype(num, kind, name, aliases, applevel_types, T, valtype): +def create_low_level_dtype(num, kind, name, aliases, applevel_types, T, valtype, + expected_size=None): + class Box(BaseBox): def __init__(self, val): self.val = val @@ -113,6 +115,8 @@ W_LowLevelDtype.aliases = aliases W_LowLevelDtype.applevel_types = applevel_types W_LowLevelDtype.num_bytes = rffi.sizeof(T) + if expected_size is not None: + assert W_LowLevelDtype.num_bytes == expected_size return W_LowLevelDtype @@ -282,10 +286,21 @@ applevel_types = [], T = rffi.SIGNEDCHAR, valtype = rffi.SIGNEDCHAR._type, + expected_size = 1, ) class W_Int8Dtype(IntegerArithmeticDtype, W_Int8Dtype): - def unwrap(self, space, w_item): - return self.adapt_val(space.int_w(space.int(w_item))) + pass + +W_Int16Dtype = create_low_level_dtype( + num = 3, kind = SIGNEDLTR, name = "int16", + aliases = ["int16"], + applevel_types = [], + T = rffi.SHORT, + valtype = rffi.SHORT._type, + expected_size = 2, +) +class W_Int16Dtype(IntegerArithmeticDtype, W_Int16Dtype): + pass W_Int32Dtype = create_low_level_dtype( num = 5, kind = SIGNEDLTR, name = "int32", @@ -293,6 +308,7 @@ applevel_types = [], T = rffi.INT, valtype = rffi.INT._type, + expected_size = 4, ) class W_Int32Dtype(IntegerArithmeticDtype, W_Int32Dtype): pass @@ -303,6 +319,7 @@ applevel_types = ["long"], T = rffi.LONGLONG, valtype = rffi.LONGLONG._type, + expected_size = 8, ) class W_Int64Dtype(IntegerArithmeticDtype, W_Int64Dtype): pass @@ -313,6 +330,7 @@ applevel_types = ["float"], T = lltype.Float, valtype = float, + expected_size = 8, ) class W_Float64Dtype(FloatArithmeticDtype, W_Float64Dtype): def unwrap(self, space, w_item): @@ -323,7 +341,7 @@ ALL_DTYPES = [ W_BoolDtype, - W_Int8Dtype, W_Int32Dtype, W_Int64Dtype, + W_Int8Dtype, W_Int16Dtype, W_Int32Dtype, W_Int64Dtype, W_Float64Dtype ] @@ -353,4 +371,4 @@ kind = interp_attrproperty("kind", cls=W_Dtype), shape = GetSetProperty(W_Dtype.descr_get_shape), ) -W_Dtype.typedef.acceptable_as_base_class = False \ No newline at end of file +W_Dtype.typedef.acceptable_as_base_class = False 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 @@ -217,7 +217,15 @@ return space.wrap("[" + " ".join(concrete._getnums(True)) + "]") def descr_getitem(self, space, w_idx): - # TODO: indexing by tuples + # TODO: indexing by arrays and lists + if space.isinstance_w(w_idx, space.w_tuple): + length = space.len_w(w_idx) + if length == 0: + return space.wrap(self) + if length > 1: # only one dimension for now. + raise OperationError(space.w_IndexError, + space.wrap("invalid index")) + w_idx = space.getitem(w_idx, space.wrap(0)) start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) if step == 0: # Single index @@ -231,8 +239,19 @@ return space.wrap(res) def descr_setitem(self, space, w_idx, w_value): - # TODO: indexing by tuples and lists + # TODO: indexing by arrays and lists self.invalidated() + if space.isinstance_w(w_idx, space.w_tuple): + length = space.len_w(w_idx) + if length > 1: # only one dimension for now. + raise OperationError(space.w_IndexError, + space.wrap("invalid index")) + if length == 0: + w_idx = space.newslice(space.wrap(0), + space.wrap(self.find_size()), + space.wrap(1)) + else: + w_idx = space.getitem(w_idx, space.wrap(0)) start, stop, step, slice_length = space.decode_index4(w_idx, self.find_size()) if step == 0: 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 @@ -82,10 +82,20 @@ assert a[1] == 1 def test_add_int8(self): - from numpy import array + from numpy import array, dtype a = array(range(5), dtype="int8") b = a + a + assert b.dtype is dtype("int8") + for i in range(5): + assert b[i] == i * 2 + + def test_add_int16(self): + from numpy import array, dtype + + a = array(range(5), dtype="int16") + b = a + a + assert b.dtype is dtype("int16") for i in range(5): assert b[i] == i * 2 @@ -98,4 +108,4 @@ from numpy import dtype # You can't subclass dtype - raises(TypeError, type, "Foo", (dtype,), {}) \ No newline at end of file + raises(TypeError, type, "Foo", (dtype,), {}) 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 @@ -84,6 +84,9 @@ a = array(range(5), dtype="int8") assert str(a) == "[0 1 2 3 4]" + a = array(range(5), dtype="int16") + assert str(a) == "[0 1 2 3 4]" + def test_str_slice(self): from numpy import array, zeros a = array(range(5), float) @@ -102,6 +105,16 @@ assert a[-1] == 8 raises(IndexError, "a[-6]") + def test_getitem_tuple(self): + from numpy import array + a = array(range(5)) + raises(IndexError, "a[(1,2)]") + for i in xrange(5): + assert a[(i,)] == i + b = a[()] + for i in xrange(5): + assert a[i] == b[i] + def test_setitem(self): from numpy import array a = array(range(5)) @@ -110,6 +123,17 @@ raises(IndexError, "a[5] = 0.0") raises(IndexError, "a[-6] = 3.0") + def test_setitem_tuple(self): + from numpy import array + a = array(range(5)) + raises(IndexError, "a[(1,2)] = [0,1]") + for i in xrange(5): + a[(i,)] = i+1 + assert a[i] == i+1 + a[()] = range(5) + for i in xrange(5): + assert a[i] == i + def test_setslice_array(self): from numpy import array a = array(range(5)) @@ -541,4 +565,4 @@ a = fromstring(self.data) for i in range(4): assert a[i] == i + 1 - raises(ValueError, fromstring, "abc") \ No newline at end of file + raises(ValueError, fromstring, "abc") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit