Advertisement
Dmitrey15

Untitled

Jan 26th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.23 KB | None | 0 0
  1. $ hg diff test_numeric.py
  2. diff -r 9698baa9d6b5 pypy/module/test_lib_pypy/numpypy/core/test_numeric.py
  3. --- a/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py    Thu Jan 26 19:13:20 2012 +0200
  4. +++ b/pypy/module/test_lib_pypy/numpypy/core/test_numeric.py    Thu Jan 26 21:27:06 2012 +0200
  5. @@ -142,3 +142,77 @@
  6.          assert str(b) == "[7 8 9]"
  7.          b = a[2:1, ]
  8.          assert str(b) == "[]"
  9. +
  10. +class AppTestConcatenation(BaseNumpyAppTest):
  11. +    def test_hstack(self):
  12. +        import numpypy as np
  13. +        a = np.array((1,2,3))
  14. +        b = np.array((2,3,4))
  15. +        assert all(np.hstack((a,b))== np.array([1, 2, 3, 2, 3, 4]))
  16. +        a = np.array([[1],[2],[3]])
  17. +        b = np.array([[2],[3],[4]])
  18. +        assert np.all(np.hstack((a,b)) == np.array([
  19. +                                                    [1, 2],
  20. +                                                    [2, 3],
  21. +                                                    [3, 4]
  22. +                                                    ]))
  23. +        for shape1, shape2 in [[(1, 2), (1, 3)], [(4, 2), [4, 3]]]:
  24. +            a, b = np.ones(shape1), np.ones(shape2)
  25. +            assert np.all(np.hstack((a, b)) == np.ones((a.shape[0], a.shape[1]+b.shape[1])))
  26. +        for shape1, shape2 in [[(2, 3, 4), (2, 7, 4)], [(1, 4, 7), (1, 10, 7)], [(1, 4, 7), (1, 0, 7)], [(1, 0, 7), (1, 0, 7)]]:
  27. +            a, b = np.ones(shape1), np.ones(shape2)
  28. +            assert np.all(np.hstack((a, b)) == np.ones((a.shape[0], a.shape[1]+b.shape[1], a.shape[2])))
  29. +
  30. +    def test_vstack(self):
  31. +        import numpypy as np
  32. +        a = np.array([1, 2, 3])
  33. +        b = np.array([2, 3, 4])
  34. +        assert np.all(np.vstack((a,b)) == np.array([
  35. +                                              [1, 2, 3],
  36. +                                              [2, 3, 4]
  37. +                                              ]))
  38. +                                              
  39. +        a = np.array([[1], [2], [3]])
  40. +        b = np.array([[2], [3], [4]])
  41. +        assert np.all(np.vstack((a,b)) == np.array([
  42. +                                                 [1],
  43. +                                                 [2],
  44. +                                                 [3],
  45. +                                                 [2],
  46. +                                                 [3],
  47. +                                                 [4]
  48. +                                                 ]))
  49. +
  50. +        for shape1, shape2 in [[(2, 1), (3, 1)], [(2, 4), [3, 4]]]:
  51. +            a, b = np.ones(shape1), np.ones(shape2)
  52. +            assert np.all(np.vstack((a, b)) == np.ones((a.shape[0]+b.shape[0], a.shape[1])))
  53. +        for shape1, shape2 in [[(3, 2, 4), (7, 2, 4)], [(0, 2, 7), (10, 2, 7)], [(0, 2, 7), (0, 2, 7)]]:
  54. +            a, b = np.ones(shape1), np.ones(shape2)
  55. +            assert np.all(np.vstack((a, b)) == np.ones((a.shape[0]+b.shape[0], a.shape[1], a.shape[2])))
  56. +
  57. +    def test_dstack(self):
  58. +        import numpypy as np
  59. +        a = np.array((1,2,3))
  60. +        b = np.array((2,3,4))
  61. +        assert np.all(np.dstack((a,b)) == np.array([[
  62. +                                               [1, 2],
  63. +                                               [2, 3],test_stac&ks.py
  64. +                                               [3, 4]
  65. +                                               ]]))
  66. +        a = np.array([[1],[2],[3]])
  67. +        b = np.array([[2],[3],[4]])
  68. +        assert np.all(np.dstack((a,b)) == np.array([
  69. +                                              [[1, 2]],
  70. +                                              [[2, 3]],
  71. +                                              [[3, 4]]
  72. +                                              ]))
  73. +        for shape1, shape2 in [[(4, 2, 3), (4, 2, 7)], [(7, 2, 0), (7, 2, 10)], [(7, 2, 0), (7, 2, 0)]]:
  74. +            a, b = np.ones(shape1), np.ones(shape2)
  75. +            assert np.all(np.dstack((a, b)) == np.ones((a.shape[0], a.shape[1], a.shape[2]+b.shape[2])))
  76. +            
  77. +        for shape1, shape2 in [[(4, 2, 3, 5), (4, 2, 7, 5)], [(7, 2, 0, 5), (7, 2, 10, 5)], [(7, 2, 0, 5), (7, 2, 0, 5)]]:
  78. +            a, b = np.ones(shape1), np.ones(shape2)
  79. +            assert np.all(np.dstack((a, b)) == np.ones((a.shape[0], a.shape[1], a.shape[2]+b.shape[2], a.shape[3])))
  80. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement