viff

changeset 1011:80ba4bffd726

Documented the FakeFieldElement class.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 06 Nov 2008 14:25:19 +0100
parents c9775d9bd895
children 464008ada9c2
files doc/field.txt viff/field.py
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/doc/field.txt	Thu Nov 06 14:25:17 2008 +0100
     1.2 +++ b/doc/field.txt	Thu Nov 06 14:25:19 2008 +0100
     1.3 @@ -21,3 +21,5 @@
     1.4           addition.
     1.5  
     1.6     .. autofunction:: GF
     1.7 +
     1.8 +   .. autoclass:: FakeFieldElement
     2.1 --- a/viff/field.py	Thu Nov 06 14:25:17 2008 +0100
     2.2 +++ b/viff/field.py	Thu Nov 06 14:25:19 2008 +0100
     2.3 @@ -515,21 +515,47 @@
     2.4      return GFElement
     2.5  
     2.6  class FakeFieldElement(FieldElement):
     2.7 +    """Fake field which does no computations.
     2.8 +
     2.9 +    This class should only be used in benchmarking. It works like any
    2.10 +    other :class:`FieldElement` except that all computations will give
    2.11 +    ``1`` as the result:
    2.12 +
    2.13 +    >>> a = FakeFieldElement(123)
    2.14 +    >>> b = FakeFieldElement(234)
    2.15 +    >>> a + b
    2.16 +    {{1}}
    2.17 +    >>> a * b
    2.18 +    {{1}}
    2.19 +    >>> a.bit(100)
    2.20 +    1
    2.21 +    >>> a.sqrt()
    2.22 +    {{1}}
    2.23 +    """
    2.24 +
    2.25      def __init__(self, value):
    2.26 -        # We store the value passed in order to make the objects take
    2.27 -        # up some meomry space.
    2.28 +        """Create a fake field element.
    2.29 +
    2.30 +        The element will store *value* in order to take up a realistic
    2.31 +        amount of RAM, but any further computation will yield the
    2.32 +        value ``1``.
    2.33 +        """
    2.34          self.value = value
    2.35  
    2.36 +    # Binary operations.
    2.37      __add__ = __radd__ = __sub__ = __rsub__ \
    2.38          = __mul__ = __rmul__ = __div__ = __rdiv__ \
    2.39          = __truediv__ = __rtruediv__ = __floordiv__ = __rfloordiv__ \
    2.40          = __pow__ = __neg__ \
    2.41          = lambda self, other: FakeFieldElement(1)
    2.42  
    2.43 +    # Unary operations.
    2.44      __invert__ = sqrt = lambda self: FakeFieldElement(1)
    2.45  
    2.46 +    # Bit extraction. We pretend that the number is *very* big.
    2.47      bit = lambda self, index: 1
    2.48  
    2.49 +    # Fake field elements are printed with double curly brackets.
    2.50      __repr__ = __str__ = lambda self: "{{%d}}" % self.value
    2.51  
    2.52  FakeFieldElement.field = FakeFieldElement