Mercurial > hg > may
diff 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 |
line wrap: on
line diff
--- a/yetilab/matrix/test/test_matrix.yeti Mon May 20 16:22:17 2013 +0100 +++ b/yetilab/matrix/test/test_matrix.yeti Mon May 20 16:45:34 2013 +0100 @@ -354,16 +354,37 @@ compare (mat.sparsity (newMatrix (ColumnMajor ()) [[0,0,0],[0,0,0]])) 0 ), +"toSparse-\(name)": \( + m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; + compareMatrices (mat.toSparse m) m and + compareMatrices (mat.toDense (mat.toSparse m)) m and + compare (mat.sparsity (mat.toSparse m)) (6/9) +), + +"toDense-\(name)": \( + m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; + compareMatrices (mat.toDense m) m and + compareMatrices (mat.toSparse (mat.toDense m)) m +), + +"thresholded-\(name)": \( + m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; + compareMatrices + (mat.thresholded 2 m) + (newMatrix (ColumnMajor ()) [[0,0,0],[0,-4,6],[0,0,3]]) and + compare (mat.sparsity (mat.thresholded 2 m)) (3/9) +), + ]); colhash = makeTests "column-dense" id; rowhash = makeTests "row-dense" mat.flipped; -sparsecolhash = makeTests "column-sparse" (mat.toSparse 0); +sparsecolhash = makeTests "column-sparse" mat.toSparse; // there are two possible orders for constructing a sparse row-major // matrix from a dense col-major one, so test them both: -sparserowhash1 = makeTests "row-sparse-a" ((mat.toSparse 0) . (mat.flipped)); -sparserowhash2 = makeTests "row-sparse-b" ((mat.flipped) . (mat.toSparse 0)); +sparserowhash1 = makeTests "row-sparse-a" (mat.toSparse . mat.flipped); +sparserowhash2 = makeTests "row-sparse-b" (mat.flipped . mat.toSparse); all = [:]; for [ colhash, rowhash, sparsecolhash, sparserowhash1, sparserowhash2 ] do h: