[pypy-commit] pypy default: Add numpypy.transpose() function to call the array method

mikefc noreply at buildbot.pypy.org
Wed Jan 18 00:29:52 CET 2012


Author: mikefc
Branch: 
Changeset: r51429:bc30fb8eed3e
Date: 2012-01-18 09:29 +1000
http://bitbucket.org/pypy/pypy/changeset/bc30fb8eed3e/

Log:	Add numpypy.transpose() function to call the array method

diff --git a/lib_pypy/numpypy/core/fromnumeric.py b/lib_pypy/numpypy/core/fromnumeric.py
--- a/lib_pypy/numpypy/core/fromnumeric.py
+++ b/lib_pypy/numpypy/core/fromnumeric.py
@@ -451,8 +451,11 @@
     (2, 1, 3)
 
     """
-    raise NotImplemented('Waiting on interp level method')
-
+    if axes is not None:
+        raise NotImplementedError('No "axes" arg yet.')
+    if not hasattr(a, 'T'):
+        a = numpypy.array(a)
+    return a.T
 
 def sort(a, axis=-1, kind='quicksort', order=None):
     """
diff --git a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
--- a/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
+++ b/pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py
@@ -125,3 +125,13 @@
         assert reshape(a, (1, -1)).shape == (1, 105)
         assert reshape(a, (1, 1, -1)).shape == (1, 1, 105)
         assert reshape(a, (-1, 1, 1)).shape == (105, 1, 1)
+    
+    def test_transpose(self):   
+        from numpypy import arange, array, transpose, ones
+        x = arange(4).reshape((2,2))
+        assert (transpose(x) == array([[0, 2],[1, 3]])).all()
+        # Once axes argument is implemented, add more tests
+        raises(NotImplementedError, "transpose(x, axes=(1, 0, 2))")
+        # x = ones((1, 2, 3))
+        # assert transpose(x, (1, 0, 2)).shape == (2, 1, 3)
+


More information about the pypy-commit mailing list