# HG changeset patch # User Chris Cannam # Date 1370034144 -3600 # Node ID 07389b654ff08f853cca93dc2e90be4f5f7e8f4f # Parent ec6a36d88f57ef5b9e4ec2da77da80da4ea76ecd Make add take a list rather than just 2 diff -r ec6a36d88f57 -r 07389b654ff0 yetilab/vector/blockfuncs.yeti --- 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, subtract is vector -> vector -> vector, multiply is vector -> vector -> vector, divideBy is number -> vector -> vector, diff -r ec6a36d88f57 -r 07389b654ff0 yetilab/vector/test/test_blockfuncs.yeti --- 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": \(