Author: mattip
Branch: numpy-monkeyaround
Changeset: r49648:a5ced36cd80a
Date: 2011-11-21 22:53 +0200
http://bitbucket.org/pypy/pypy/changeset/a5ced36cd80a/
Log: add test and implementation for transpose, add test for set_shape
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
@@ -680,6 +680,20 @@
return NDimSlice(self, new_sig, start, shards[:], backshards[:],
shape[:])
+ def descr_get_transpose(self, space):
+ new_sig = signature.Signature.find_sig([
+ NDimSlice.signature, self.signature
+ ])
+ shards = []
+ backshards = []
+ shape = []
+ for i in range(len(self.shape) - 1, -1, -1):
+ shards.append(self.shards[i])
+ backshards.append(self.backshards[i])
+ shape.append(self.shape[i])
+ return space.wrap(NDimSlice(self, new_sig, self.start, shards[:],
+ backshards[:], shape[:]))
+
def descr_mean(self, space):
return space.wrap(space.float_w(self.descr_sum(space)) /
self.find_size())
@@ -1111,6 +1125,8 @@
shape = GetSetProperty(BaseArray.descr_get_shape),
size = GetSetProperty(BaseArray.descr_get_size),
+ T = GetSetProperty(BaseArray.descr_get_transpose),
+
mean = interp2app(BaseArray.descr_mean),
sum = interp2app(BaseArray.descr_sum),
prod = interp2app(BaseArray.descr_prod),
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
@@ -315,6 +315,19 @@
c = a[:3]
assert c.shape == (3,)
+ def test_set_shape(self):
+ from numpypy import arange
+ py.test.skip("shape is immutable for now")
+ a = arange(12)
+ a.shape = (3,4)
+ assert a == [range(4), range(4,8), range(8,12)]
+ a.shape = (3,2,2)
+ assert a[1,1,1] == 7
+ a.shape = (2,-1)
+ assert a == [range(6), range(6,12)]
+ a.shape = 12
+ assert a.shape == (12,)
+
def test_add(self):
from numpypy import array
a = array(range(5))
@@ -901,6 +914,18 @@
b[:] = (a + a)
assert (b == zeros((4, 3, 5))).all()
+ def test_transpose(self):
+ from numpypy import array
+ a = array(((range(3), range(3,6)), (range(6, 9), range(9, 12)),
(range(12, 15), range(15, 18)), (range(18, 21), range(21,24))))
+ assert a.shape == (4 ,2 ,3)
+ b = a.T
+ assert b.shape == (3, 2, 4)
+ assert(b[0, :, 0] == [0, 3]).all()
+ b[:,0,0]=1000
+ assert(a[0,0,:]==[1000,1000,1000]).all()
+
+
+
class AppTestSupport(object):
def setup_class(cls):
import struct
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit