diff options
Diffstat (limited to 'numpy/f2py/tests')
-rw-r--r-- | numpy/f2py/tests/src/size/foo.f90 | 30 | ||||
-rw-r--r-- | numpy/f2py/tests/test_size.py | 16 |
2 files changed, 46 insertions, 0 deletions
diff --git a/numpy/f2py/tests/src/size/foo.f90 b/numpy/f2py/tests/src/size/foo.f90 index 9602837fe..5b66f8c43 100644 --- a/numpy/f2py/tests/src/size/foo.f90 +++ b/numpy/f2py/tests/src/size/foo.f90 @@ -12,3 +12,33 @@ subroutine foo(a, n, m, b) b(i) = sum(a(i,:)) enddo end subroutine + +subroutine trans(x,y) + implicit none + real, intent(in), dimension(:,:) :: x + real, intent(out), dimension( size(x,2), size(x,1) ) :: y + integer :: N, M, i, j + N = size(x,1) + M = size(x,2) + DO i=1,N + do j=1,M + y(j,i) = x(i,j) + END DO + END DO +end subroutine trans + +subroutine flatten(x,y) + implicit none + real, intent(in), dimension(:,:) :: x + real, intent(out), dimension( size(x) ) :: y + integer :: N, M, i, j, k + N = size(x,1) + M = size(x,2) + k = 1 + DO i=1,N + do j=1,M + y(k) = x(i,j) + k = k + 1 + END DO + END DO +end subroutine flatten diff --git a/numpy/f2py/tests/test_size.py b/numpy/f2py/tests/test_size.py index c00dd9a31..a548e9885 100644 --- a/numpy/f2py/tests/test_size.py +++ b/numpy/f2py/tests/test_size.py @@ -24,6 +24,22 @@ class TestSizeSumExample(util.F2PyTest): r = self.module.foo([[1,2],[3,4],[5,6]]) assert_equal(r, [3,7,11],`r`) + @dec.slow + def test_transpose(self): + r = self.module.trans([[1,2]]) + assert_equal(r, [[1],[2]],`r`) + + r = self.module.trans([[1,2,3],[4,5,6]]) + assert_equal(r, [[1,4],[2,5],[3,6]],`r`) + + @dec.slow + def test_flatten(self): + r = self.module.flatten([[1,2]]) + assert_equal(r, [1,2],`r`) + + r = self.module.flatten([[1,2,3],[4,5,6]]) + assert_equal(r, [1,2,3,4,5,6],`r`) + if __name__ == "__main__": import nose nose.runmodule() |