• R/O
  • SSH

提交

标签

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A small kernel of code for playing with Galois fields of arbitrary characteristic


Commit MetaInfo

修订版363cd639b602f6b0bfb93b538e10c3bcbec87fc8 (tree)
时间2016-04-24 23:52:40
作者Eric Hopper <hopper@omni...>
CommiterEric Hopper

Log Message

Rename size to size_ for consistency with prime_ and basis_.

更改概述

差异

diff -r b56509398ead -r 363cd639b602 gf.py
--- a/gf.py Sat Apr 23 16:13:43 2016 -0400
+++ b/gf.py Sun Apr 24 10:52:40 2016 -0400
@@ -20,7 +20,7 @@
2020 "and < prime.")
2121 if basis_[0] != 1:
2222 raise ValueError("First element of basis must be 1")
23- size = len(basis_) - 1
23+ size_ = len(basis_) - 1
2424
2525 @_total_ordering
2626 class gf(_gfBase):
@@ -38,8 +38,8 @@
3838
3939 def __init__(self, val):
4040 val = tuple((int(v) for v in val))
41- if len(val) != size:
42- raise ValueError("val must be sequence of size size of ints")
41+ if len(val) != size_:
42+ raise ValueError("val must be sequence of size size_ of ints")
4343 if any((v < 0) or (v >= prime_) for v in val):
4444 raise ValueError("Each element of val must be >= 0 and < %d"
4545 % (prime_,))
@@ -86,9 +86,9 @@
8686
8787 def _intmul(self, other):
8888 if other == 0:
89- return self.__class__([0] * size)
89+ return self.__class__([0] * size_)
9090 elif other < 0:
91- return self.__class__([0] * size) - self._intmul(-other)
91+ return self.__class__([0] * size_) - self._intmul(-other)
9292 elif other & 1:
9393 return self + self._intmul(other - 1)
9494 else:
@@ -105,15 +105,15 @@
105105 return self._intmul(other)
106106 else:
107107 return NotImplemented
108- tmpval = [0] * (size * 2)
108+ tmpval = [0] * (size_ * 2)
109109 for i, factor in enumerate(reversed(other.val_)):
110110 for j, term in enumerate(reversed(self.val_)):
111111 tmpval[i + j] += factor * term
112112 tmpval = tuple((term % prime_) for term in tmpval)
113113 tmpval = tuple(reversed(tmpval))
114114 shiftval = tuple((prime_ - term) % prime_ for term in basis_) \
115- + ((0,) * (size - 1))
116- while len(tmpval) > size:
115+ + ((0,) * (size_ - 1))
116+ while len(tmpval) > size_:
117117 while tmpval[0] != 0:
118118 tmpval = tuple((x + y) % prime_ \
119119 for x, y in zip(tmpval, shiftval))
@@ -140,7 +140,7 @@
140140 return NotImplemented
141141 if other < 0:
142142 raise ValueError("Negative powers are not supported.")
143- start = self.__class__((0,) * (size - 1) + (1,))
143+ start = self.__class__((0,) * (size_ - 1) + (1,))
144144 base = self
145145 while other > 0:
146146 if other & 1: