Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67819:61d2ad085488 Date: 2013-11-03 20:38 -0500 http://bitbucket.org/pypy/pypy/changeset/61d2ad085488/
Log: accept order argument for copy 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 @@ -63,6 +63,11 @@ NPY_FLOATINGLTR = 'f' NPY_COMPLEXLTR = 'c' +NPY_ANYORDER = -1 +NPY_CORDER = 0 +NPY_FORTRANORDER = 1 +NPY_KEEPORDER = 2 + NPY_CLIP = 0 NPY_WRAP = 1 NPY_RAISE = 2 diff --git a/pypy/module/micronumpy/conversion_utils.py b/pypy/module/micronumpy/conversion_utils.py --- a/pypy/module/micronumpy/conversion_utils.py +++ b/pypy/module/micronumpy/conversion_utils.py @@ -18,3 +18,25 @@ return mode raise OperationError(space.w_TypeError, space.wrap("clipmode not understood")) + +def order_converter(space, w_order, default): + if space.is_none(w_order): + return default + if not space.isinstance_w(w_order, space.w_str): + if space.is_true(w_order): + return NPY_FORTRANORDER + else: + return NPY_CORDER + else: + order = space.str_w(w_order) + if order.startswith('C') or order.startswith('c'): + return NPY_CORDER + elif order.startswith('F') or order.startswith('f'): + return NPY_FORTRANORDER + elif order.startswith('A') or order.startswith('a'): + return NPY_ANYORDER + elif order.startswith('K') or order.startswith('k'): + return NPY_KEEPORDER + else: + raise OperationError(space.w_TypeError, space.wrap( + "order not understood")) 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 @@ -18,6 +18,8 @@ from rpython.rlib import jit from rpython.rlib.rstring import StringBuilder from pypy.module.micronumpy.arrayimpl.base import BaseArrayImplementation +from pypy.module.micronumpy.conversion_utils import order_converter +from pypy.module.micronumpy.constants import * def _find_shape(space, w_size, dtype): if space.is_none(w_size): @@ -287,7 +289,11 @@ def get_scalar_value(self): return self.implementation.get_scalar_value() - def descr_copy(self, space): + def descr_copy(self, space, w_order=None): + order = order_converter(space, w_order, NPY_KEEPORDER) + if order == NPY_FORTRANORDER: + raise OperationError(space.w_NotImplementedError, space.wrap( + "unsupported value for order")) copy = self.implementation.copy(space) w_subtype = space.type(self) return wrap_impl(space, w_subtype, self, copy) 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 @@ -411,6 +411,22 @@ b = a.copy() assert b[0] == a[0] + a = arange(8) + b = a.copy(order=None) + assert (b == a).all() + b = a.copy(order=0) + assert (b == a).all() + b = a.copy(order='C') + assert (b == a).all() + b = a.copy(order='K') + assert (b == a).all() + b = a.copy(order='A') + assert (b == a).all() + import sys + if '__pypy__' in sys.builtin_module_names: + raises(NotImplementedError, a.copy, order='F') + raises(NotImplementedError, a.copy, order=True) + def test_iterator_init(self): from numpypy import array a = array(range(5)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit