Mercurial > hg > may
comparison yetilab/matrix/test/test_matrix.yeti @ 257:f00ab8baa6d7
Make sum, difference, scaled and abs use sparse operations and return sparse matrices if all inputs are sparse
author | Chris Cannam |
---|---|
date | Tue, 21 May 2013 22:37:28 +0100 |
parents | 8043f7405eae |
children | f3b7b5d20f88 |
comparison
equal
deleted
inserted
replaced
256:97e97a2e6a4e | 257:f00ab8baa6d7 |
---|---|
213 catch FailureException e: | 213 catch FailureException e: |
214 true | 214 true |
215 yrt | 215 yrt |
216 ), | 216 ), |
217 | 217 |
218 "sparseSum-\(name)": \( | |
219 s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [ | |
220 { i = 0, j = 0, v = 1 }, | |
221 { i = 0, j = 2, v = 2 }, | |
222 { i = 1, j = 1, v = 4 }, | |
223 ]; | |
224 t = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [ | |
225 { i = 0, j = 1, v = 7 }, | |
226 { i = 1, j = 0, v = 5 }, | |
227 { i = 1, j = 1, v = 6 }, | |
228 ]; | |
229 tot = mat.sum s t; | |
230 mat.isSparse? tot and | |
231 compareMatrices tot (mat.sum (mat.toDense s) t) and | |
232 compareMatrices tot (mat.sum (mat.toDense s) (mat.toDense t)) and | |
233 compareMatrices tot (mat.sum s (mat.toDense t)) and | |
234 compareMatrices tot | |
235 (mat.newSparseMatrix (RowMajor ()) { rows = 2, columns = 3 } [ | |
236 { i = 0, j = 0, v = 1 }, | |
237 { i = 0, j = 1, v = 7 }, | |
238 { i = 0, j = 2, v = 2 }, | |
239 { i = 1, j = 0, v = 5 }, | |
240 { i = 1, j = 1, v = 10 }, | |
241 ]) | |
242 ), | |
243 | |
218 "difference-\(name)": \( | 244 "difference-\(name)": \( |
219 compareMatrices | 245 compareMatrices |
220 (mat.difference (constMatrix 2 { rows = 3, columns = 4 }) | 246 (mat.difference (constMatrix 2 { rows = 3, columns = 4 }) |
221 (constMatrix 1 { rows = 3, columns = 4 })) | 247 (constMatrix 1 { rows = 3, columns = 4 })) |
222 (constMatrix 1 { rows = 3, columns = 4 }) | 248 (constMatrix 1 { rows = 3, columns = 4 }) |
228 (constMatrix 1 { rows = 3, columns = 5 })); | 254 (constMatrix 1 { rows = 3, columns = 5 })); |
229 false; | 255 false; |
230 catch FailureException e: | 256 catch FailureException e: |
231 true | 257 true |
232 yrt | 258 yrt |
259 ), | |
260 | |
261 "sparseDifference-\(name)": \( | |
262 s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [ | |
263 { i = 0, j = 0, v = 1 }, | |
264 { i = 0, j = 2, v = 2 }, | |
265 { i = 1, j = 1, v = 4 }, | |
266 ]; | |
267 t = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [ | |
268 { i = 0, j = 1, v = 7 }, | |
269 { i = 1, j = 0, v = 5 }, | |
270 { i = 1, j = 1, v = 6 }, | |
271 ]; | |
272 diff = mat.difference s t; | |
273 mat.isSparse? diff and | |
274 compareMatrices diff (mat.difference (mat.toDense s) t) and | |
275 compareMatrices diff (mat.difference (mat.toDense s) (mat.toDense t)) and | |
276 compareMatrices diff (mat.difference s (mat.toDense t)) and | |
277 compareMatrices diff | |
278 (mat.newSparseMatrix (RowMajor ()) { rows = 2, columns = 3 } [ | |
279 { i = 0, j = 0, v = 1 }, | |
280 { i = 0, j = 1, v = -7 }, | |
281 { i = 0, j = 2, v = 2 }, | |
282 { i = 1, j = 0, v = -5 }, | |
283 { i = 1, j = 1, v = -2 }, | |
284 ]) | |
233 ), | 285 ), |
234 | 286 |
235 "abs-\(name)": \( | 287 "abs-\(name)": \( |
236 compareMatrices | 288 compareMatrices |
237 (mat.abs (newMatrix (ColumnMajor ()) [[-1,4],[2,-5],[-3,0]])) | 289 (mat.abs (newMatrix (ColumnMajor ()) [[-1,4],[2,-5],[-3,0]])) |