comparison yetilab/matrix/test/test_matrix.yeti @ 210:3a2be6eb8bd3 matrix_opaque_immutable

Finish matrix api conversion compile fixes
author Chris Cannam
date Wed, 08 May 2013 21:10:29 +0100
parents 9bc6070c041c
children 26111c11d8e4
comparison
equal deleted inserted replaced
209:74e0e6dc77a1 210:3a2be6eb8bd3
19 newMatrix t d = flipper (mat.newMatrix t (map block.fromList d)); 19 newMatrix t d = flipper (mat.newMatrix t (map block.fromList d));
20 [ 20 [
21 21
22 "constMatrixEmpty-\(name)": \( 22 "constMatrixEmpty-\(name)": \(
23 m = constMatrix 2 { rows = 0, columns = 0 }; 23 m = constMatrix 2 { rows = 0, columns = 0 };
24 compare m.size { columns = 0, rows = 0 } 24 compare (mat.size m) { columns = 0, rows = 0 }
25 ), 25 ),
26 26
27 "constMatrixEmpty2-\(name)": \( 27 "constMatrixEmpty2-\(name)": \(
28 compare (constMatrix 2 { rows = 0, columns = 4 }).size { columns = 0, rows = 0 } and 28 compare (mat.size (constMatrix 2 { rows = 0, columns = 4 })) { columns = 0, rows = 0 } and
29 compare (constMatrix 2 { rows = 4, columns = 0 }).size { columns = 0, rows = 0 } 29 compare (mat.size (constMatrix 2 { rows = 4, columns = 0 })) { columns = 0, rows = 0 }
30 ), 30 ),
31 31
32 "constMatrix-\(name)": \( 32 "constMatrix-\(name)": \(
33 m = constMatrix 2 { rows = 3, columns = 4 }; 33 m = constMatrix 2 { rows = 3, columns = 4 };
34 compare m.size { columns = 4, rows = 3 } and 34 compare (mat.size m) { columns = 4, rows = 3 } and
35 all id (map do row: compare (block.list (m.getRow row)) [2,2,2,2] done [0..2]) and 35 all id (map do row: compare (block.list (mat.getRow row m)) [2,2,2,2] done [0..2]) and
36 all id (map do col: compare (block.list (m.getColumn col)) [2,2,2] done [0..3]) 36 all id (map do col: compare (block.list (mat.getColumn col m)) [2,2,2] done [0..3])
37 ), 37 ),
38 38
39 "randomMatrixEmpty-\(name)": \( 39 "randomMatrixEmpty-\(name)": \(
40 m = randomMatrix { rows = 0, columns = 0 }; 40 m = randomMatrix { rows = 0, columns = 0 };
41 compare m.size { columns = 0, rows = 0 } 41 compare (mat.size m) { columns = 0, rows = 0 }
42 ), 42 ),
43 43
44 "randomMatrix-\(name)": \( 44 "randomMatrix-\(name)": \(
45 m = randomMatrix { rows = 3, columns = 4 }; 45 m = randomMatrix { rows = 3, columns = 4 };
46 compare m.size { columns = 4, rows = 3 } 46 compare (mat.size m) { columns = 4, rows = 3 }
47 ), 47 ),
48 48
49 "zeroMatrixEmpty-\(name)": \( 49 "zeroMatrixEmpty-\(name)": \(
50 m = zeroMatrix { rows = 0, columns = 0 }; 50 m = zeroMatrix { rows = 0, columns = 0 };
51 compare m.size { columns = 0, rows = 0 } 51 compare (mat.size m) { columns = 0, rows = 0 }
52 ), 52 ),
53 53
54 "zeroMatrix-\(name)": \( 54 "zeroMatrix-\(name)": \(
55 m = zeroMatrix { rows = 3, columns = 4 }; 55 m = zeroMatrix { rows = 3, columns = 4 };
56 compare m.size { columns = 4, rows = 3 } and 56 compare (mat.size m) { columns = 4, rows = 3 } and
57 all id (map do row: compare (block.list (m.getRow row)) [0,0,0,0] done [0..2]) and 57 all id (map do row: compare (block.list (mat.getRow row m)) [0,0,0,0] done [0..2]) and
58 all id (map do col: compare (block.list (m.getColumn col)) [0,0,0] done [0..3]) 58 all id (map do col: compare (block.list (mat.getColumn col m)) [0,0,0] done [0..3])
59 ), 59 ),
60 60
61 "identityMatrixEmpty-\(name)": \( 61 "identityMatrixEmpty-\(name)": \(
62 m = identityMatrix { rows = 0, columns = 0 }; 62 m = identityMatrix { rows = 0, columns = 0 };
63 compare m.size { columns = 0, rows = 0 } 63 compare (mat.size m) { columns = 0, rows = 0 }
64 ), 64 ),
65 65
66 "identityMatrix-\(name)": \( 66 "identityMatrix-\(name)": \(
67 m = identityMatrix { rows = 3, columns = 4 }; 67 m = identityMatrix { rows = 3, columns = 4 };
68 compare m.size { columns = 4, rows = 3 } and 68 compare (mat.size m) { columns = 4, rows = 3 } and
69 all id (map do row: compare (block.list (m.getRow row)) [1,1,1,1] done [0..2]) and 69 all id (map do row: compare (block.list (mat.getRow row m)) [1,1,1,1] done [0..2]) and
70 all id (map do col: compare (block.list (m.getColumn col)) [1,1,1] done [0..3]) 70 all id (map do col: compare (block.list (mat.getColumn col m)) [1,1,1] done [0..3])
71 ), 71 ),
72 72
73 "generateEmpty-\(name)": \( 73 "generateEmpty-\(name)": \(
74 m = generate do row col: 0 done { rows = 0, columns = 0 }; 74 m = generate do row col: 0 done { rows = 0, columns = 0 };
75 compare m.size { columns = 0, rows = 0 } 75 compare (mat.size m) { columns = 0, rows = 0 }
76 ), 76 ),
77 77
78 "generate-\(name)": \( 78 "generate-\(name)": \(
79 m = generate do row col: row * 10 + col done { rows = 2, columns = 3 }; 79 m = generate do row col: row * 10 + col done { rows = 2, columns = 3 };
80 compare (block.list (m.getRow 0)) [0,1,2] and 80 compare (block.list (mat.getRow 0 m)) [0,1,2] and
81 compare (block.list (m.getRow 1)) [10,11,12] 81 compare (block.list (mat.getRow 1 m)) [10,11,12]
82 ), 82 ),
83 83
84 "widthAndHeight-\(name)": \( 84 "widthAndHeight-\(name)": \(
85 m = constMatrix 2 { rows = 3, columns = 4 }; 85 m = constMatrix 2 { rows = 3, columns = 4 };
86 compare m.size { columns = mat.width m, rows = mat.height m } 86 compare (mat.size m) { columns = mat.width m, rows = mat.height m }
87 ), 87 ),
88 88
89 "equal-\(name)": \( 89 "equal-\(name)": \(
90 m = newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]; 90 m = newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]];
91 n = m; 91 n = m;
102 "getAt-\(name)": \( 102 "getAt-\(name)": \(
103 generator row col = row * 10 + col; 103 generator row col = row * 10 + col;
104 m = generate generator { rows = 2, columns = 3 }; 104 m = generate generator { rows = 2, columns = 3 };
105 all id 105 all id
106 (map do row: all id 106 (map do row: all id
107 (map do col: m.getAt row col == generator row col done [0..2]) 107 (map do col: mat.getAt row col m == generator row col done [0..2])
108 done [0..1]) 108 done [0..1])
109 ), 109 ),
110 110
111 "setAt-\(name)": \( 111 "setAt-\(name)": \(
112 generator row col = row * 10 + col; 112 generator row col = row * 10 + col;
113 m = generate generator { rows = 2, columns = 3 }; 113 m = generate generator { rows = 2, columns = 3 };
114 m.setAt 1 2 16; 114 mat.setAt 1 2 16 m;
115 compare (m.getAt 1 2) 16 and 115 compare (mat.getAt 1 2 m) 16 and
116 compare (m.getAt 1 1) 11 and 116 compare (mat.getAt 1 1 m) 11 and
117 compare (m.getAt 0 2) 2 117 compare (mat.getAt 0 2 m) 2
118 ), 118 ),
119 119
120 "copyOfEqual-\(name)": \( 120 "copyOfEqual-\(name)": \(
121 m = constMatrix 2 { rows = 3, columns = 4 }; 121 m = constMatrix 2 { rows = 3, columns = 4 };
122 m'' = mat.copyOf m; 122 m'' = mat.copyOf m;
125 125
126 "copyOfAlias-\(name)": \( 126 "copyOfAlias-\(name)": \(
127 m = constMatrix 2 { rows = 3, columns = 4 }; 127 m = constMatrix 2 { rows = 3, columns = 4 };
128 m' = m; 128 m' = m;
129 m'' = mat.copyOf m; 129 m'' = mat.copyOf m;
130 m.setAt 0 0 6; 130 mat.setAt 0 0 6 m;
131 compareMatrices m' m and not mat.equal m m''; 131 compareMatrices m' m and not mat.equal m m'';
132 ), 132 ),
133 133
134 "transposedEmpty-\(name)": \( 134 "transposedEmpty-\(name)": \(
135 compare (mat.transposed (constMatrix 2 { rows = 0, columns = 0 })).size { columns = 0, rows = 0 } and 135 compare (mat.size (mat.transposed (constMatrix 2 { rows = 0, columns = 0 }))) { columns = 0, rows = 0 } and
136 compare (mat.transposed (constMatrix 2 { rows = 0, columns = 4 })).size { columns = 0, rows = 0 } and 136 compare (mat.size (mat.transposed (constMatrix 2 { rows = 0, columns = 4 }))) { columns = 0, rows = 0 } and
137 compare (mat.transposed (constMatrix 2 { rows = 4, columns = 0 })).size { columns = 0, rows = 0 } 137 compare (mat.size (mat.transposed (constMatrix 2 { rows = 4, columns = 0 }))) { columns = 0, rows = 0 }
138 ), 138 ),
139 139
140 "transposedSize-\(name)": \( 140 "transposedSize-\(name)": \(
141 compare (mat.transposed (constMatrix 2 { rows = 3, columns = 4 })).size { columns = 3, rows = 4 } 141 compare (mat.size (mat.transposed (constMatrix 2 { rows = 3, columns = 4 }))) { columns = 3, rows = 4 }
142 ), 142 ),
143 143
144 "transposed-\(name)": \( 144 "transposed-\(name)": \(
145 generator row col = row * 10 + col; 145 generator row col = row * 10 + col;
146 m = generate generator { rows = 2, columns = 3 }; 146 m = generate generator { rows = 2, columns = 3 };
147 m' = mat.transposed m; 147 m' = mat.transposed m;
148 all id 148 all id
149 (map do row: all id 149 (map do row: all id
150 // like getAt test, but with col/row flipped 150 // like getAt test, but with col/row flipped
151 (map do col: m'.getAt col row == generator row col done [0..2]) 151 (map do col: mat.getAt col row m' == generator row col done [0..2])
152 done [0..1]) 152 done [0..1])
153 ), 153 ),
154 154
155 "transposed-back-\(name)": \( 155 "transposed-back-\(name)": \(
156 m = newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]; 156 m = newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]];