changeset 159:a9d58d9c71ca

Fix matrix.equal (did not check matrix size, could return true if one was a subset of the other) and add test for it; fix resizedTo test
author Chris Cannam
date Wed, 01 May 2013 12:32:08 +0100
parents b6db07468ed1
children 97df257b32d3
files yetilab/matrix/matrix.yeti yetilab/matrix/test/test_matrix.yeti
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti	Wed May 01 12:03:45 2013 +0100
+++ b/yetilab/matrix/matrix.yeti	Wed May 01 12:32:08 2013 +0100
@@ -101,8 +101,8 @@
 // Matrices with different storage order but the same contents are
 // equal (but comparing them is slow)
 equal m1 m2 =
-    if m1.isRowMajor? != m2.isRowMajor?
-    then equal (flipped m1) m2;
+    if m1.size != m2.size then false
+    elif m1.isRowMajor? != m2.isRowMajor? then equal (flipped m1) m2;
     else
         compare d1 d2 = all id (map2 vec.equal d1 d2);
         case m1.data of
--- a/yetilab/matrix/test/test_matrix.yeti	Wed May 01 12:03:45 2013 +0100
+++ b/yetilab/matrix/test/test_matrix.yeti	Wed May 01 12:32:08 2013 +0100
@@ -91,10 +91,12 @@
     n = m;
     p = newMatrix (RowMajor ()) [[1,2,3],[4,5,6]];
     q = newMatrix (ColumnMajor ()) [[1,2,3],[4,5,6]];
+    r = newMatrix (ColumnMajor ()) [[1,4],[2,5]];
     compareMatrices m n and
         compareMatrices m p and
         compareMatrices n p and
-        not mat.equal m q
+        not mat.equal m q and
+        not mat.equal m r
 ),
 
 "getAt-\(name)": \(
@@ -227,7 +229,7 @@
     compareMatrices
        (mat.resizedTo { rows = 2, columns = 2 }
            (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]))
-       (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]) and
+       (newMatrix (ColumnMajor ()) [[1,4],[2,5]]) and
         compareMatrices
            (mat.resizedTo { rows = 3, columns = 4 }
                (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]))
@@ -235,7 +237,7 @@
         compareMatrices
            (mat.resizedTo { rows = 1, columns = 1 }
                (newMatrix (ColumnMajor ()) [[1,4],[2,5],[3,6]]))
-           (newMatrix (ColumnMajor ()) [[1]])
+           (newMatrix (RowMajor ()) [[1]])
 ),
 
 "zeroSizeMatrix-\(name)": \(