提交 d9166080 authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Frederic

flake8 of theano/gof/graph.py; 1 E left

上级 f4edcc59
...@@ -7,18 +7,17 @@ To read about what theano graphs are from a user perspective, have a look at ...@@ -7,18 +7,17 @@ To read about what theano graphs are from a user perspective, have a look at
""" """
from __future__ import print_function from __future__ import print_function
__docformat__ = "restructuredtext en"
from collections import deque from collections import deque
from copy import copy from copy import copy
from itertools import count from itertools import count
import theano import theano
import warnings
from theano.gof import utils from theano.gof import utils
from six import string_types, integer_types, iteritems from six import string_types, integer_types, iteritems
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
__docformat__ = "restructuredtext en"
# Lazy imports to avoid circular dependencies. # Lazy imports to avoid circular dependencies.
is_same_graph_with_merge = None is_same_graph_with_merge = None
equal_computations = None equal_computations = None
...@@ -310,7 +309,7 @@ class Variable(Node): ...@@ -310,7 +309,7 @@ class Variable(Node):
`compile.function` uses each `Apply` instance's `inputs` attribute `compile.function` uses each `Apply` instance's `inputs` attribute
together with each Variable's `owner` field to determine which inputs are necessary to compute the function's outputs. together with each Variable's `owner` field to determine which inputs are necessary to compute the function's outputs.
""" """
#__slots__ = ['type', 'owner', 'index', 'name'] # __slots__ = ['type', 'owner', 'index', 'name']
__count__ = count(0) __count__ = count(0)
def __init__(self, type, owner=None, index=None, name=None): def __init__(self, type, owner=None, index=None, name=None):
...@@ -409,7 +408,7 @@ class Variable(Node): ...@@ -409,7 +408,7 @@ class Variable(Node):
self._fn_cache = dict() self._fn_cache = dict()
inputs = tuple(sorted(inputs_to_values.keys(), key=id)) inputs = tuple(sorted(inputs_to_values.keys(), key=id))
if not inputs in self._fn_cache: if inputs not in self._fn_cache:
self._fn_cache[inputs] = theano.function(inputs, self) self._fn_cache[inputs] = theano.function(inputs, self)
args = [inputs_to_values[param] for param in inputs] args = [inputs_to_values[param] for param in inputs]
...@@ -429,7 +428,7 @@ class Constant(Variable): ...@@ -429,7 +428,7 @@ class Constant(Variable):
Constant nodes make eligible numerous optimizations: constant inlining in C code, constant folding, etc. Constant nodes make eligible numerous optimizations: constant inlining in C code, constant folding, etc.
""" """
#__slots__ = ['data'] # __slots__ = ['data']
def __init__(self, type, data, name=None): def __init__(self, type, data, name=None):
"""Initialize self. """Initialize self.
...@@ -481,8 +480,7 @@ class Constant(Variable): ...@@ -481,8 +480,7 @@ class Constant(Variable):
raise ValueError("Constant instances cannot have an owner.") raise ValueError("Constant instances cannot have an owner.")
owner = property(lambda self: None, __set_owner) owner = property(lambda self: None, __set_owner)
value = property(lambda self: self.data, value = property(lambda self: self.data, doc='read-only data access method')
doc='read-only data access method')
# index is not defined, because the `owner` attribute must necessarily be None # index is not defined, because the `owner` attribute must necessarily be None
...@@ -654,9 +652,7 @@ def clone(i, o, copy_inputs=True): ...@@ -654,9 +652,7 @@ def clone(i, o, copy_inputs=True):
return [equiv[input] for input in i], [equiv[output] for output in o] return [equiv[input] for input in i], [equiv[output] for output in o]
def clone_get_equiv(inputs, outputs, def clone_get_equiv(inputs, outputs, copy_inputs_and_orphans=True, memo=None):
copy_inputs_and_orphans=True,
memo=None):
""" """
Return a dictionary that maps from Variable and Apply nodes in the Return a dictionary that maps from Variable and Apply nodes in the
original graph to a new node (a clone) in a new graph. original graph to a new node (a clone) in a new graph.
...@@ -776,7 +772,8 @@ def general_toposort(r_out, deps, debug_print=False, ...@@ -776,7 +772,8 @@ def general_toposort(r_out, deps, debug_print=False,
rlist.append(node) rlist.append(node)
rset.add(node) rset.add(node)
for client in clients.get(node, []): for client in clients.get(node, []):
deps_cache[client] = [a for a in deps_cache[client] if a is not node] deps_cache[client] = [a for a in deps_cache[client]
if a is not node]
if not deps_cache[client]: if not deps_cache[client]:
sources.append(client) sources.append(client)
...@@ -858,8 +855,10 @@ def io_toposort(inputs, outputs, orderings=None): ...@@ -858,8 +855,10 @@ def io_toposort(inputs, outputs, orderings=None):
default_leaf_formatter = str default_leaf_formatter = str
default_node_formatter = lambda op, argstrings: "%s(%s)" % (op.op,
", ".join(argstrings))
def default_node_formatter(op, argstrings):
return "%s(%s)" % (op.op, ", ".join(argstrings))
def io_connection_pattern(inputs, outputs): def io_connection_pattern(inputs, outputs):
...@@ -1010,7 +1009,7 @@ def is_same_graph(var1, var2, givens=None, debug=False): ...@@ -1010,7 +1009,7 @@ def is_same_graph(var1, var2, givens=None, debug=False):
inside = dict((v, [in_var(v, k) for k in (1, 2)]) inside = dict((v, [in_var(v, k) for k in (1, 2)])
for v in (to_replace, replace_by)) for v in (to_replace, replace_by))
if (inside[to_replace][0] and not inside[to_replace][1] and if (inside[to_replace][0] and not inside[to_replace][1] and
inside[replace_by][1] and not inside[replace_by][0]): inside[replace_by][1] and not inside[replace_by][0]):
# Substitute variable in `var1` by one from `var2`. # Substitute variable in `var1` by one from `var2`.
in_xs.append(to_replace) in_xs.append(to_replace)
in_ys.append(replace_by) in_ys.append(replace_by)
...@@ -1151,7 +1150,7 @@ def view_roots(r): ...@@ -1151,7 +1150,7 @@ def view_roots(r):
def list_of_nodes(inputs, outputs): def list_of_nodes(inputs, outputs):
""" Return the apply nodes of the graph between inputs and outputs """ """ Return the apply nodes of the graph between inputs and outputs """
return stack_search( return stack_search(
deque([o.owner for o in outputs]), deque([o.owner for o in outputs]),
lambda o: [inp.owner for inp in o.inputs lambda o: [inp.owner for inp in o.inputs
if inp.owner if inp.owner and
and not any(i in inp.owner.outputs for i in inputs)]) not any(i in inp.owner.outputs for i in inputs)])
...@@ -224,7 +224,6 @@ whitelist_flake8 = [ ...@@ -224,7 +224,6 @@ whitelist_flake8 = [
"sparse/sandbox/truedot.py", "sparse/sandbox/truedot.py",
"sparse/sandbox/sp.py", "sparse/sandbox/sp.py",
"gof/unify.py", "gof/unify.py",
"gof/graph.py",
"gof/__init__.py", "gof/__init__.py",
"gof/op.py", "gof/op.py",
"gof/tests/test_cmodule.py", "gof/tests/test_cmodule.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论