changeset 1107:88ac6ac5fe70

Utility function for if_then that works with shares.
author Tord Reistad <tordr@item.ntnu.no>
date Thu, 05 Mar 2009 13:00:59 +0100
parents ab726c059750
children e5aecd62cf67
files viff/util.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/util.py	Fri Feb 20 10:20:34 2009 +0100
+++ b/viff/util.py	Thu Mar 05 13:00:59 2009 +0100
@@ -388,6 +388,16 @@
                          for key, value in usage.iteritems()])
         _last_memory_usage = usage
 
+def if_then(cond, a, b):
+    """If then else operator works both for integers and for shares.
+
+    >>> if_then(0, 3, 6)
+    6
+    >>> if_then(1, 3, 6)
+    3
+    """
+    return b + cond * (a - b)
+
 if __name__ == "__main__":
     import doctest    #pragma NO COVER
     doctest.testmod() #pragma NO COVER