提交 30d8150c authored 作者: Olivier Delalleau's avatar Olivier Delalleau

PEP8

上级 3db224ef
......@@ -1236,20 +1236,21 @@ class OpWiseCLinker(link.LocalLinker):
self.no_recycling = no_recycling
return self
def make_all(self, profiler = None, input_storage = None, output_storage = None):
def make_all(self, profiler=None, input_storage=None, output_storage=None):
# The lock will be acquired when we compile the first
# C code. We will keep the lock untill all the function
# compilation will be finished. This allow to don't
# require the lock when all c code are already compiled!
orig_n_lock = getattr(get_lock,"n_lock",0)
orig_n_lock = getattr(get_lock, "n_lock", 0)
try:
env = self.env
order = env.toposort()
no_recycling = self.no_recycling
input_storage, output_storage, storage_map = link.map_storage(env, order, input_storage, output_storage)
input_storage, output_storage, storage_map = link.map_storage(
env, order, input_storage, output_storage)
if self.allow_gc:
computed, last_user = link.gc_helper(order)
post_thunk_old_storage = []
......@@ -1267,7 +1268,7 @@ class OpWiseCLinker(link.LocalLinker):
# There are ops that don't have _op_use_c_code property
# for example ifelse (or any ops that come with their own
# make_thunk
old_value = getattr(node.op,'_op_use_c_code', False)
old_value = getattr(node.op, '_op_use_c_code', False)
try:
node.op._op_use_c_code = True
thunks += [node.op.make_thunk(node,
......@@ -1282,31 +1283,37 @@ class OpWiseCLinker(link.LocalLinker):
if self.allow_gc:
post_thunk_old_storage.append([storage_map[input]
for input in node.inputs
if (input in computed) and (input not in env.outputs) and node == last_user[input]])
if ((input in computed) and
(input not in env.outputs) and
node == last_user[input])])
if no_recycling is True:
no_recycling = storage_map.values()
no_recycling = utils.difference(no_recycling, input_storage)
else:
no_recycling = [storage_map[r] for r in no_recycling if r not in env.inputs]
no_recycling = [storage_map[r]
for r in no_recycling if r not in env.inputs]
f = link.streamline(env, thunks, order,
post_thunk_old_storage,
no_recycling = no_recycling,
nice_errors = self.nice_errors)
no_recycling=no_recycling,
nice_errors=self.nice_errors)
f.allow_gc = self.allow_gc
finally:
# Release lock on compilation directory.
if getattr(get_lock,"n_lock",0) > orig_n_lock:
if getattr(get_lock, "n_lock", 0) > orig_n_lock:
release_lock()
assert get_lock.n_lock == orig_n_lock
return f, [link.Container(input, storage) for input, storage in izip(env.inputs, input_storage)], \
[link.Container(output, storage, True) for output, storage in izip(env.outputs, output_storage)], \
thunks, order
return (f,
[link.Container(input, storage)
for input, storage in izip(env.inputs, input_storage)],
[link.Container(output, storage, True)
for output, storage in izip(env.outputs, output_storage)],
thunks,
order)
def _default_checker(x, y):
......@@ -1315,7 +1322,9 @@ def _default_checker(x, y):
variables contain the same data using ==.
"""
if x[0] != y[0]:
raise Exception("Output mismatch.", {'performlinker': x[0], 'clinker': y[0]})
raise Exception("Output mismatch.",
{'performlinker': x[0], 'clinker': y[0]})
class DualLinker(link.Linker):
"""WRITEME
......@@ -1329,7 +1338,7 @@ class DualLinker(link.Linker):
function.
"""
def __init__(self, checker = _default_checker):
def __init__(self, checker=_default_checker):
"""
Initialize a DualLinker.
......@@ -1355,10 +1364,11 @@ class DualLinker(link.Linker):
self.env = None
self.checker = checker
def accept(self, env, no_recycling = []):
def accept(self, env, no_recycling=[]):
if self.env is not None and self.env is not env:
return type(self)(self.checker).accept(env, no_recycling)
#raise Exception("Cannot accept from a Linker that is already tied to another Env.")
# raise Exception("Cannot accept from a Linker that is already "
# "tied to another Env.")
self.env = env
self.no_recycling = no_recycling
return self
......@@ -1368,16 +1378,20 @@ class DualLinker(link.Linker):
env = self.env
no_recycling = self.no_recycling
_f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs)
_f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env,
no_recycling=no_recycling).make_all(**kwargs)
kwargs.pop('input_storage', None)
_f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs)
_f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env,
no_recycling=no_recycling).make_all(**kwargs)
def f():
for input1, input2 in izip(i1, i2):
# set the inputs to be the same in both branches
# the copy is necessary in order for inplace ops not to interfere
# Set the inputs to be the same in both branches.
# The copy is necessary in order for inplace ops not to
# interfere.
input2.storage[0] = copy(input1.storage[0])
for thunk1, thunk2, node1, node2 in izip(thunks1, thunks2, order1, order2):
for thunk1, thunk2, node1, node2 in izip(thunks1, thunks2,
order1, order2):
for output, storage in izip(node1.outputs, thunk1.outputs):
if output in no_recycling:
storage[0] = None
......@@ -1387,7 +1401,8 @@ class DualLinker(link.Linker):
try:
thunk1()
thunk2()
for output1, output2 in izip(thunk1.outputs, thunk2.outputs):
for output1, output2 in izip(thunk1.outputs,
thunk2.outputs):
self.checker(output1, output2)
except Exception:
link.raise_with_op(node1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论