提交 9d7c48d9 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Flake8 for gof/vm.py

上级 6d034f05
......@@ -53,7 +53,8 @@ AddConfigVar('vm.lazy',
in_c_key=False)
def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, dependencies):
def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re,
dependencies):
reallocated_info = {}
viewed_by = {}
for var in fgraph.variables:
......@@ -74,14 +75,14 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
ins = None
if dmap and idx_o in dmap:
idx_v = dmap[idx_o]
assert len(
idx_v) == 1, "Here we only support the possibility to destroy one input"
assert len(idx_v) == 1, ("Here we only support the possibility"
" to destroy one input")
ins = node.inputs[idx_v[0]]
if vmap and idx_o in vmap:
assert ins is None
idx_v = vmap[idx_o]
assert len(
idx_v) == 1, "Here we only support the possibility to view one input"
assert len(idx_v) == 1, ("Here we only support the possibility"
" to view one input")
ins = node.inputs[idx_v[0]]
if ins is not None:
assert isinstance(ins, theano.Variable)
......@@ -94,7 +95,8 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
assert not (ins in view_of and viewed_by[ins])
if (getattr(ins, 'ndim', None) == 0 and not storage_map[ins][0]
and ins not in fgraph.outputs and ins.owner
and all([compute_map_re[v][0] for v in dependencies.get(ins, [])])
and all([compute_map_re[v][0]
for v in dependencies.get(ins, [])])
and ins not in allocated):
# Constant Memory cannot be changed
# Constant and shared variables' storage_map value is not empty
......@@ -105,8 +107,9 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
if reuse_out:
break
for out in order[i].outputs:
if (getattr(out, 'ndim', None) == 0 and out not in pre_allocated
and ins.type == out.type):
if (getattr(out, 'ndim', None) == 0 and
out not in pre_allocated and
ins.type == out.type):
reuse_out = out
pre_allocated.add(out)
allocated.add(ins)
......@@ -122,8 +125,9 @@ def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, depend
if reuse_out:
break
for out in order[i].outputs:
if (getattr(out, 'ndim', None) == 0 and out not in pre_allocated
and ins.type == out.type):
if (getattr(out, 'ndim', None) == 0 and
out not in pre_allocated and
ins.type == out.type):
reuse_out = out
pre_allocated.add(out)
allocated.add(ins)
......@@ -508,9 +512,10 @@ class Stack(VM):
st = "c"
self.variable_strides[var] = st
except Exception:
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map=storage_map)
link.raise_with_op(
current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map=storage_map)
for o in current_apply.outputs:
compute_map[o][0] = 1
......@@ -544,10 +549,13 @@ class Stack(VM):
'destroy_map',
False)):
warnings.warn(
"There was a bug that existed in the default Theano configuration,"
" only in the development version between July 5th 2012"
" and July 30th 2012. This was not in a released version."
" The bug was affecting this script.",
"There was a bug that existed in "
"the default Theano configuration,"
" only in the development version "
"between July 5th 2012 and "
"July 30th 2012. This was not in "
"a released version. The bug was "
"affecting this script.",
# The stack level is not good when
# inside a Scan.
stacklevel=3
......@@ -578,9 +586,10 @@ class Stack(VM):
self.call_times[current_idx] += dt
except Exception:
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map=storage_map)
link.raise_with_op(
current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map=storage_map)
if requires:
for r in requires:
......@@ -639,7 +648,7 @@ class Stack(VM):
if self.allow_gc:
for v in storage_map:
if v.owner and not v in self.outputs:
if v.owner and v not in self.outputs:
if compute_map[v][0] == 2:
continue
else:
......@@ -840,7 +849,6 @@ class VM_Linker(link.LocalLinker):
vars_idx_inv[i] = var
# put storage_map and compute_map into a int-based scheme
n_applies = len(nodes)
storage_map_list = [storage_map[vars_idx_inv[i]]
for i in xrange(len(vars_idx_inv))]
compute_map_list = [compute_map[vars_idx_inv[i]]
......@@ -988,7 +996,8 @@ class VM_Linker(link.LocalLinker):
else:
dependencies = self.compute_gc_dependencies(storage_map)
reallocated_info = calculate_reallocate_info(order, fgraph, storage_map, compute_map_re,dependencies)
reallocated_info = calculate_reallocate_info(
order, fgraph, storage_map, compute_map_re, dependencies)
for node in order:
try:
......@@ -1014,7 +1023,8 @@ class VM_Linker(link.LocalLinker):
lazy = config.vm.lazy
if lazy is None:
lazy = not all([(not th.lazy) for th in thunks])
if not (lazy or (config.profile and config.profile_memory) or self.use_cloop or self.callback):
if not (lazy or (config.profile and config.profile_memory) or
self.use_cloop or self.callback):
for pair in reallocated_info.values():
storage_map[pair[1]] = storage_map[pair[0]]
......
......@@ -268,7 +268,6 @@ whitelist_flake8 = [
"sparse/sandbox/truedot.py",
"sparse/sandbox/sp.py",
"gof/destroyhandler.py",
"gof/vm.py",
"gof/cutils.py",
"gof/compiledir.py",
"gof/unify.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论