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

Flake8 for gof/vm.py

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