[pypy-commit] pypy numpy-fixes: test, fix array(<non-contiguous ndarray>)
mattip
noreply at buildbot.pypy.org
Thu Apr 30 22:12:05 CEST 2015
Author: mattip <matti.picus at gmail.com>
Branch: numpy-fixes
Changeset: r76956:80fe68674c7a
Date: 2015-04-30 04:03 +0300
http://bitbucket.org/pypy/pypy/changeset/80fe68674c7a/
Log: test, fix array(<non-contiguous ndarray>)
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
@@ -124,12 +124,13 @@
copy = True
if copy:
shape = w_object.get_shape()
- elems_w = [None] * w_object.get_size()
- elsize = w_object.get_dtype().elsize
- # TODO - use w_object.implementation without copying to a list
- # unfortunately that causes a union error in translation
- for i in range(w_object.get_size()):
- elems_w[i] = w_object.implementation.getitem(i * elsize)
+ w_arr = W_NDimArray.from_shape(space, shape, dtype, order=order)
+ if support.product(shape) == 1:
+ w_arr.set_scalar_value(dtype.coerce(space,
+ w_object.implementation.getitem(0)))
+ else:
+ loop.setslice(space, shape, w_arr.implementation, w_object.implementation)
+ return w_arr
else:
imp = w_object.implementation
with imp as storage:
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -237,7 +237,7 @@
assert np.WRAP is 1
assert np.RAISE is 2
- def test_ndarray(self):
+ def test_creation(self):
from numpy import ndarray, array, dtype, flatiter
assert type(ndarray) is type
@@ -269,6 +269,12 @@
assert a.flags['C']
assert not a.flags['F']
+ x = array([[0, 2], [1, 1], [2, 0]])
+ y = array(x.T, dtype=float)
+ assert (y == x.T).all()
+ y = array(x.T, copy=False)
+ assert (y == x.T).all()
+
def test_ndmin(self):
from numpy import array
More information about the pypy-commit
mailing list