changeset 165:84443da335f9

Add channels tests (some currently failing)
author Chris Cannam
date Wed, 01 May 2013 22:19:36 +0100
parents 4bd7fb9542ff
children 6ffdf5d4dfcf
files yetilab/stream/channels.yeti yetilab/stream/test/test_channels.yeti yetilab/test/all.yeti
diffstat 3 files changed, 100 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/stream/channels.yeti	Wed May 01 21:46:25 2013 +0100
+++ b/yetilab/stream/channels.yeti	Wed May 01 22:19:36 2013 +0100
@@ -7,13 +7,17 @@
         
 interleaved m = 
    ({ columns, rows } = m.size;
-    v = vec.zeros (columns * rows);
-    for [0..rows-1] do row:
-        for [0..columns-1] do col:
-            v[col * rows + row] := m.getAt row col;
+    if rows == 1 then
+        m.getRow 0
+    else
+        v = vec.zeros (columns * rows);
+        for [0..rows-1] do row:
+            for [0..columns-1] do col:
+                v[col * rows + row] := m.getAt row col;
+            done;
         done;
-    done;
-    block.block v);
+        block.block v;
+    fi);
 
 deinterleaved channels b =
     if channels == 1 then
@@ -41,15 +45,19 @@
     block.block v);
 
 mixedDownFromInterleaved channels b =
-   (v = block.data b;
-    columns = ((vec.length v) / channels);
-    v' = vec.zeros columns;
-    for [0..channels-1] do row:
-        for [0..columns-1] do col:
-            v'[col] := v'[col] + v[col * channels + row];
+    if channels == 1 then
+        b;
+    else
+        v = block.data b;
+        columns = ((vec.length v) / channels);
+        v' = vec.zeros columns;
+        for [0..channels-1] do row:
+            for [0..columns-1] do col:
+                v'[col] := v'[col] + v[col * channels + row];
+            done;
         done;
-    done;
-    block.block v');
+        block.block v';
+    fi;
 
 mixedFromInterleavedTo targetChannels channels b = 
     if targetChannels == channels then
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/stream/test/test_channels.yeti	Wed May 01 22:19:36 2013 +0100
@@ -0,0 +1,77 @@
+
+module yetilab.stream.test.test_channels;
+
+ch = load yetilab.stream.channels;
+mat = load yetilab.matrix.matrix;
+bl = load yetilab.block.block;
+
+{ compare, compareUsing } = load yetilab.test.test;
+
+newMatrix data = mat.newMatrix (ColumnMajor ()) (map bl.fromList data);
+
+compareBlocks b1 b2 =
+    compare (bl.list b1) (bl.list b2);
+
+[
+
+"interleaved": \(
+    compareBlocks (ch.interleaved (newMatrix [[1,4],[2,5],[3,6]]))
+       (bl.fromList [1,4,2,5,3,6]) and
+        compareBlocks (ch.interleaved (newMatrix [[1],[2],[3]]))
+           (bl.fromList [1,2,3])
+),
+
+"deinterleaved": \(
+    compareUsing mat.equal (ch.deinterleaved 2 (bl.fromList [1,4,2,5,3,6]))
+       (newMatrix [[1,4],[2,5],[3,6]]) and
+        compareUsing mat.equal (ch.deinterleaved 1 (bl.fromList [1,2,3]))
+           (newMatrix [[1],[2],[3]])
+),
+
+"mixedDown": \(
+    compareBlocks (ch.mixedDown (newMatrix [[1,4],[2,5],[3,6]]))
+       (bl.fromList [5,7,9]) and
+        compareBlocks (ch.mixedDown (newMatrix []))
+           (bl.fromList [])
+),
+
+"mixedDownFromInterleaved": \(
+    compareBlocks (ch.mixedDownFromInterleaved 2 (bl.fromList [1,4,2,5,3,6]))
+       (bl.fromList [5,7,9]) and
+        compareBlocks (ch.mixedDownFromInterleaved 1 (bl.fromList [1,2,3]))
+           (bl.fromList [1,2,3])
+),
+
+"mixedFromInterleavedTo": \(
+    compareBlocks (ch.mixedFromInterleavedTo 1 2 (bl.fromList [1,4,2,5,3,6]))
+       (bl.fromList [5,7,9]) and
+        compareBlocks (ch.mixedFromInterleavedTo 2 2 (bl.fromList [1,4,2,5,3,6]))
+           (bl.fromList [1,4,2,5,3,6]) and
+        compareBlocks (ch.mixedFromInterleavedTo 3 2 (bl.fromList [1,4,2,5,3,6]))
+           (bl.fromList [1,4,0,2,5,0,3,6,0]) and
+        compareBlocks (ch.mixedFromInterleavedTo 1 1 (bl.fromList [1,2,3]))
+           (bl.fromList [1,2,3]) and
+        compareBlocks (ch.mixedFromInterleavedTo 2 1 (bl.fromList [1,2,3]))
+           (bl.fromList [1,1,2,2,3,3]) and
+        compareBlocks (ch.mixedFromInterleavedTo 3 1 (bl.fromList [1,2,3]))
+           (bl.fromList [1,1,0,2,2,0,3,3,0])
+),
+
+"mixedAndInterleavedTo": \(
+    compareBlocks (ch.mixedAndInterleavedTo 1 (newMatrix [[1,4],[2,5],[3,6]]))
+       (bl.fromList [5,7,9]) and
+        compareBlocks (ch.mixedAndInterleavedTo 2 (newMatrix [[1,4],[2,5],[3,6]]))
+           (bl.fromList [1,4,2,5,3,6]) and
+        compareBlocks (ch.mixedAndInterleavedTo 3 (newMatrix [[1,4],[2,5],[3,6]]))
+           (bl.fromList [1,4,0,2,5,0,3,6,0]) and
+        compareBlocks (ch.mixedAndInterleavedTo 1 (newMatrix [[1],[2],[3]]))
+           (bl.fromList [1,2,3]) and
+        compareBlocks (ch.mixedAndInterleavedTo 2 (newMatrix [[1],[2],[3]]))
+           (bl.fromList [1,1,2,2,3,3]) and
+        compareBlocks (ch.mixedAndInterleavedTo 3 (newMatrix [[1],[2],[3]]))
+           (bl.fromList [1,1,0,2,2,0,3,3,0])
+),
+
+] is hash<string, () -> boolean>;
+
+
--- a/yetilab/test/all.yeti	Wed May 01 21:46:25 2013 +0100
+++ b/yetilab/test/all.yeti	Wed May 01 22:19:36 2013 +0100
@@ -8,6 +8,7 @@
 "blockfuncs" : load yetilab.block.test.test_blockfuncs,
 "complex"    : load yetilab.block.test.test_complex,
 "framer"     : load yetilab.stream.test.test_framer,
+"channels"   : load yetilab.stream.test.test_channels,
 "fft"        : load yetilab.transform.test.test_fft,
 "vamppost"   : load yetilab.vamp.test.test_vamppost,
 "vamp"       : load yetilab.vamp.test.test_vamp,