[pypy-commit] pypy numpy-refactor: transpose
fijal
noreply at buildbot.pypy.org
Thu Aug 30 19:45:17 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-refactor
Changeset: r57024:d4cad2a3a4e5
Date: 2012-08-30 17:50 +0200
http://bitbucket.org/pypy/pypy/changeset/d4cad2a3a4e5/
Log: transpose
diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -184,6 +184,19 @@
view = chunks.apply(self)
view.setslice(space, w_value)
+ def transpose(self):
+ if len(self.shape) < 2:
+ return self
+ 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 SliceArray(self.start, strides,
+ backstrides, shape, self)
+
class SliceArray(ConcreteArray):
def __init__(self, start, strides, backstrides, shape, parent):
self.strides = strides
diff --git a/pypy/module/micronumpy/arrayimpl/scalar.py b/pypy/module/micronumpy/arrayimpl/scalar.py
--- a/pypy/module/micronumpy/arrayimpl/scalar.py
+++ b/pypy/module/micronumpy/arrayimpl/scalar.py
@@ -44,4 +44,6 @@
def get_size(self):
return 1
-
+
+ def transpose(self):
+ return self
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
@@ -129,6 +129,10 @@
arr.implementation = arr.implementation.reshape(space, new_shape)
return arr
+ def descr_get_transpose(self, space):
+ arr = instantiate(W_NDimArray)
+ arr.implementation = self.implementation.transpose()
+ return arr
# --------------------- binary operations ----------------------------
@@ -240,6 +244,7 @@
copy = interp2app(W_NDimArray.descr_copy),
reshape = interp2app(W_NDimArray.descr_reshape),
+ T = GetSetProperty(W_NDimArray.descr_get_transpose),
)
def decode_w_dtype(space, w_dtype):
More information about the pypy-commit
mailing list