comparison yetilab/matrix/test/test_matrix.yeti @ 255:8043f7405eae

Add general enumerate, ensure zeros fed in to makeSparse are not retained in non-zero lists; test
author Chris Cannam
date Tue, 21 May 2013 21:58:34 +0100
parents 9fe3192cce38
children f00ab8baa6d7
comparison
equal deleted inserted replaced
252:efdb1aee9d21 255:8043f7405eae
403 (mat.thresholded 2 m) 403 (mat.thresholded 2 m)
404 (newMatrix (ColumnMajor ()) [[0,0,0],[0,-4,6],[0,0,3]]) and 404 (newMatrix (ColumnMajor ()) [[0,0,0],[0,-4,6],[0,0,3]]) and
405 compare (mat.density (mat.thresholded 2 m)) (3/9) 405 compare (mat.density (mat.thresholded 2 m)) (3/9)
406 ), 406 ),
407 407
408 "newSparseMatrix-\(name)": \(
409 s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [
410 { i = 0, j = 0, v = 1 },
411 { i = 0, j = 2, v = 2 },
412 { i = 1, j = 1, v = 4 },
413 ];
414 // If there are zeros in the entries list, they should not end up
415 // in the sparse data
416 t = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [
417 { i = 0, j = 0, v = 1 },
418 { i = 0, j = 2, v = 0 },
419 { i = 1, j = 1, v = 4 },
420 ];
421 compare (mat.density s) (3/6) and
422 compare (mat.density t) (2/6) and
423 compareMatrices s (newMatrix (RowMajor ()) [[1,0,2],[0,4,0]]) and
424 compareMatrices t (newMatrix (RowMajor ()) [[1,0,0],[0,4,0]])
425 ),
426
427 "enumerate-\(name)": \(
428 m = newMatrix (ColumnMajor ()) [[1,2,0],[-1,-4,6],[0,0,3]];
429 all = [
430 { i = 0, j = 0, v = 1 },
431 { i = 1, j = 0, v = 2 },
432 { i = 2, j = 0, v = 0 },
433 { i = 0, j = 1, v = -1 },
434 { i = 1, j = 1, v = -4 },
435 { i = 2, j = 1, v = 6 },
436 { i = 0, j = 2, v = 0 },
437 { i = 1, j = 2, v = 0 },
438 { i = 2, j = 2, v = 3 },
439 ];
440 sortEntries =
441 sortBy do a b:
442 if a.i == b.i then a.j < b.j else a.i < b.i fi
443 done;
444 compare
445 (sortEntries (mat.enumerate m))
446 (sortEntries
447 (if mat.isSparse? m then filter do d: d.v != 0 done all else all fi));
448 ),
449
408 ]); 450 ]);
409 451
410 colhash = makeTests "column-dense" id; 452 colhash = makeTests "column-dense" id;
411 rowhash = makeTests "row-dense" mat.flipped; 453 rowhash = makeTests "row-dense" mat.flipped;
412 sparsecolhash = makeTests "column-sparse" mat.toSparse; 454 sparsecolhash = makeTests "column-sparse" mat.toSparse;