Mercurial > hg > may
diff yetilab/matrix/matrix.yeti @ 158:b6db07468ed1
Rework stream to support indefinite-length streams and handle multiple channels in framer. Make compile, but some tests fail (and others are still missing).
author | Chris Cannam |
---|---|
date | Wed, 01 May 2013 12:03:45 +0100 |
parents | 2bc6534248fe |
children | a9d58d9c71ca |
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti Wed May 01 07:58:39 2013 +0100 +++ b/yetilab/matrix/matrix.yeti Wed May 01 12:03:45 2013 +0100 @@ -45,7 +45,7 @@ RowM rows: r = rows[row]; (r is ~double[])[col]; ColM cols: c = cols[col]; (c is ~double[])[row]; esac, - setAt row col n = + setAt row col n = //!!! dangerous, could modify copies -- should it be allowed? case d of RowM rows: r = rows[row]; (r is ~double[])[col] := n; ColM cols: c = cols[col]; (c is ~double[])[row] := n; @@ -77,6 +77,7 @@ constMatrix n = generate do row col: n done; randomMatrix = generate do row col: Math#random() done; identityMatrix = constMatrix 1; +zeroSizeMatrix () = zeroMatrix { rows = 0, columns = 0 }; width m = m.size.columns; height m = m.size.rows; @@ -134,6 +135,16 @@ scaled factor m = generate do row col: factor * m.getAt row col done m.size; +resizedTo newsize m = + (oldsize = m.size; + if newsize == oldsize then m + else + generate do row col: + if row < oldsize.rows and col < oldsize.columns + then m.getAt row col else 0 fi + done newsize; + fi); + sum' m1 m2 = if m1.size != m2.size then failWith "Matrices are not the same size: \(m1.size), \(m2.size)"; @@ -151,7 +162,7 @@ fi; { -constMatrix, randomMatrix, zeroMatrix, identityMatrix, +constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix, generate, width, height, equal, @@ -159,6 +170,7 @@ transposed, flipped, scaled, +resizedTo, sum = sum', product, newMatrix, newRowVector, newColumnVector, }