# HG changeset patch # User Chris Cannam # Date 1367855385 -3600 # Node ID 3f4f3af724b058a844d89b45c13f9f1008ff2150 # Parent 8148422e9102ffea03a5566c36a3bb2be5a9a2f3 Add type declarations for matrix, filter diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/block/block.yeti --- 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, diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/block/blocktype.yeti --- /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[]; + +(); + diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/block/complex.yeti --- 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, diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/matrix/matrix.yeti --- 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, + asColumns is matrix -> list, + sum is matrix -> matrix -> matrix, + product is matrix -> matrix -> matrix, + concat is (Horizontal () | Vertical ()) -> list -> matrix, + rowSlice is number -> number -> matrix -> matrix, + columnSlice is number -> number -> matrix -> matrix, + newMatrix is (ColumnMajor () | RowMajor ()) -> list -> matrix, + newRowVector is block -> matrix, + newColumnVector is block -> matrix, } diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/matrix/matrixtype.yeti --- /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 +}; + +(); + diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/stream/filter.yeti --- 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, + repeated is stream -> stream, } - diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/stream/streamtype.yeti --- 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 () -> (), }; diff -r 8148422e9102 -r 3f4f3af724b0 yetilab/vamp/vamp.yeti --- 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