changeset 297:07389b654ff0

Make add take a list rather than just 2
author Chris Cannam
date Fri, 31 May 2013 22:02:24 +0100
parents ec6a36d88f57
children 920f736f8702
files yetilab/vector/blockfuncs.yeti yetilab/vector/test/test_blockfuncs.yeti
diffstat 2 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/vector/blockfuncs.yeti	Fri May 31 22:02:03 2013 +0100
+++ b/yetilab/vector/blockfuncs.yeti	Fri May 31 22:02:24 2013 +0100
@@ -45,13 +45,14 @@
         len: sum' v / len
     esac;
 
-add b1 b2 =
-   (v1 = raw b1;
-    v2 = raw b2;
-    len = if length v1 < length v2 then length v1 else length v2 fi;
+add bb =
+   (len = head (sort (map vec.length bb));
+    vv = map raw bb;
     out = new double[len];
     for [0..len-1] do i:
-        out[i] := v1[i] + v2[i]
+        for vv do v: 
+            out[i] := out[i] + v[i];
+        done;
     done;
     vec.vector out);
 
@@ -106,7 +107,7 @@
 {
 sum is vector -> number = sum',
 mean is vector -> number,
-add is vector -> vector -> vector,
+add is list?<vector> -> vector,
 subtract is vector -> vector -> vector,
 multiply is vector -> vector -> vector, 
 divideBy is number -> vector -> vector, 
--- a/yetilab/vector/test/test_blockfuncs.yeti	Fri May 31 22:02:03 2013 +0100
+++ b/yetilab/vector/test/test_blockfuncs.yeti	Fri May 31 22:02:24 2013 +0100
@@ -38,9 +38,9 @@
 ),
 
 "add": \(
-    compare (list (add (zeros 0) (ones 5))) [] and
-        compare (list (add (consts 3 4) (fromList [1,2,3]))) [4,5,6] and
-        compare (list (add (consts (-3) 4) (fromList [1,2,3]))) [-2,-1,0] 
+    compare (list (add [zeros 0, ones 5])) [] and
+        compare (list (add [consts 3 4, fromList [1,2,3] ])) [4,5,6] and
+        compare (list (add [consts (-3) 4, fromList [1,2,3] ])) [-2,-1,0] 
 ),
 
 "subtract": \(