Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r69272:a00ad3c03145 Date: 2014-02-22 13:52 -0500 http://bitbucket.org/pypy/pypy/changeset/a00ad3c03145/
Log: fix numpy.concatenate(axis=None) diff --git a/pypy/module/micronumpy/interp_arrayops.py b/pypy/module/micronumpy/interp_arrayops.py --- a/pypy/module/micronumpy/interp_arrayops.py +++ b/pypy/module/micronumpy/interp_arrayops.py @@ -98,15 +98,25 @@ return w_arr.descr_dot(space, w_obj2, w_out) -@unwrap_spec(axis=int) -def concatenate(space, w_args, axis=0): +def concatenate(space, w_args, w_axis=None): args_w = space.listview(w_args) if len(args_w) == 0: - raise OperationError(space.w_ValueError, space.wrap("need at least one array to concatenate")) + raise oefmt(space.w_ValueError, "need at least one array to concatenate") args_w = [convert_to_array(space, w_arg) for w_arg in args_w] + if w_axis is None: + w_axis = space.wrap(0) + if space.is_none(w_axis): + args_w = [w_arg.reshape(space, + space.newlist([w_arg.descr_get_size(space)])) + for w_arg in args_w] + w_axis = space.wrap(0) dtype = args_w[0].get_dtype() shape = args_w[0].get_shape()[:] ndim = len(shape) + if ndim == 0: + raise oefmt(space.w_ValueError, + "zero-dimensional arrays cannot be concatenated") + axis = space.int_w(w_axis) orig_axis = axis if axis < 0: axis = ndim + axis diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py --- a/pypy/module/micronumpy/interp_support.py +++ b/pypy/module/micronumpy/interp_support.py @@ -91,7 +91,7 @@ axis = maxint else: axis = space.int_w(w_axis) - if axis < -shapelen or axis>= shapelen: + if axis < -shapelen or axis >= shapelen: raise oefmt(space.w_ValueError, "axis entry %d is out of bounds [%d, %d)", axis, -shapelen, shapelen) 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 @@ -1773,6 +1773,18 @@ def test_concatenate(self): from numpypy import array, concatenate, dtype + exc = raises(ValueError, concatenate, (array(1.5), array(2.5))) + assert exc.value[0] == 'zero-dimensional arrays cannot be concatenated' + a = concatenate((array(1.5), array(2.5)), axis=None) + assert (a == [1.5, 2.5]).all() + assert exc.value[0] == 'zero-dimensional arrays cannot be concatenated' + exc = raises(ValueError, concatenate, (array([1.5]), array(2.5))) + assert exc.value[0] == 'all the input arrays must have same number ' \ + 'of dimensions' + exc = raises(ValueError, concatenate, (array(1.5), array([2.5]))) + assert exc.value[0] == 'zero-dimensional arrays cannot be concatenated' + a = concatenate((array([1.5]), array([2.5]))) + assert (a == [1.5, 2.5]).all() a1 = array([0,1,2]) a2 = array([3,4,5]) a = concatenate((a1, a2)) @@ -1783,6 +1795,8 @@ assert (a == [0,1,2,3,4,5]).all() a = concatenate((a1, a2), axis=-1) assert (a == [0,1,2,3,4,5]).all() + a = concatenate((a1, a2), axis=None) + assert (a == [0,1,2,3,4,5]).all() b1 = array([[1, 2], [3, 4]]) b2 = array([[5, 6]]) @@ -1790,6 +1804,8 @@ assert (b == [[1, 2],[3, 4],[5, 6]]).all() c = concatenate((b1, b2.T), axis=1) assert (c == [[1, 2, 5],[3, 4, 6]]).all() + c1 = concatenate((b1, b2), axis=None) + assert (c1 == [1, 2, 3, 4, 5, 6]).all() d = concatenate(([0],[1])) assert (d == [0,1]).all() e1 = array([[0,1],[2,3]]) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit