/rev/382f0eb42dca
changeset: 1324:382f0eb42dca
user: Marcel Keller <[email protected]>
date: Thu Oct 22 19:38:16 2009 +0200
summary: field: Optimized standard path in GF256 operations.
diffstat:
viff/field.py | 19 ++++++++++---------
1 files changed, 10 insertions(+), 9 deletions(-)
diffs (42 lines):
diff -r 2fb6e3f39e69 -r 382f0eb42dca viff/field.py
--- a/viff/field.py Tue Oct 06 18:37:52 2009 +0200
+++ b/viff/field.py Thu Oct 22 19:38:16 2009 +0200
@@ -162,15 +162,16 @@
>>> GF256(0x01) + 1
[0]
"""
- if not isinstance(other, (GF256, int, long)):
+ if isinstance(other, GF256):
+ return _add_table[self.value][other.value]
+ elif isinstance(other, (int, long)):
+ return _add_table[self.value][other]
+ else:
# This occurs with code like 'a + b' where b is a Share.
# In that case we must return NotImplemented to signal
# that b.__radd__(a) should be run instead. The Share will
# then schedule things correctly.
return NotImplemented
- if isinstance(other, GF256):
- other = other.value
- return _add_table[self.value][other]
def __radd__(self, other):
"""Add this and another number (reflected argument version).
@@ -206,12 +207,12 @@
>>> GF256(16) * GF256(32)
[54]
"""
- if not isinstance(other, (GF256, int, long)):
+ if isinstance(other, GF256):
+ return _mul_table[self.value][other.value]
+ elif isinstance(other, (int, long)):
+ return _mul_table[self.value][other]
+ else:
return NotImplemented
- if isinstance(other, GF256):
- other = other.value
- return _mul_table[self.value][other]
-
def __rmul__(self, other):
"""Multiply this and another number (reflected argument
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk