[pypy-commit] pypy ndmin: make test pass -- add ndmin param to numpy.array

MichaelBlume noreply at buildbot.pypy.org
Thu Mar 22 20:53:59 CET 2012


Author: Mike Blume <mike at loggly.com>
Branch: ndmin
Changeset: r53923:c22d05cd841d
Date: 2012-03-19 23:43 -0700
http://bitbucket.org/pypy/pypy/changeset/c22d05cd841d/

Log:	make test pass -- add ndmin param to numpy.array

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
@@ -1125,7 +1125,8 @@
 
 @unwrap_spec(subok=bool, copy=bool, ownmaskna=bool)
 def array(space, w_item_or_iterable, w_dtype=None, w_order=None,
-          subok=True, copy=True, w_maskna=None, ownmaskna=False):
+          subok=True, copy=True, w_maskna=None, ownmaskna=False,
+          w_ndmin=None):
     # find scalar
     if w_maskna is None:
         w_maskna = space.w_None
@@ -1170,8 +1171,13 @@
                 break
         if dtype is None:
             dtype = interp_dtype.get_dtype_cache(space).w_float64dtype
+    shapelen = len(shape)
+    if w_ndmin is not None and not space.is_w(w_ndmin, space.w_None):
+        ndmin = space.int_w(w_ndmin)
+        if ndmin > shapelen:
+            shape = [1] * (ndmin - shapelen) + shape
+            shapelen = ndmin
     arr = W_NDimArray(shape[:], dtype=dtype, order=order)
-    shapelen = len(shape)
     arr_iter = arr.create_iter()
     # XXX we might want to have a jitdriver here
     for i in range(len(elems_w)):


More information about the pypy-commit mailing list