changeset 161:38938ca5db0c

Fix types in Vamp process call
author Chris Cannam
date Wed, 01 May 2013 13:40:03 +0100
parents 97df257b32d3
children 073641eba879
files yetilab/matrix/matrix.yeti yetilab/matrix/test/test_matrix.yeti yetilab/vamp/vamp.yeti
diffstat 3 files changed, 48 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti	Wed May 01 12:43:12 2013 +0100
+++ b/yetilab/matrix/matrix.yeti	Wed May 01 13:40:03 2013 +0100
@@ -98,6 +98,12 @@
             { rows = m.size.columns, columns = m.size.rows });
     fi;
 
+toRowMajor m =
+    if m.isRowMajor? then m else flipped m fi;
+
+toColumnMajor m =
+    if not m.isRowMajor? then m else flipped m fi;
+
 // Matrices with different storage order but the same contents are
 // equal (but comparing them is slow)
 equal m1 m2 =
@@ -161,6 +167,12 @@
         done { rows = m1.size.rows, columns = m2.size.columns }
     fi;
 
+asRows m =
+    map (block.list . m.getRow) [0 .. m.size.rows - 1];
+
+asColumns m =
+    map (block.list . m.getColumn) [0 .. m.size.columns - 1];
+
 {
 constMatrix, randomMatrix, zeroMatrix, identityMatrix, zeroSizeMatrix,
 generate,
@@ -168,9 +180,10 @@
 equal,
 copyOf,
 transposed,
-flipped,
+flipped, toRowMajor, toColumnMajor,
 scaled,
 resizedTo,
+asRows, asColumns,
 sum = sum', product,
 newMatrix, newRowVector, newColumnVector,
 }
--- a/yetilab/matrix/test/test_matrix.yeti	Wed May 01 12:43:12 2013 +0100
+++ b/yetilab/matrix/test/test_matrix.yeti	Wed May 01 13:40:03 2013 +0100
@@ -175,6 +175,24 @@
     compareMatrices (mat.flipped m) (mat.flipped (constMatrix 0 { rows = 0, columns = 0 }));
 ),
 
+"toRowMajor-\(name)": \(
+    m = newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]];
+    m' = mat.toRowMajor m;
+    m'' = newMatrix (RowMajor ()) [[1,2,3],[4,5,6]];
+    m''' = mat.toRowMajor m'';
+    compareMatrices m m' and compareMatrices m m'' and compareMatrices m' m''
+        and compareMatrices m m''';
+),
+
+"toColumnMajor-\(name)": \(
+    m = newMatrix (RowMajor ()) [[1,4],[2,5],[3,6]];
+    m' = mat.toColumnMajor m;
+    m'' = newMatrix (ColumnMajor ()) [[1,2,3],[4,5,6]];
+    m''' = mat.toColumnMajor m'';
+    compareMatrices m m' and compareMatrices m m'' and compareMatrices m' m''
+        and compareMatrices m m''';
+),
+
 "scaled-\(name)": \(
     compareMatrices
        (mat.scaled 0.5 (constMatrix 2 { rows = 3, columns = 4 }))
@@ -246,6 +264,18 @@
        (newMatrix (ColumnMajor ()) [])
 ),
 
+"asRows-\(name)": \(
+    compare
+       (mat.asRows (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]))
+        [[1,2,3],[4,5,6]];
+),
+
+"asColumns-\(name)": \(
+    compare
+       (mat.asColumns (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]))
+        [[1,4],[2,5],[3,6]];
+),
+
 ]);
 
 colhash = makeTests "column-major" id;
--- a/yetilab/vamp/vamp.yeti	Wed May 01 12:43:12 2013 +0100
+++ b/yetilab/vamp/vamp.yeti	Wed May 01 13:40:03 2013 +0100
@@ -13,6 +13,7 @@
 bl = load yetilab.block.block;
 fr = load yetilab.stream.framer;
 af = load yetilab.stream.audiofile;
+mat = load yetilab.matrix.matrix;
 vamprdf = load yetilab.vamp.vamprdf;
 vamppost = load yetilab.vamp.vamppost;
 
@@ -207,8 +208,8 @@
         Some data: map2 outputDescriptor (map Some data.outputs) p#getOutputDescriptors();
         None (): map (outputDescriptor (None ())) p#getOutputDescriptors();
         esac,
-    process blocks time is 'a -> ~RealTime -> 'b = 
-        featureSet p#process((map bl.floats blocks) as ~float[][], 0, time),
+    process frame time is 'a -> ~RealTime -> 'b = 
+        featureSet p#process((mat.asRows frame) as ~float[][], 0, time),
     getRemainingFeatures () = featureSet p#getRemainingFeatures(),
     dispose () = p#dispose(),
     });
@@ -250,7 +251,7 @@
                        }>>> =
     case frames of
     frame::rest:
-        p.process [frame] RealTime#frame2RealTime(count, sampleRate)
+        p.process frame RealTime#frame2RealTime(count, sampleRate)
         :.
         \(processed { p, sampleRate, hop } rest (count + hop));
     _: