Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68229:5898d0122baa
Date: 2013-11-18 19:47 -0500
http://bitbucket.org/pypy/pypy/changeset/5898d0122baa/
Log: support order argument for array.tostring
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
@@ -93,7 +93,11 @@
def descr_fill(self, space, w_value):
self.fill(self.get_dtype().coerce(space, w_value))
- def descr_tostring(self, space):
+ def descr_tostring(self, space, w_order=None):
+ order = order_converter(space, w_order, NPY_CORDER)
+ if order == NPY_FORTRANORDER:
+ raise OperationError(space.w_NotImplementedError, space.wrap(
+ "unsupported value for order"))
return space.wrap(loop.tostring(space, self))
def getitem_filter(self, space, arr):
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
@@ -2829,6 +2829,15 @@
assert array([1, 2, 3], '<i2')[::2].tostring() == '\x01\x00\x03\x00'
assert array([1, 2, 3], '>i2')[::2].tostring() == '\x00\x01\x00\x03'
assert array(0, dtype='i2').tostring() == '\x00\x00'
+ a = array([[1, 2], [3, 4]], dtype='i1')
+ for order in (None, False, 'C', 'K', 'a'):
+ assert a.tostring(order) == '\x01\x02\x03\x04'
+ import sys
+ for order in (True, 'F'):
+ if '__pypy__' in sys.builtin_module_names:
+ raises(NotImplementedError, a.tostring, order)
+ else:
+ assert a.tostring(order) == '\x01\x03\x02\x04'
class AppTestRepr(BaseNumpyAppTest):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit