本文整理汇总了Python中field.Field.trace方法的典型用法代码示例。如果您正苦于以下问题:Python Field.trace方法的具体用法?Python Field.trace怎么用?Python Field.trace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类field.Field
的用法示例。
在下文中一共展示了Field.trace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_matrix
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import trace [as 别名]
def generate_matrix(q, number_processes = 35):
field = Field(q)
two_powers = [2 ** (q - i) for i in xrange(q + 1)]
with Manager() as manager:
A = manager.dict() # where we store the row integers
amount = lambda : len(A) # I use this to print out how many rows we have generated periodically
def append(x):
if x in A:
return 0
A[x] = True
return 1
#append = lambda x : A.__setitem__(x, True)
is_new = lambda x : not A.__contains__(x) # to avoid duplicate entries
# we don't need the a = 0, b = q - 1 case because it requires setting the 0th column (0 * (q-1)) which has already been chosen
a = q - 1
# generate all the numerators quickly
numerators = [[field.add(field.multiply(a, t), c) for t in field.trace()] for c in field]
bs = range(q - 3) + [q - 1] # all the b values we need
_distribute(lambda bs : _make_and_start_process(bs, a, field, numerators, append, is_new, two_powers, amount), bs, number_processes)
# start all the processes and then wait for them to finish
# the keys of the dictionary represent the row integers for the problem
return A.keys()
示例2: get_original_matrix
# 需要导入模块: from field import Field [as 别名]
# 或者: from field.Field import trace [as 别名]
def get_original_matrix(q):
f = Field(q)
with Manager() as manager:
A = manager.dict()
Add = f.add
Mult = f.multiply
trace = f.trace()
invarray = [f.inverse(i) for i in range(q)]
two_powers = [2 ** (q - i) for i in xrange(q + 1)]
tuples = [(0, q - 1)] + [(q - 1, b) for b in f]
num_processes = 30
_distribute(tuples, A, f, Add, Mult, trace, invarray, two_powers, q, num_processes)
# Reduce and return A
return A.keys()