gvsig-3d / 1.10 / trunk / binaries / mac / raster / gdal / GDAL.framework / Versions / 1.7 / Python / site-packages / numpy / core / tests / test_shape_base.py @ 27
History | View | Annotate | Download (4.46 KB)
1 |
from numpy.testing import * |
---|---|
2 |
from numpy.core import array, atleast_1d, atleast_2d, atleast_3d, vstack, \ |
3 |
hstack, newaxis |
4 |
|
5 |
class TestAtleast1d(TestCase): |
6 |
def test_0D_array(self): |
7 |
a = array(1); b = array(2); |
8 |
res=map(atleast_1d,[a,b])
|
9 |
desired = [array([1]),array([2])] |
10 |
assert_array_equal(res,desired) |
11 |
|
12 |
def test_1D_array(self): |
13 |
a = array([1,2]); b = array([2,3]); |
14 |
res=map(atleast_1d,[a,b])
|
15 |
desired = [array([1,2]),array([2,3])] |
16 |
assert_array_equal(res,desired) |
17 |
|
18 |
def test_2D_array(self): |
19 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
20 |
res=map(atleast_1d,[a,b])
|
21 |
desired = [a,b] |
22 |
assert_array_equal(res,desired) |
23 |
|
24 |
def test_3D_array(self): |
25 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
26 |
a = array([a,a]);b = array([b,b]); |
27 |
res=map(atleast_1d,[a,b])
|
28 |
desired = [a,b] |
29 |
assert_array_equal(res,desired) |
30 |
|
31 |
def test_r1array(self): |
32 |
""" Test to make sure equivalent Travis O's r1array function
|
33 |
"""
|
34 |
assert(atleast_1d(3).shape == (1,)) |
35 |
assert(atleast_1d(3j).shape == (1,)) |
36 |
assert(atleast_1d(3L).shape == (1,)) |
37 |
assert(atleast_1d(3.0).shape == (1,)) |
38 |
assert(atleast_1d([[2,3],[4,5]]).shape == (2,2)) |
39 |
|
40 |
class TestAtleast2d(TestCase): |
41 |
def test_0D_array(self): |
42 |
a = array(1); b = array(2); |
43 |
res=map(atleast_2d,[a,b])
|
44 |
desired = [array([[1]]),array([[2]])] |
45 |
assert_array_equal(res,desired) |
46 |
|
47 |
def test_1D_array(self): |
48 |
a = array([1,2]); b = array([2,3]); |
49 |
res=map(atleast_2d,[a,b])
|
50 |
desired = [array([[1,2]]),array([[2,3]])] |
51 |
assert_array_equal(res,desired) |
52 |
|
53 |
def test_2D_array(self): |
54 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
55 |
res=map(atleast_2d,[a,b])
|
56 |
desired = [a,b] |
57 |
assert_array_equal(res,desired) |
58 |
|
59 |
def test_3D_array(self): |
60 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
61 |
a = array([a,a]);b = array([b,b]); |
62 |
res=map(atleast_2d,[a,b])
|
63 |
desired = [a,b] |
64 |
assert_array_equal(res,desired) |
65 |
|
66 |
def test_r2array(self): |
67 |
""" Test to make sure equivalent Travis O's r2array function
|
68 |
"""
|
69 |
assert(atleast_2d(3).shape == (1,1)) |
70 |
assert(atleast_2d([3j,1]).shape == (1,2)) |
71 |
assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2)) |
72 |
|
73 |
|
74 |
class TestAtleast3d(TestCase): |
75 |
def test_0D_array(self): |
76 |
a = array(1); b = array(2); |
77 |
res=map(atleast_3d,[a,b])
|
78 |
desired = [array([[[1]]]),array([[[2]]])] |
79 |
assert_array_equal(res,desired) |
80 |
|
81 |
def test_1D_array(self): |
82 |
a = array([1,2]); b = array([2,3]); |
83 |
res=map(atleast_3d,[a,b])
|
84 |
desired = [array([[[1],[2]]]),array([[[2],[3]]])] |
85 |
assert_array_equal(res,desired) |
86 |
|
87 |
def test_2D_array(self): |
88 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
89 |
res=map(atleast_3d,[a,b])
|
90 |
desired = [a[:,:,newaxis],b[:,:,newaxis]] |
91 |
assert_array_equal(res,desired) |
92 |
|
93 |
def test_3D_array(self): |
94 |
a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); |
95 |
a = array([a,a]);b = array([b,b]); |
96 |
res=map(atleast_3d,[a,b])
|
97 |
desired = [a,b] |
98 |
assert_array_equal(res,desired) |
99 |
|
100 |
class TestHstack(TestCase): |
101 |
def test_0D_array(self): |
102 |
a = array(1); b = array(2); |
103 |
res=hstack([a,b]) |
104 |
desired = array([1,2]) |
105 |
assert_array_equal(res,desired) |
106 |
|
107 |
def test_1D_array(self): |
108 |
a = array([1]); b = array([2]); |
109 |
res=hstack([a,b]) |
110 |
desired = array([1,2]) |
111 |
assert_array_equal(res,desired) |
112 |
|
113 |
def test_2D_array(self): |
114 |
a = array([[1],[2]]); b = array([[1],[2]]); |
115 |
res=hstack([a,b]) |
116 |
desired = array([[1,1],[2,2]]) |
117 |
assert_array_equal(res,desired) |
118 |
|
119 |
class TestVstack(TestCase): |
120 |
def test_0D_array(self): |
121 |
a = array(1); b = array(2); |
122 |
res=vstack([a,b]) |
123 |
desired = array([[1],[2]]) |
124 |
assert_array_equal(res,desired) |
125 |
|
126 |
def test_1D_array(self): |
127 |
a = array([1]); b = array([2]); |
128 |
res=vstack([a,b]) |
129 |
desired = array([[1],[2]]) |
130 |
assert_array_equal(res,desired) |
131 |
|
132 |
def test_2D_array(self): |
133 |
a = array([[1],[2]]); b = array([[1],[2]]); |
134 |
res=vstack([a,b]) |
135 |
desired = array([[1],[2],[1],[2]]) |
136 |
assert_array_equal(res,desired) |
137 |
|
138 |
def test_2D_array2(self): |
139 |
a = array([1,2]); b = array([1,2]); |
140 |
res=vstack([a,b]) |
141 |
desired = array([[1,2],[1,2]]) |
142 |
assert_array_equal(res,desired) |
143 |
|