[pypy-commit] pypy matrixmath: tests, implementation of transpose
mattip
noreply at buildbot.pypy.org
Fri Nov 25 08:35:05 CET 2011
Author: mattip
Branch: matrixmath
Changeset: r49776:cdef93e5ffca
Date: 2011-11-25 09:04 +0200
http://bitbucket.org/pypy/pypy/changeset/cdef93e5ffca/
Log: tests, implementation of transpose
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
@@ -757,6 +757,20 @@
return space.wrap(space.is_true(self.get_concrete().eval(
self.start_iter(self.shape)).wrap(space)))
+ def descr_get_transpose(self, space):
+ new_sig = signature.Signature.find_sig([
+ NDimSlice.signature, self.signature
+ ])
+ strides = []
+ backstrides = []
+ shape = []
+ for i in range(len(self.shape) - 1, -1, -1):
+ strides.append(self.strides[i])
+ backstrides.append(self.backstrides[i])
+ shape.append(self.shape[i])
+ return space.wrap(NDimSlice(self, new_sig, self.start, strides[:],
+ backstrides[:], shape[:]))
+
def getitem(self, item):
raise NotImplementedError
@@ -1162,6 +1176,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
@@ -934,6 +934,19 @@
c = b + b
assert c.sum() == (6 + 8 + 10 + 12) * 2
+ 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):
More information about the pypy-commit
mailing list