Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r68461:c8e4f9503987
Date: 2013-12-18 01:31 -0500
http://bitbucket.org/pypy/pypy/changeset/c8e4f9503987/

Log:    test/fix ndarray init from list of array scalars

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
@@ -1425,6 +1425,8 @@
     if dtype is None or (
                  dtype.is_str_or_unicode() and dtype.get_size() < 1):
         for w_elem in elems_w:
+            if isinstance(w_elem, W_NDimArray) and w_elem.is_scalar():
+                w_elem = w_elem.get_scalar_value()
             dtype = interp_ufuncs.find_dtype_for_scalar(space, w_elem,
                                                         dtype)
             #if dtype is interp_dtype.get_dtype_cache(space).w_float64dtype:
diff --git a/pypy/module/micronumpy/strides.py 
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -62,9 +62,10 @@
     if (is_rec_type and space.isinstance_w(w_elem, space.w_tuple)):
         return True
     if (space.isinstance_w(w_elem, space.w_tuple) or
-        isinstance(w_elem, W_NDimArray) or
         space.isinstance_w(w_elem, space.w_list)):
         return False
+    if isinstance(w_elem, W_NDimArray) and not w_elem.is_scalar():
+        return False
     return True
 
 def find_shape_and_elems(space, w_iterable, dtype):
@@ -72,7 +73,6 @@
     batch = space.listview(w_iterable)
     is_rec_type = dtype is not None and dtype.is_record_type()
     while True:
-        new_batch = []
         if not batch:
             return shape[:], []
         if is_single_elem(space, batch[0], is_rec_type):
@@ -81,6 +81,7 @@
                     raise OperationError(space.w_ValueError, space.wrap(
                         "setting an array element with a sequence"))
             return shape[:], batch
+        new_batch = []
         size = space.len_w(batch[0])
         for w_elem in batch:
             if (is_single_elem(space, w_elem, is_rec_type) or
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
@@ -455,6 +455,25 @@
         a = array(range(5))
         assert a[3] == 3
 
+    def test_list_of_array_init(self):
+        import numpy as np
+        a = np.array([np.array(True), np.array(False)])
+        assert a.shape == (2,)
+        assert a.dtype == np.bool_
+        assert (a == [True, False]).all()
+        a = np.array([np.array(True), np.array(2)])
+        assert a.shape == (2,)
+        assert a.dtype == np.int_
+        assert (a == [1, 2]).all()
+        a = np.array([np.array(True), np.int_(2)])
+        assert a.shape == (2,)
+        assert a.dtype == np.int_
+        assert (a == [1, 2]).all()
+        a = np.array([np.array([True]), np.array([2])])
+        assert a.shape == (2, 1)
+        assert a.dtype == np.int_
+        assert (a == [[1], [2]]).all()
+
     def test_getitem(self):
         from numpypy import array
         a = array(range(5))
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to