Author: Brian Kearns <[email protected]>
Branch:
Changeset: r68408:fb30e6aa03bb
Date: 2013-12-11 14:16 -0500
http://bitbucket.org/pypy/pypy/changeset/fb30e6aa03bb/
Log: support bool order argument for ndarray.__new__
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
@@ -1065,9 +1065,9 @@
return w_obj
pass
-@unwrap_spec(offset=int, order=str)
+@unwrap_spec(offset=int)
def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
- offset=0, w_strides=None, order='C'):
+ offset=0, w_strides=None, w_order=None):
from pypy.module.micronumpy.arrayimpl.concrete import ConcreteArray
from pypy.module.micronumpy.support import calc_strides
dtype = space.interp_w(interp_dtype.W_Dtype,
@@ -1101,6 +1101,11 @@
if not shape:
return W_NDimArray.new_scalar(space, dtype)
+ order = order_converter(space, w_order, NPY_CORDER)
+ if order == NPY_CORDER:
+ order = 'C'
+ else:
+ order = 'F'
if space.is_w(w_subtype, space.gettypefor(W_NDimArray)):
return W_NDimArray.from_shape(space, shape, dtype, order)
strides, backstrides = calc_strides(shape, dtype.base, order)
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
@@ -271,6 +271,17 @@
# test uninitialized value crash?
assert len(str(a)) > 0
+ import sys
+ for order in [False, True, 'C', 'F']:
+ a = ndarray.__new__(ndarray, (2, 3), float, order=order)
+ assert a.shape == (2, 3)
+ if order in [True, 'F'] and '__pypy__' not in
sys.builtin_module_names:
+ assert a.flags['F']
+ assert not a.flags['C']
+ else:
+ assert a.flags['C']
+ assert not a.flags['F']
+
def test_ndmin(self):
from numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit