# HG changeset patch # User Chris Cannam # Date 1367754102 -3600 # Node ID fd16551c2fc85afcfd5de3e77e6bffebb57d04f5 # Parent 479a739c99b148adc8ff9f8745ba4376fdcb741f Implement and test rowSlice, columnSlice diff -r 479a739c99b1 -r fd16551c2fc8 yetilab/matrix/matrix.yeti --- 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, } diff -r 479a739c99b1 -r fd16551c2fc8 yetilab/matrix/test/test_matrix.yeti --- 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;