changeset 210:3a2be6eb8bd3 matrix_opaque_immutable

Finish matrix api conversion compile fixes
author Chris Cannam
date Wed, 08 May 2013 21:10:29 +0100
parents 74e0e6dc77a1
children 8e79cf8a4399
files yetilab/matrix/test/test_matrix.yeti yetilab/stream/channels.yeti yetilab/stream/filter.yeti yetilab/stream/framer.yeti yetilab/stream/test/test_audiofile.yeti yetilab/stream/test/test_filter.yeti yetilab/stream/test/test_syntheticstream.yeti
diffstat 7 files changed, 76 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/matrix/test/test_matrix.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/matrix/test/test_matrix.yeti	Wed May 08 21:10:29 2013 +0100
@@ -21,69 +21,69 @@
 
 "constMatrixEmpty-\(name)": \(
     m = constMatrix 2 { rows = 0, columns = 0 };
-    compare m.size { columns = 0, rows = 0 }
+    compare (mat.size m) { columns = 0, rows = 0 }
 ),
 
 "constMatrixEmpty2-\(name)": \(
-    compare (constMatrix 2 { rows = 0, columns = 4 }).size { columns = 0, rows = 0 } and
-        compare (constMatrix 2 { rows = 4, columns = 0 }).size { columns = 0, rows = 0 }
+    compare (mat.size (constMatrix 2 { rows = 0, columns = 4 })) { columns = 0, rows = 0 } and
+        compare (mat.size (constMatrix 2 { rows = 4, columns = 0 })) { columns = 0, rows = 0 }
 ),
 
 "constMatrix-\(name)": \(
     m = constMatrix 2 { rows = 3, columns = 4 };
-    compare m.size { columns = 4, rows = 3 } and
-        all id (map do row: compare (block.list (m.getRow row)) [2,2,2,2] done [0..2]) and
-        all id (map do col: compare (block.list (m.getColumn col)) [2,2,2] done [0..3])
+    compare (mat.size m) { columns = 4, rows = 3 } and
+        all id (map do row: compare (block.list (mat.getRow row m)) [2,2,2,2] done [0..2]) and
+        all id (map do col: compare (block.list (mat.getColumn col m)) [2,2,2] done [0..3])
 ),
 
 "randomMatrixEmpty-\(name)": \(
     m = randomMatrix { rows = 0, columns = 0 };
-    compare m.size { columns = 0, rows = 0 }
+    compare (mat.size m) { columns = 0, rows = 0 }
 ),
 
 "randomMatrix-\(name)": \(
     m = randomMatrix { rows = 3, columns = 4 };
-    compare m.size { columns = 4, rows = 3 }
+    compare (mat.size m) { columns = 4, rows = 3 }
 ),
 
 "zeroMatrixEmpty-\(name)": \(
     m = zeroMatrix { rows = 0, columns = 0 };
-    compare m.size { columns = 0, rows = 0 }
+    compare (mat.size m) { columns = 0, rows = 0 }
 ),
 
 "zeroMatrix-\(name)": \(
     m = zeroMatrix { rows = 3, columns = 4 };
-    compare m.size { columns = 4, rows = 3 } and
-        all id (map do row: compare (block.list (m.getRow row)) [0,0,0,0] done [0..2]) and
-        all id (map do col: compare (block.list (m.getColumn col)) [0,0,0] done [0..3])
+    compare (mat.size m) { columns = 4, rows = 3 } and
+        all id (map do row: compare (block.list (mat.getRow row m)) [0,0,0,0] done [0..2]) and
+        all id (map do col: compare (block.list (mat.getColumn col m)) [0,0,0] done [0..3])
 ),
 
 "identityMatrixEmpty-\(name)": \(
     m = identityMatrix { rows = 0, columns = 0 };
-    compare m.size { columns = 0, rows = 0 }
+    compare (mat.size m) { columns = 0, rows = 0 }
 ),
 
 "identityMatrix-\(name)": \(
     m = identityMatrix { rows = 3, columns = 4 };
-    compare m.size { columns = 4, rows = 3 } and
-        all id (map do row: compare (block.list (m.getRow row)) [1,1,1,1] done [0..2]) and
-        all id (map do col: compare (block.list (m.getColumn col)) [1,1,1] done [0..3])
+    compare (mat.size m) { columns = 4, rows = 3 } and
+        all id (map do row: compare (block.list (mat.getRow row m)) [1,1,1,1] done [0..2]) and
+        all id (map do col: compare (block.list (mat.getColumn col m)) [1,1,1] done [0..3])
 ),
 
 "generateEmpty-\(name)": \(
     m = generate do row col: 0 done { rows = 0, columns = 0 };
-    compare m.size { columns = 0, rows = 0 }
+    compare (mat.size m) { columns = 0, rows = 0 }
 ),
 
 "generate-\(name)": \(
     m = generate do row col: row * 10 + col done { rows = 2, columns = 3 };
-    compare (block.list (m.getRow 0)) [0,1,2] and
-        compare (block.list (m.getRow 1)) [10,11,12]
+    compare (block.list (mat.getRow 0 m)) [0,1,2] and
+        compare (block.list (mat.getRow 1 m)) [10,11,12]
 ),
 
 "widthAndHeight-\(name)": \(
     m = constMatrix 2 { rows = 3, columns = 4 };
-    compare m.size { columns = mat.width m, rows = mat.height m }
+    compare (mat.size m) { columns = mat.width m, rows = mat.height m }
 ),
 
 "equal-\(name)": \(
@@ -104,17 +104,17 @@
     m = generate generator { rows = 2, columns = 3 };
     all id
        (map do row: all id
-           (map do col: m.getAt row col == generator row col done [0..2])
+           (map do col: mat.getAt row col m == generator row col done [0..2])
             done [0..1])
 ),
 
 "setAt-\(name)": \(
     generator row col = row * 10 + col;
     m = generate generator { rows = 2, columns = 3 };
-    m.setAt 1 2 16;
-    compare (m.getAt 1 2) 16 and
-        compare (m.getAt 1 1) 11 and
-        compare (m.getAt 0 2) 2
+    mat.setAt 1 2 16 m;
+    compare (mat.getAt 1 2 m) 16 and
+        compare (mat.getAt 1 1 m) 11 and
+        compare (mat.getAt 0 2 m) 2
 ),
 
 "copyOfEqual-\(name)": \(
@@ -127,18 +127,18 @@
     m = constMatrix 2 { rows = 3, columns = 4 };
     m' = m;
     m'' = mat.copyOf m;
-    m.setAt 0 0 6;
+    mat.setAt 0 0 6 m;
     compareMatrices m' m and not mat.equal m m'';
 ),
 
 "transposedEmpty-\(name)": \(
-    compare (mat.transposed (constMatrix 2 { rows = 0, columns = 0 })).size { columns = 0, rows = 0 } and
-        compare (mat.transposed (constMatrix 2 { rows = 0, columns = 4 })).size { columns = 0, rows = 0 } and
-        compare (mat.transposed (constMatrix 2 { rows = 4, columns = 0 })).size { columns = 0, rows = 0 }
+    compare (mat.size (mat.transposed (constMatrix 2 { rows = 0, columns = 0 }))) { columns = 0, rows = 0 } and
+        compare (mat.size (mat.transposed (constMatrix 2 { rows = 0, columns = 4 }))) { columns = 0, rows = 0 } and
+        compare (mat.size (mat.transposed (constMatrix 2 { rows = 4, columns = 0 }))) { columns = 0, rows = 0 }
 ),
 
 "transposedSize-\(name)": \(
-    compare (mat.transposed (constMatrix 2 { rows = 3, columns = 4 })).size { columns = 3, rows = 4 }
+    compare (mat.size (mat.transposed (constMatrix 2 { rows = 3, columns = 4 }))) { columns = 3, rows = 4 }
 ),
 
 "transposed-\(name)": \(
@@ -148,7 +148,7 @@
     all id
        (map do row: all id
            // like getAt test, but with col/row flipped
-           (map do col: m'.getAt col row == generator row col done [0..2])
+           (map do col: mat.getAt col row m' == generator row col done [0..2])
             done [0..1])
 ),
 
--- a/yetilab/stream/channels.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/channels.yeti	Wed May 08 21:10:29 2013 +0100
@@ -6,14 +6,14 @@
 mat = load yetilab.matrix.matrix;
         
 interleaved m = 
-   ({ columns, rows } = m.size;
+   ({ columns, rows } = (mat.size m);
     if rows == 1 then
-        m.getRow 0
+        mat.getRow 0 m
     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;
+                v[col * rows + row] := mat.getAt row col m;
             done;
         done;
         block.block v;
@@ -35,11 +35,11 @@
     fi;
 
 mixedDown m =  //!!! sum or average? at the moment we sum
-   ({ columns, rows } = m.size;
+   ({ columns, rows } = (mat.size m);
     v = vec.zeros columns;
     for [0..rows-1] do row:
         for [0..columns-1] do col:
-            v[col] := v[col] + m.getAt row col;
+            v[col] := v[col] + mat.getAt row col m;
         done;
     done;
     block.block v);
@@ -81,14 +81,14 @@
     fi;
 
 mixedTo targetChannels m = 
-    if targetChannels == m.size.rows then    // n -> n: pass unmodified
+    if targetChannels == mat.height m then   // n -> n: pass unmodified
         m
     elif targetChannels == 1 then            // n -> 1: mix down
         deinterleaved 1 (mixedDown m)
-    elif m.size.rows == 1 then               // 1 -> n: copy to all channels
-        mat.newMatrix (RowMajor ()) (map \(m.getRow 0) [1..targetChannels])
+    elif mat.height m == 1 then              // 1 -> n: copy to all channels
+        mat.newMatrix (RowMajor ()) (map \(mat.getRow 0 m) [1..targetChannels])
     else                                     // n -> m: truncate or add zeros
-        mat.resizedTo { rows = targetChannels, columns = m.size.columns } m
+        mat.resizedTo { rows = targetChannels, columns = mat.width m } m
     fi;
 
 mixedAndInterleavedTo targetChannels m = 
--- a/yetilab/stream/filter.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/filter.yeti	Wed May 08 21:10:29 2013 +0100
@@ -88,8 +88,8 @@
 
 mixed streams =
    (mix m1 m2 =
-       (sz = { rows = max m1.size.rows m2.size.rows,
-               columns = min m1.size.columns m2.size.columns };
+       (sz = { rows = max (mat.height m1) (mat.height m2),
+               columns = min (mat.width m1) (mat.width m2) };
         if sz.columns == 0 then
             mat.zeroSizeMatrix ()
         else
@@ -132,9 +132,9 @@
         get finished? () = any id (map (.finished?) streams),
         read count =
            (outs = map do s: s.read count done streams;
-            minlen = head (sort (map do m: m.size.columns done outs));
+            minlen = head (sort (map mat.width outs));
             outs = map do m:
-                mat.resizedTo { rows = m.size.rows, columns = minlen } m
+                mat.resizedTo { rows = mat.height m, columns = minlen } m
                 done outs;
             mat.concat (Vertical ()) outs
             ),
@@ -154,8 +154,8 @@
         var cache = mat.zeroSizeMatrix ();
         chunks = array [];
         cachedPartsFor count =
-           (start = pos % cache.size.columns;
-            avail = cache.size.columns - start;
+           (start = pos % (mat.width cache);
+            avail = (mat.width cache) - start;
             if avail >= count then
                 pos := pos + count;
                 [mat.columnSlice start count cache]
@@ -165,11 +165,11 @@
                     cachedPartsFor (count - avail);
             fi);
         readFromCache count =
-           (if cache.size.columns == 0 then
+           (if (mat.width cache) == 0 then
                 cache := mat.concat (Horizontal ()) (list chunks);
                 clearArray chunks;
             fi;
-            if cache.size.columns == 0 then
+            if (mat.width cache) == 0 then
                 cache
             else
                 mat.concat (Horizontal ()) (cachedPartsFor count);
@@ -184,7 +184,7 @@
                     readFromCache count
                 else
                     part = s.read count;
-                    len = part.size.columns;
+                    len = (mat.width part);
                     push chunks part;
                     pos := pos + len;
                     if len == count then part
--- a/yetilab/stream/framer.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/framer.yeti	Wed May 08 21:10:29 2013 +0100
@@ -35,7 +35,7 @@
         do buf row:
             block.concat
                [block.rangeOf hop (size-hop) buf,
-                block.resizedTo hop (m.getRow row)];
+                block.resizedTo hop (mat.getRow row m)];
         done buffer [0..stream.channels-1];
 
     // Number of "valid" elements (not tail-end zero-padding) left in buffer
--- a/yetilab/stream/test/test_audiofile.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/test/test_audiofile.yeti	Wed May 08 21:10:29 2013 +0100
@@ -3,6 +3,7 @@
 
 af = load yetilab.stream.audiofile;
 bl = load yetilab.block.block;
+mat = load yetilab.matrix.matrix;
 
 { compare } = load yetilab.test.test;
 
@@ -31,11 +32,11 @@
         f = opener (testfile "20samples");
         first15 = f.read 15;
         last5 = f.read 10;
-        compare first15.size { rows = 1, columns = 15 } and
-            compare last5.size { rows = 1, columns = 5 } and
-            compare (bl.list (first15.getRow 0))
+        compare (mat.size first15) { rows = 1, columns = 15 } and
+            compare (mat.size last5) { rows = 1, columns = 5 } and
+            compare (bl.list (mat.getRow 0 first15))
                 [ float (32767/32768),0,0,0,0,0,0,0,0,0,0,0,0,0,0 ] and
-            compare (bl.list (last5.getRow 0)) [ 0,0,0,0,-1 ] and
+            compare (bl.list (mat.getRow 0 last5)) [ 0,0,0,0,-1 ] and
             ( f.close () ; true )
         done [ af.open, af.openMono ]);
 ),
--- a/yetilab/stream/test/test_filter.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/test/test_filter.yeti	Wed May 08 21:10:29 2013 +0100
@@ -41,7 +41,7 @@
         compare str.sampleRate 2 and
         compare str.available (Known 3) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,1,2 ] and
         compare str.position 3 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -52,11 +52,11 @@
     // as above
     str = filt.withDuration 3 (syn.generated 2 id);
     compare str.position 0 and
-        compare (bl.list ((str.read 2).getRow 0)) [ 0,1 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 0,1 ] and
         compare str.position 2 and
         compare str.available (Known 1) and
         compare str.finished? false and
-        compare (bl.list ((str.read 2).getRow 0)) [ 2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 2 ] and
         compare str.position 3 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -74,11 +74,11 @@
         compare str.sampleRate 2 and
         compare str.available (Known 5) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2,0 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,1,2,0 ] and
         compare str.position 4 and
         compare str.available (Known 1) and
         compare str.finished? false and
-        compare (bl.list ((str.read 2).getRow 0)) [ 0 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 0 ] and
         compare str.position 5 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -92,7 +92,7 @@
         compare str.sampleRate 2 and
         compare str.available (maybeKnown 3) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,1,2 ] and
         compare str.position 3 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -106,7 +106,7 @@
         compare str.sampleRate 2 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2,3 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,1,2,3 ] and
         compare str.position 4 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
@@ -120,11 +120,11 @@
         compare str.sampleRate 2 and
         compare str.available (maybeKnown 5) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,0,0,1 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,0,0,1 ] and
         compare str.position 4 and
         compare str.available (maybeKnown 1) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 2 ] and
         compare str.position 5 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -138,11 +138,11 @@
         compare str.sampleRate 2 and
         compare str.available (maybeKnown 5) and
         compare str.finished? false and
-        compare (bl.list ((str.read 1).getRow 0)) [ 0 ] and
+        compare (bl.list (mat.getRow 0 (str.read 1))) [ 0 ] and
         compare str.position 1 and
         compare str.available (maybeKnown 4) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,0,1,2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,0,1,2 ] and
         compare str.position 5 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -156,7 +156,7 @@
         compare str.sampleRate 2 and
         compare str.available (maybeKnown 5) and
         compare str.finished? false and
-        compare (bl.list ((str.read 7).getRow 0)) [ 0,0,0,1,2 ] and
+        compare (bl.list (mat.getRow 0 (str.read 7))) [ 0,0,0,1,2 ] and
         compare str.position 5 and
         compare str.available (Known 0) and
         compare str.finished? true and
@@ -170,13 +170,13 @@
         compare str.sampleRate 2 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compare (bl.list ((str.read 2).getRow 0)) [ 0,0 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 0,0 ] and
         compare str.position 2 and
         compare str.finished? false and
-        compare (bl.list ((str.read 2).getRow 0)) [ 0,1 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 0,1 ] and
         compare str.position 4 and
         compare str.finished? false and
-        compare (bl.list ((str.read 2).getRow 0)) [ 2,3 ] and
+        compare (bl.list (mat.getRow 0 (str.read 2))) [ 2,3 ] and
         compare str.position 6 and
         compare str.finished? false and
         ( str.close (); true )
--- a/yetilab/stream/test/test_syntheticstream.yeti	Wed May 08 20:48:57 2013 +0100
+++ b/yetilab/stream/test/test_syntheticstream.yeti	Wed May 08 21:10:29 2013 +0100
@@ -21,7 +21,7 @@
         compare str.sampleRate 2 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compare (bl.list ((str.read 4).getRow 0)) [ 0,1,2,3 ] and
+        compare (bl.list (mat.getRow 0 (str.read 4))) [ 0,1,2,3 ] and
         compare str.position 4
 ),
 
