Mercurial > hg > may
comparison yetilab/matrix/test/test_matrix.yeti @ 243:1313764cb89c sparse
Separate out thresholding from toSparse. Not entirely sure this is a good thing
author | Chris Cannam |
---|---|
date | Mon, 20 May 2013 16:45:34 +0100 |
parents | 0ac8672d12b2 |
children | ce4de16ea65d |
comparison
equal
deleted
inserted
replaced
242:0ac8672d12b2 | 243:1313764cb89c |
---|---|
352 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[1,2,0],[0,5,0]])) (3/6) and | 352 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[1,2,0],[0,5,0]])) (3/6) and |
353 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[1,2,3],[4,5,6]])) (6/6) and | 353 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[1,2,3],[4,5,6]])) (6/6) and |
354 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[0,0,0],[0,0,0]])) 0 | 354 compare (mat.sparsity (newMatrix (ColumnMajor ()) [[0,0,0],[0,0,0]])) 0 |
355 ), | 355 ), |
356 | 356 |
357 "toSparse-\(name)": \( | |
358 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; | |
359 compareMatrices (mat.toSparse m) m and | |
360 compareMatrices (mat.toDense (mat.toSparse m)) m and | |
361 compare (mat.sparsity (mat.toSparse m)) (6/9) | |
362 ), | |
363 | |
364 "toDense-\(name)": \( | |
365 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; | |
366 compareMatrices (mat.toDense m) m and | |
367 compareMatrices (mat.toSparse (mat.toDense m)) m | |
368 ), | |
369 | |
370 "thresholded-\(name)": \( | |
371 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; | |
372 compareMatrices | |
373 (mat.thresholded 2 m) | |
374 (newMatrix (ColumnMajor ()) [[0,0,0],[0,-4,6],[0,0,3]]) and | |
375 compare (mat.sparsity (mat.thresholded 2 m)) (3/9) | |
376 ), | |
377 | |
357 ]); | 378 ]); |
358 | 379 |
359 colhash = makeTests "column-dense" id; | 380 colhash = makeTests "column-dense" id; |
360 rowhash = makeTests "row-dense" mat.flipped; | 381 rowhash = makeTests "row-dense" mat.flipped; |
361 sparsecolhash = makeTests "column-sparse" (mat.toSparse 0); | 382 sparsecolhash = makeTests "column-sparse" mat.toSparse; |
362 | 383 |
363 // there are two possible orders for constructing a sparse row-major | 384 // there are two possible orders for constructing a sparse row-major |
364 // matrix from a dense col-major one, so test them both: | 385 // matrix from a dense col-major one, so test them both: |
365 sparserowhash1 = makeTests "row-sparse-a" ((mat.toSparse 0) . (mat.flipped)); | 386 sparserowhash1 = makeTests "row-sparse-a" (mat.toSparse . mat.flipped); |
366 sparserowhash2 = makeTests "row-sparse-b" ((mat.flipped) . (mat.toSparse 0)); | 387 sparserowhash2 = makeTests "row-sparse-b" (mat.flipped . mat.toSparse); |
367 | 388 |
368 all = [:]; | 389 all = [:]; |
369 for [ colhash, rowhash, sparsecolhash, sparserowhash1, sparserowhash2 ] do h: | 390 for [ colhash, rowhash, sparsecolhash, sparserowhash1, sparserowhash2 ] do h: |
370 for (keys h) do k: all[k] := h[k] done; | 391 for (keys h) do k: all[k] := h[k] done; |
371 done; | 392 done; |