[pypy-commit] pypy default: test, fix and start to optimize a=np.array(b) where b is a ndarray subtype
mattip
noreply at buildbot.pypy.org
Mon Feb 2 08:22:59 CET 2015
Author: mattip <matti.picus at gmail.com>
Branch:
Changeset: r75638:a0d3e64efd8b
Date: 2015-02-02 09:23 +0200
http://bitbucket.org/pypy/pypy/changeset/a0d3e64efd8b/
Log: test, fix and start to optimize a=np.array(b) where b is a ndarray
subtype
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -82,9 +82,18 @@
return w_object.descr_copy(space, w_order)
elif not copy and (subok or type(w_object) is W_NDimArray):
return w_object
-
- # not an array or incorrect dtype
- shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
+ if isinstance(w_object, W_NDimArray) and copy and not subok:
+ # TODO do the loop.assign without copying elems_w
+ shape = w_object.get_shape()
+ _elems_w = w_object.reshape(space, space.wrap(-1))
+ elems_w = [None] * w_object.get_size()
+ for i in range(len(elems_w)):
+ elems_w[i] = _elems_w.descr_getitem(space, space.wrap(i))
+ if space.is_none(w_dtype):
+ dtype = w_object.get_dtype()
+ else:
+ # not an array
+ shape, elems_w = strides.find_shape_and_elems(space, w_object, dtype)
if dtype is None or (dtype.is_str_or_unicode() and dtype.elsize < 1):
dtype = strides.find_dtype_for_seq(space, elems_w, dtype)
if dtype is None:
diff --git a/pypy/module/micronumpy/test/test_subtype.py b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -304,10 +304,13 @@
out.shape = (sh, 1)
else:
out.shape = (1, sh)
- print 'out, shape was',old_shape,'now',out.shape
+ #print 'out, shape was',old_shape,'now',out.shape,'out',out
return out
- a = matrix([[1., 2.]])
+ a = matrix([[1., 2.], [3., 4.]])
b = N.array([a])
+ assert (b == a).all()
+ b = N.array(a)
+ assert len(b.shape) == 2
def test_setstate_no_version(self):
# Some subclasses of ndarray, like MaskedArray, do not use
More information about the pypy-commit
mailing list