viff

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 diff
     1.1 --- a/viff/util.py	Fri Feb 20 10:20:34 2009 +0100
     1.2 +++ b/viff/util.py	Thu Mar 05 13:00:59 2009 +0100
     1.3 @@ -388,6 +388,16 @@
     1.4                           for key, value in usage.iteritems()])
     1.5          _last_memory_usage = usage
     1.6  
     1.7 +def if_then(cond, a, b):
     1.8 +    """If then else operator works both for integers and for shares.
     1.9 +
    1.10 +    >>> if_then(0, 3, 6)
    1.11 +    6
    1.12 +    >>> if_then(1, 3, 6)
    1.13 +    3
    1.14 +    """
    1.15 +    return b + cond * (a - b)
    1.16 +
    1.17  if __name__ == "__main__":
    1.18      import doctest    #pragma NO COVER
    1.19      doctest.testmod() #pragma NO COVER