http://hg.viff.dk/viff/rev/b4d9b373bbab
changeset: 1084:b4d9b373bbab
user:      Marcel Keller <[email protected]>
date:      Tue Jan 20 10:45:50 2009 +0100
summary:   Added lin_comb() to compute linear combinations of shares with less 
overhead.

diffstat:

1 file changed, 28 insertions(+)
viff/passive.py |   28 ++++++++++++++++++++++++++++

diffs (38 lines):

diff -r e530dfcb40cd -r b4d9b373bbab viff/passive.py
--- a/viff/passive.py   Thu Jan 15 18:30:46 2009 +0100
+++ b/viff/passive.py   Tue Jan 20 10:45:50 2009 +0100
@@ -135,6 +135,34 @@
         result.addCallback(lambda (a, b): a - b)
         return result
 
+    def lin_comb(self, coefficients, shares):
+        """Linear combination of shares.
+
+        Communication cost: none. Saves the construction of unnecessary shares
+        compared to using add() and mul()."""
+
+        for coeff in coefficients:
+            assert not isinstance(coeff, Share), \
+                "Coefficients should not be shares."
+
+        assert len(coefficients) == len(shares), \
+            "Number of coefficients and shares should be equal."
+
+        field = None
+        for share in shares:
+            field = getattr(share, "field", field)
+        for i, share in enumerate(shares):
+            if not isinstance(share, Share):
+                shares[i] = Share(self, field, share)
+
+        def computation(shares, coefficients):
+            summands = [shares[i] * coefficients[i] for i in 
range(len(shares))]
+            return reduce(lambda x, y: x + y, summands)
+
+        result = gather_shares(shares)
+        result.addCallback(computation, coefficients)
+        return result
+
     @profile
     @increment_pc
     def mul(self, share_a, share_b):
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk

Reply via email to