diff yetilab/matrix/test/test_matrix.yeti @ 251:9fe3192cce38

Proper sparse*sparse multiply, more efficient makeSparse. Still loads of room for improvement, but the timings are more predictable now at least.
author Chris Cannam
date Tue, 21 May 2013 12:11:40 +0100
parents 1ea5bf6e76b6
children 8043f7405eae
line wrap: on
line diff
--- a/yetilab/matrix/test/test_matrix.yeti	Mon May 20 22:17:35 2013 +0100
+++ b/yetilab/matrix/test/test_matrix.yeti	Tue May 21 12:11:40 2013 +0100
@@ -249,6 +249,30 @@
            (newMatrix (ColumnMajor ()) [[58,139],[64,154]])
 ),
 
+"sparseProduct-\(name)": \(
+    s = mat.newSparseMatrix (ColumnMajor ()) { rows = 2, columns = 3 } [
+        { i = 0, j = 0, v = 1 },
+        { i = 0, j = 2, v = 2 },
+        { i = 1, j = 1, v = 4 },
+    ];
+    t = mat.newSparseMatrix (ColumnMajor ()) { rows = 3, columns = 2 } [
+        { i = 0, j = 1, v = 7 },
+        { i = 1, j = 0, v = 5 },
+        { i = 2, j = 0, v = 6 },
+    ];
+    prod = mat.product s t;
+    mat.isSparse? prod and
+        compareMatrices prod (mat.product (mat.toDense s) t) and
+        compareMatrices prod (mat.product (mat.toDense s) (mat.toDense t)) and
+        compareMatrices prod (mat.product s (mat.toDense t)) and
+        compareMatrices prod 
+           (mat.newSparseMatrix (RowMajor ()) { rows = 2, columns = 2 } [
+               { i = 0, j = 0, v = 12 },
+               { i = 0, j = 1, v = 7 },
+               { i = 1, j = 0, v = 20 },
+            ])
+),
+
 "productFail-\(name)": \(
     try
       \() (mat.product (constMatrix 2 { rows = 4, columns = 2 })