Mercurial > hg > may
changeset 177:370d9350495c
Start on matrix concat
author | Chris Cannam |
---|---|
date | Thu, 02 May 2013 21:05:10 +0100 |
parents | 344f0fefa00c |
children | 032c4986b6b0 |
files | yetilab/matrix/matrix.yeti yetilab/matrix/test/test_matrix.yeti |
diffstat | 2 files changed, 34 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti Thu May 02 19:09:08 2013 +0100 +++ b/yetilab/matrix/matrix.yeti Thu May 02 21:05:10 2013 +0100 @@ -173,6 +173,31 @@ asColumns m = map m.getColumn [0 .. m.size.columns - 1]; +concatAgainstGrain tagger getter n mm = + make (tagger (array + (map do i: + block.data (block.concat (map do m: getter m i done mm)) + done [0..n-1]))); + +concatWithGrain tagger getter n mm = + make (tagger (array + (concat + (map do m: + map do i: getter m i done [0..n-1] + done mm)))); + +concat direction mm = //!!! storage order is taken from first matrix in sequence + if empty? mm then zeroSizeMatrix () + else + nrows = (head mm).size.rows; + tagger = if (head mm).isRowMajor? then RowM else ColM fi; + if not (all id (map do m: m.size.rows == nrows done mm)) then + failWith "Matrix dimensions incompatible: not all have \(nrows) rows" + else + concatWithGrain tagger (.getRow) nrows mm; + fi + fi; + { constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix, generate, @@ -185,6 +210,7 @@ resizedTo, asRows, asColumns, sum = sum', product, +concat, newMatrix, newRowVector, newColumnVector, }
--- a/yetilab/matrix/test/test_matrix.yeti Thu May 02 19:09:08 2013 +0100 +++ b/yetilab/matrix/test/test_matrix.yeti Thu May 02 21:05:10 2013 +0100 @@ -278,6 +278,14 @@ [[1,4],[2,5],[3,6]]; ), +"concat-lr-\(name)": \( + compareMatrices + (mat.concat (Horizontal ()) + [(newMatrix (ColumnMajor ()) [[1,4],[2,5]]), + (newMatrix (RowMajor ()) [[3],[6]])]) + (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]) +), + ]); colhash = makeTests "column-major" id;