@@ -33,7 +33,7 @@
         compare str.sampleRate 8 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compareApprox epsilon (bl.list ((str.read 6).getRow 0)) [ 0, 1, 0, -1, 0, 1 ] and
+        compareApprox epsilon (bl.list (mat.getRow 0 (str.read 6))) [ 0, 1, 0, -1, 0, 1 ] and
         compare str.position 6
 ),
 
@@ -44,7 +44,7 @@
         compare str.sampleRate 8 and
         compare str.available (Infinite ()) and
         compare str.finished? false and
-        compare (bl.list ((str.read 3).getRow 0)) [ 0, 0, 0 ] and
+        compare (bl.list (mat.getRow 0 (str.read 3))) [ 0, 0, 0 ] and
         compare str.position 3
 ),
 
@@ -55,7 +55,7 @@
         compare str.sampleRate 2 and
         compare str.available (Known 0) and
         compare str.finished? true and
-        compare (bl.list ((str.read 3).getRow 0)) [] and
+        compare (bl.list (mat.getRow 0 (str.read 3))) [] and
         compare str.position 0
 ),
 
@@ -66,11 +66,11 @@
         compare str.sampleRate 2 and
         compare str.available (Known 4) and
         compare str.finished? false and
-        compare (bl.list ((str.read 3).getRow 0)) [ 1, 2, 3 ] and
+        compare (bl.list (mat.getRow 0 (str.read 3))) [ 1, 2, 3 ] and
         compare str.position 3 and
         compare str.available (Known 1) and
         compare str.finished? false and
-        compare (bl.list ((str.read 3).getRow 0)) [ 4 ] and
+        compare (bl.list (mat.getRow 0 (str.read 3))) [ 4 ] and
         compare str.position 4 and
         compare str.available (Known 0) and
         compare str.finished? true