Mercurial > hg > may
changeset 195:3f4f3af724b0
Add type declarations for matrix, filter
author | Chris Cannam |
---|---|
date | Mon, 06 May 2013 16:49:45 +0100 |
parents | 8148422e9102 |
children | dd0be537bd97 |
files | yetilab/block/block.yeti yetilab/block/blocktype.yeti yetilab/block/complex.yeti yetilab/matrix/matrix.yeti yetilab/matrix/matrixtype.yeti yetilab/stream/filter.yeti yetilab/stream/streamtype.yeti yetilab/vamp/vamp.yeti |
diffstat | 8 files changed, 85 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/yetilab/block/block.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/block/block.yeti Mon May 06 16:49:45 2013 +0100 @@ -3,7 +3,7 @@ vec = load yetilab.block.fvector; -typedef opaque block = ~double[]; +load yetilab.block.blocktype; { zeros = vec.zeros,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/block/blocktype.yeti Mon May 06 16:49:45 2013 +0100 @@ -0,0 +1,7 @@ + +module yetilab.block.blocktype; + +typedef opaque block = ~double[]; + +(); +
--- a/yetilab/block/complex.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/block/complex.yeti Mon May 06 16:49:45 2013 +0100 @@ -1,7 +1,9 @@ module yetilab.block.complex; -load yetilab.block.block; +load yetilab.block.blocktype; + +bl = load yetilab.block.block; import java.lang: ClassCastException; @@ -66,10 +68,10 @@ array (map \(complex 0 0) [1..n]); magnitudes cc is list?<~Cplx> -> block = - fromList (map magnitude cc); + bl.fromList (map magnitude cc); angles cc is list?<~Cplx> -> block = - fromList (map angle cc); + bl.fromList (map angle cc); { real,
--- a/yetilab/matrix/matrix.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/matrix/matrix.yeti Mon May 06 16:49:45 2013 +0100 @@ -13,6 +13,9 @@ block = load yetilab.block.block; bf = load yetilab.block.blockfuncs; +load yetilab.block.blocktype; +load yetilab.matrix.matrixtype; + make d = { get data () = d, get size () = @@ -138,10 +141,10 @@ newColumnVector data = //!!! NB does not copy data make (ColM (array [block.data data])); -scaled factor m = +scaled factor m = //!!! v inefficient generate do row col: factor * m.getAt row col done m.size; -resizedTo newsize m = +resizedTo newsize m = //!!! also v inefficient (oldsize = m.size; if newsize == oldsize then m else @@ -234,19 +237,46 @@ fi; { -constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix, -generate, -width, height, -equal, -copyOf, -transposed, -flipped, toRowMajor, toColumnMajor, -scaled, -resizedTo, -asRows, asColumns, -sum = sum', product, -concat, -rowSlice, columnSlice, -newMatrix, newRowVector, newColumnVector, + generate, + constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix, + width, height, + equal, + copyOf, + transposed, + flipped, toRowMajor, toColumnMajor, + scaled, + resizedTo, + asRows, asColumns, + sum = sum', product, + concat, + rowSlice, columnSlice, + newMatrix, newRowVector, newColumnVector, +} as { + generate is (number -> number -> number) -> { .rows is number, .columns is number } -> matrix, + constMatrix is number -> { .rows is number, .columns is number } -> matrix, + randomMatrix is { .rows is number, .columns is number } -> matrix, + zeroMatrix is { .rows is number, .columns is number } -> matrix, + identityMatrix is { .rows is number, .columns is number } -> matrix, + zeroSizeMatrix is () -> matrix, + width is matrix -> number, + height is matrix -> number, + equal is matrix -> matrix -> boolean, + copyOf is matrix -> matrix, + transposed is matrix -> matrix, + flipped is matrix -> matrix, + toRowMajor is matrix -> matrix, + toColumnMajor is matrix -> matrix, + scaled is number -> matrix -> matrix, + resizedTo is { .rows is number, .columns is number } -> matrix -> matrix, + asRows is matrix -> list<block>, + asColumns is matrix -> list<block>, + sum is matrix -> matrix -> matrix, + product is matrix -> matrix -> matrix, + concat is (Horizontal () | Vertical ()) -> list<matrix> -> matrix, + rowSlice is number -> number -> matrix -> matrix, + columnSlice is number -> number -> matrix -> matrix, + newMatrix is (ColumnMajor () | RowMajor ()) -> list<block> -> matrix, + newRowVector is block -> matrix, + newColumnVector is block -> matrix, }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/yetilab/matrix/matrixtype.yeti Mon May 06 16:49:45 2013 +0100 @@ -0,0 +1,17 @@ + +module yetilab.matrix.matrixtype; + +load yetilab.block.blocktype; + +typedef matrix = { + data is RowM array<~double[]> | ColM array<~double[]>, + size is { rows is number, columns is number }, + getColumn is number -> block, + getRow is number -> block, + getAt is number -> number -> number, + setAt is number -> number -> number -> (), + isRowMajor? is boolean +}; + +(); +
--- a/yetilab/stream/filter.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/stream/filter.yeti Mon May 06 16:49:45 2013 +0100 @@ -36,8 +36,6 @@ (n = min count (nsamples - pos); pos := pos + n; if not s.finished? then - fromStream = s.read n; - got = fromStream.size.columns; mat.concat (Horizontal ()) (fromStream :: if got == n then [] @@ -159,10 +157,12 @@ delayedBy, multiplexed, repeated, -//!!!} as { -// withDuration is number -> stream -> stream +} as { + withDuration is number -> stream -> stream, + delayedBy is number -> stream -> stream, + multiplexed is list<stream> -> stream, + repeated is stream -> stream, } -
--- a/yetilab/stream/streamtype.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/stream/streamtype.yeti Mon May 06 16:49:45 2013 +0100 @@ -1,6 +1,8 @@ module yetilab.stream.streamtype; +load yetilab.matrix.matrixtype; + typedef stream = { position is number, @@ -8,7 +10,7 @@ sampleRate is number, available is Known number | Unknown () | Infinite (), finished? is boolean, - read is number -> 'a, // actually a matrix + read is number -> matrix, close is () -> (), };
--- a/yetilab/vamp/vamp.yeti Mon May 06 15:03:22 2013 +0100 +++ b/yetilab/vamp/vamp.yeti Mon May 06 16:49:45 2013 +0100 @@ -235,7 +235,7 @@ //!!! bring block typedef into scope -- this shouldn't be necessary, //but see comment in processed below -load yetilab.block.block; +load yetilab.block.blocktype; processed { p, sampleRate, hop } frames count // I don't know why this type declaration is necessary. Without