comparison yetilab/matrix/test/test_matrix.yeti @ 258:f3b7b5d20f88

Replace matrix thresholded with a more general filter function that works for sparse matrices too
author Chris Cannam
date Wed, 22 May 2013 08:56:51 +0100
parents f00ab8baa6d7
children fae62dca8048
comparison
equal deleted inserted replaced
257:f00ab8baa6d7 258:f3b7b5d20f88
447 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; 447 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]];
448 compareMatrices (mat.toDense m) m and 448 compareMatrices (mat.toDense m) m and
449 compareMatrices (mat.toSparse (mat.toDense m)) m 449 compareMatrices (mat.toSparse (mat.toDense m)) m
450 ), 450 ),
451 451
452 "thresholded-\(name)": \( 452 "filter-\(name)": \(
453 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]]; 453 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]];
454 compareMatrices 454 compareMatrices
455 (mat.thresholded 2 m) 455 (mat.filter (> 2) m)
456 (newMatrix (ColumnMajor ()) [[0,0,0],[0,-4,6],[0,0,3]]) and 456 (newMatrix (ColumnMajor ()) [[0,0,0],[0,0,6],[0,0,3]]) and
457 compare (mat.density (mat.thresholded 2 m)) (3/9) 457 compare (mat.density (mat.filter (> 2) m)) (2/9)
458 ), 458 ),
459 459
460 "newSparseMatrix-\(name)": \( 460 "newSparseMatrix-\(name)": \(
461 s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [ 461 s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [
462 { i = 0, j = 0, v = 1 }, 462 { i = 0, j = 0, v = 1 },