Author: Yichao Yu <yyc1...@gmail.com> Branch: numpy-generic-item Changeset: r74053:5f0f0784b29a Date: 2014-09-23 09:26 -0400 http://bitbucket.org/pypy/pypy/changeset/5f0f0784b29a/
Log: generic.transpose 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 @@ -161,6 +161,18 @@ "index %d is out of bounds for size 1", idx) return self.item(space) + def descr_transpose(self, space, args_w): + if len(args_w) == 1 and space.isinstance_w(args_w[0], space.w_tuple): + args_w = space.fixedview(args_w[0]) + if len(args_w) >= 1: + for w_arg in args_w: + try: + idx = support.index_w(space, w_arg) + except OperationError: + raise oefmt(space.w_TypeError, "an integer is required") + raise oefmt(space.w_ValueError, "axes don't match array") + return self.item(space) + def descr_getitem(self, space, w_item): from pypy.module.micronumpy.base import convert_to_array if space.is_w(w_item, space.w_Ellipsis) or \ @@ -637,6 +649,7 @@ tolist = interp2app(W_GenericBox.item), item = interp2app(W_GenericBox.descr_item), + transpose = interp2app(W_GenericBox.descr_transpose), min = interp2app(W_GenericBox.descr_self), max = interp2app(W_GenericBox.descr_self), argmin = interp2app(W_GenericBox.descr_zero), diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -293,11 +293,14 @@ def test_scalar_iter(self): from numpypy import int8, int16, int32, int64, float32, float64 - for t in int8, int16, int32, int64, float32, float64: + from numpypy import complex64, complex128 + for t in (int8, int16, int32, int64, float32, float64, + complex64, complex128): raises(TypeError, iter, t(17)) def test_item_tolist(self): from numpypy import int8, int16, int32, int64, float32, float64 + from numpypy import complex64, complex128 for t in int8, int16, int32, int64: val = t(17) assert val == 17 @@ -327,3 +330,51 @@ raises(ValueError, val.item, 0, '') raises(TypeError, val.item, '') raises(IndexError, val.item, 2) + + for t in complex64, complex128: + val = t(17j) + assert val == 17j + assert val.item() == 17j + assert val.tolist() == 17j + assert type(val.item()) == complex + assert type(val.tolist()) == complex + val.item(0) + val.item(()) + val.item((0,)) + raises(ValueError, val.item, 0, 1) + raises(ValueError, val.item, 0, '') + raises(TypeError, val.item, '') + raises(IndexError, val.item, 2) + + def test_transpose(self): + from numpypy import int8, int16, int32, int64, float32, float64 + from numpypy import complex64, complex128 + for t in int8, int16, int32, int64: + val = t(17) + assert val == 17 + assert val.transpose() == 17 + assert type(val.transpose()) == int + val.transpose(()) + raises(ValueError, val.transpose, 0, 1) + raises(TypeError, val.transpose, 0, '') + raises(ValueError, val.transpose, 0) + + for t in float32, float64: + val = t(17) + assert val == 17 + assert val.transpose() == 17 + assert type(val.transpose()) == float + val.transpose(()) + raises(ValueError, val.transpose, 0, 1) + raises(TypeError, val.transpose, 0, '') + raises(ValueError, val.transpose, 0) + + for t in complex64, complex128: + val = t(17j) + assert val == 17j + assert val.transpose() == 17j + assert type(val.transpose()) == complex + val.transpose(()) + raises(ValueError, val.transpose, 0, 1) + raises(TypeError, val.transpose, 0, '') + raises(ValueError, val.transpose, 0) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit