Author: mattip
Branch: matrixmath-reshape-merge
Changeset: r50091:131fbfea066a
Date: 2011-12-03 18:24 +0200
http://bitbucket.org/pypy/pypy/changeset/131fbfea066a/
Log: passing more tests
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
@@ -101,7 +101,7 @@
def get_shape_from_iterable(space, old_size, w_iterable):
new_size = 0
new_shape = []
- if not space.issequence_w(w_iterable):
+ if space.isinstance_w(w_iterable, space.w_int):
new_size = space.int_w(w_iterable)
if new_size < 0:
new_size = old_size
@@ -109,6 +109,9 @@
else:
neg_dim = -1
batch = space.listview(w_iterable)
+ #Allow for shape = (1,2,3) or shape = ((1,2,3))
+ if len(batch)>1 and space.issequence_w(batch[0]):
+ batch = space.listview(batch[0])
new_size = 1
if len(batch) < 1:
if old_size ==1:
@@ -875,11 +878,11 @@
return NDimSlice(self, new_sig, start, strides[:], backstrides[:],
shape[:])
- def descr_reshape(self, space, w_iterable):
+ def descr_reshape(self, space, w_args):
"""Return a reshaped view into the original array's data
"""
concrete = self.get_concrete()
- new_shape = get_shape_from_iterable(space, concrete.find_size(),
w_iterable)
+ new_shape = get_shape_from_iterable(space, concrete.find_size(),
w_args)
#Since we got to here, prod(new_shape) == self.size
new_strides = calc_new_strides(new_shape, concrete.shape,
concrete.strides)
if new_strides:
@@ -895,7 +898,7 @@
else:
#Create copy with contiguous data
arr = concrete.copy()
- arr.set_shape(space, new_shape)
+ arr.setshape(space, new_shape)
return arr
def descr_mean(self, space):
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
@@ -209,8 +209,8 @@
assert a[2] == 4
def test_copy(self):
- from numpypy import array
- a = array(range(5))
+ from numpypy import arange, array
+ a = arange(5)
b = a.copy()
for i in xrange(5):
assert b[i] == a[i]
@@ -383,7 +383,7 @@
z=arange(96).reshape((12, -1))
assert z.shape == (12, 8)
- y=z.reshape(4,3,8)
+ y=z.reshape((4,3,8))
v=y[:,::2,:]
w = y.reshape(96)
u = v.reshape(64)
@@ -395,7 +395,13 @@
assert w[41] == 1000
#u is not a view, it is a copy!
assert u[25] == 41
-
+
+ def test_reshape_varargs(self):
+ skip("How do I do varargs in rpython? reshape should accept a"
+ " variable number of arguments")
+ z=arange(96).reshape(12, -1)
+ y=z.reshape(4,3,8)
+
def test_add(self):
from numpypy import array
a = array(range(5))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit