# HG changeset patch # User Chris Cannam # Date 1410430271 -3600 # Node ID 7c33308cebf822037b40c137c1acf5dd62b2a66f # Parent 02fba8dc2a92c2496ce1aeb800b5c26192922f8e Make it permissible for mapRows to change the number of columns (if consistent) and mapColumns to change number of rows; test for same diff -r 02fba8dc2a92 -r 7c33308cebf8 src/may/matrix.yeti --- a/src/may/matrix.yeti Thu Sep 11 11:00:58 2014 +0100 +++ b/src/may/matrix.yeti Thu Sep 11 11:11:11 2014 +0100 @@ -968,14 +968,10 @@ fi; mapRows rf 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)))); + fromRows (map rf (asRows m)); mapColumns cf m = - newMatrix (size m) (Columns (map cf (asColumns m))); + fromColumns (map cf (asColumns m)); format m = strJoin "\n" diff -r 02fba8dc2a92 -r 7c33308cebf8 src/may/matrix/test/test_matrix.yeti --- a/src/may/matrix/test/test_matrix.yeti Thu Sep 11 11:00:58 2014 +0100 +++ b/src/may/matrix/test/test_matrix.yeti Thu Sep 11 11:11:11 2014 +0100 @@ -272,6 +272,18 @@ compareMatrices (mat.mapRows (vec.scaled 2) m') m'' ), +"mapRows-extend-\(name)": \( + m = fromRows [[1,4],[0,5],[3,6]]; + m' = mat.mapRows do r: vec.concat [r, r] done m; + compareMatrices m' (mat.concatHorizontal [ m, m ]) +), + +"mapRows-shrink-\(name)": \( + m = fromRows [[1,4],[0,5],[3,6]]; + m' = mat.mapRows do r: vec.resizedTo 1 r done m; + compareMatrices m' (fromRows [[1],[0],[3]]); +), + "mapColumns-\(name)": \( m = fromRows [[1,4],[0,5],[3,6]]; m' = fromColumns [[1,0,3],[4,5,6]]; @@ -280,6 +292,18 @@ compareMatrices (mat.mapColumns (vec.scaled 2) m') m'' ), +"mapColumns-extend-\(name)": \( + m = fromColumns [[1,4],[0,5],[3,6]]; + m' = mat.mapColumns do r: vec.concat [r, r] done m; + compareMatrices m' (mat.concatVertical [ m, m ]) +), + +"mapColumns-shrink-\(name)": \( + m = fromColumns [[1,4],[0,5],[3,6]]; + m' = mat.mapColumns do r: vec.resizedTo 1 r done m; + compareMatrices m' (fromColumns [[1],[0],[3]]); +), + "minValue-\(name)": \( compare (mat.minValue (fromRows [[1,2],[3,4],[5,-1]])) (-1) and compare (mat.minValue (fromRows [[1,2],[3,0],[5,-1]])) (-1) and