Mercurial > hg > may
changeset 588:28871ec9e4a9
Some newMatrix tests (some currently failing). And, should mapRows/mapColumns be allowed to (coherently) change the matrix size?
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 08:18:45 +0100 |
parents | b50912d6d72b |
children | 02fba8dc2a92 |
files | src/may/matrix.yeti src/may/matrix/test/test_matrix.yeti |
diffstat | 2 files changed, 62 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/may/matrix.yeti Mon Jul 28 21:18:19 2014 +0100 +++ b/src/may/matrix.yeti Thu Sep 11 08:18:45 2014 +0100 @@ -213,9 +213,9 @@ case d of Rows rr: if (length rr) != size.rows then - failWith "Wrong number of rows in row-major newMatrix (\(length rr), size calls for \(size.rows)"; + failWith "Wrong number of rows in row-major newMatrix (\(length rr), size calls for \(size.rows))"; elif not empty? rr and vec.length (head rr) != size.columns then - failWith "Wrong number of columns in row-major newMatrix (\(vec.length (head rr)), size calls for \(size.columns)"; + failWith "Wrong number of columns in row-major newMatrix (\(vec.length (head rr)), size calls for \(size.columns))"; else { size, @@ -224,9 +224,9 @@ fi; Columns cc: if (length cc) != size.columns then - failWith "Wrong number of columns in column-major newMatrix (\(length cc), size calls for \(size.columns)"; + failWith "Wrong number of columns in column-major newMatrix (\(length cc), size calls for \(size.columns))"; elif not empty? cc and vec.length (head cc) != size.rows then - failWith "Wrong number of rows in column-major newMatrix (\(vec.length (head cc)), size calls for \(size.rows)"; + failWith "Wrong number of rows in column-major newMatrix (\(vec.length (head cc)), size calls for \(size.rows))"; else { size, @@ -968,7 +968,11 @@ fi; mapRows rf m = - newMatrix (size m) (Rows (map rf (asRows m))); + (rows = map rf (asRows m); + if not empty? rows and vec.length (head rows) != width m then + failWith "Map function changes row length in mapRows: from \(width m) to \(vec.length (head rows))"; + fi; + newMatrix (size m) (Rows (map rf (asRows m)))); mapColumns cf m = newMatrix (size m) (Columns (map cf (asColumns m)));
--- a/src/may/matrix/test/test_matrix.yeti Mon Jul 28 21:18:19 2014 +0100 +++ b/src/may/matrix/test/test_matrix.yeti Thu Sep 11 08:18:45 2014 +0100 @@ -16,6 +16,7 @@ randomMatrix s = flipper (mat.randomMatrix s); identityMatrix s = flipper (mat.identityMatrix s); generate f s = flipper (mat.generate f s); + newMatrix s data = flipper (mat.newMatrix s data); fromRows d = flipper (mat.fromRows (map vec.fromList d)); fromColumns d = flipper (mat.fromColumns (map vec.fromList d)); [ @@ -95,6 +96,58 @@ compare (mat.size m) { columns = mat.width m, rows = mat.height m } ), +"newMatrix-rows-\(name)": \( + rowc rr = Rows (map vec.fromList rr); + m1 = newMatrix { rows = 0, columns = 0 } (rowc []); + m2 = newMatrix { rows = 2, columns = 0 } (rowc [[],[]]); + m3 = newMatrix { rows = 3, columns = 2 } (rowc [[1,2],[3,4],[5,6]]); + compare (mat.size m1) { rows = 0, columns = 0 } and + compare (mat.size m2) { rows = 2, columns = 0 } and + compare (mat.size m3) { rows = 3, columns = 2 } and + compareMatrices m3 (fromRows [[1,2],[3,4],[5,6]]); +), + +"newMatrix-columns-\(name)": \( + colc cc = Columns (map vec.fromList cc); + m1 = newMatrix { rows = 0, columns = 0 } (colc []); + m2 = newMatrix { rows = 0, columns = 2 } (colc [[],[]]); + m3 = newMatrix { rows = 2, columns = 3 } (colc [[1,2],[3,4],[5,6]]); + compare (mat.size m1) { rows = 0, columns = 0 } and + compare (mat.size m2) { rows = 0, columns = 2 } and + compare (mat.size m3) { rows = 2, columns = 3 } and + compareMatrices m3 (fromColumns [[1,2],[3,4],[5,6]]); +), + +"newMatrix-fail-\(name)": \( + rowc rr = Rows (map vec.fromList rr); + colc cc = Columns (map vec.fromList cc); + all id + (map do t: + try + \() (t ()); + false; + catch FailureException e: + true; + yrt + done + [ + \(newMatrix { rows = 0, columns = 0 } (rowc [[]])), + \(newMatrix { rows = 0, columns = 0 } (colc [[]])), + \(newMatrix { rows = 2, columns = 0 } (rowc [[]])), + \(newMatrix { rows = 0, columns = 2 } (colc [[]])), + \(newMatrix { rows = 2, columns = 2 } (rowc [[],[]])), + \(newMatrix { rows = 2, columns = 2 } (colc [[],[]])), + \(newMatrix { rows = 2, columns = 3 } (rowc [[1,2],[3,4,5]])), + \(newMatrix { rows = 3, columns = 2 } (colc [[1,2],[3,4,5]])), + \(newMatrix { rows = 2, columns = 3 } (rowc [[1,2,3],[4,5]])), + \(newMatrix { rows = 3, columns = 2 } (colc [[1,2,3],[4,5]])), + \(newMatrix { rows = 2, columns = 3 } (rowc [[1,2,3],[4,5,6],[7,8,9]])), + \(newMatrix { rows = 3, columns = 2 } (colc [[1,2,3],[4,5,6],[7,8,9]])), + \(newMatrix { rows = 2, columns = 3 } (rowc [[1,2,3]])), + \(newMatrix { rows = 3, columns = 2 } (colc [[1,2,3]])) + ]); +), + "equal-\(name)": \( m = fromColumns [[1,4],[0,5],[3,6]]; n = m;