Mercurial > hg > may
changeset 187:fd16551c2fc8
Implement and test rowSlice, columnSlice
author | Chris Cannam |
---|---|
date | Sun, 05 May 2013 12:41:42 +0100 |
parents | 479a739c99b1 |
children | 8a8b07134cad |
files | yetilab/matrix/matrix.yeti yetilab/matrix/test/test_matrix.yeti |
diffstat | 2 files changed, 29 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti Sun May 05 12:41:29 2013 +0100 +++ b/yetilab/matrix/matrix.yeti Sun May 05 12:41:42 2013 +0100 @@ -195,7 +195,8 @@ failWith "Matrix dimensions incompatible for concat (found \(map do m: counter m.size done mm) not all of which are \(n))"; fi); -concat direction mm = //!!! storage order is taken from first matrix in sequence +concat direction mm = //!!! doc: storage order is taken from first matrix in sequence + //!!! would this be better as separate concatHorizontal/concatVertical functions? if empty? mm then zeroSizeMatrix () else first = head mm; @@ -217,6 +218,20 @@ esac; fi; +rowSlice start count m = //!!! doc: storage order same as input + if m.isRowMajor? then + make (RowM (array (map (block.data . m.getRow) [start .. start + count - 1]))) + else + make (ColM (array (map (block.data . (block.rangeOf start count)) (asColumns m)))) + fi; + +columnSlice start count m = //!!! doc: storage order same as input + if not m.isRowMajor? then + make (ColM (array (map (block.data . m.getColumn) [start .. start + count - 1]))) + else + make (RowM (array (map (block.data . (block.rangeOf start count)) (asRows m)))) + fi; + { constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix, generate, @@ -230,6 +245,7 @@ asRows, asColumns, sum = sum', product, concat, +rowSlice, columnSlice, newMatrix, newRowVector, newColumnVector, }
--- a/yetilab/matrix/test/test_matrix.yeti Sun May 05 12:41:29 2013 +0100 +++ b/yetilab/matrix/test/test_matrix.yeti Sun May 05 12:41:42 2013 +0100 @@ -316,6 +316,18 @@ yrt ), +"rowSlice-\(name)": \( + compareMatrices + (mat.rowSlice 1 2 (newMatrix (RowMajor ()) [[1,2],[3,4],[5,6],[7,8]])) + (newMatrix (RowMajor ()) [[3,4],[5,6]]) +), + +"columnSlice-\(name)": \( + compareMatrices + (mat.columnSlice 1 2 (newMatrix (RowMajor ()) [[1,2,3,4],[5,6,7,8]])) + (newMatrix (RowMajor ()) [[2,3],[6,7]]) +), + ]); colhash = makeTests "column-major" id;