提交 3ebd725a authored 作者: Iban Harlouchet's avatar Iban Harlouchet

flake8 of theano/gof/link.py

上级 8c4e330d
...@@ -7,14 +7,14 @@ import traceback ...@@ -7,14 +7,14 @@ import traceback
import numpy import numpy
import theano import theano
from theano.compat import PY3, izip from theano.compat import izip
from six import reraise from six import reraise
from six.moves import StringIO from six.moves import StringIO
from theano.gof import utils from theano.gof import utils
from theano.gof import graph from theano.gof import graph
from theano.gof.type import Type from theano.gof.type import Type
from .utils import MethodNotDefined, undef from .utils import undef
__excepthook = sys.excepthook __excepthook = sys.excepthook
...@@ -281,9 +281,9 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None): ...@@ -281,9 +281,9 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
else: else:
detailed_err_msg += "\n" detailed_err_msg += "\n"
detailed_err_msg += " TotalSize: %s Byte(s) %.3f GB\n" % ( detailed_err_msg += " TotalSize: %s Byte(s) %.3f GB\n" % (
total_size, total_size/1024./1024/1024) total_size, total_size / 1024. / 1024 / 1024)
detailed_err_msg += " TotalSize inputs: %s Byte(s) %.3f BG\n" % ( detailed_err_msg += " TotalSize inputs: %s Byte(s) %.3f BG\n" % (
total_size_inputs, total_size_inputs/1024./1024/1024) total_size_inputs, total_size_inputs / 1024. / 1024 / 1024)
else: else:
hints.append( hints.append(
...@@ -326,7 +326,7 @@ class Linker(object): ...@@ -326,7 +326,7 @@ class Linker(object):
raise utils.MethodNotDefined("make_thunk", type(self), raise utils.MethodNotDefined("make_thunk", type(self),
self.__class__.__name__) self.__class__.__name__)
## DELETEME ## # DELETEME #
def make_function(self, unpack_single=True, **kwargs): def make_function(self, unpack_single=True, **kwargs):
""" """
Returns a function that takes values corresponding to the inputs of the Returns a function that takes values corresponding to the inputs of the
...@@ -350,8 +350,8 @@ class Linker(object): ...@@ -350,8 +350,8 @@ class Linker(object):
def execute(*args): def execute(*args):
def e_arity(takes, got): def e_arity(takes, got):
return 'Function call takes exactly %i %s (%i given)' \ return 'Function call takes exactly %i %s (%i given)' % (
% (takes, ['argument', 'arguments'][takes > 1], got) takes, ['argument', 'arguments'][takes > 1], got)
if (len(args) != len(inputs)): if (len(args) != len(inputs)):
raise TypeError(e_arity(len(inputs), len(args))) raise TypeError(e_arity(len(inputs), len(args)))
for arg, variable in izip(args, inputs): for arg, variable in izip(args, inputs):
...@@ -394,7 +394,7 @@ class Container(object): ...@@ -394,7 +394,7 @@ class Container(object):
""" """
if not isinstance(storage, list) or not len(storage) >= 1: if not isinstance(storage, list) or not len(storage) >= 1:
raise TypeError("storage must be a list of length at least one") raise TypeError("storage must be a list of length at least one")
#self.r = r # self.r = r
if isinstance(r, Type): if isinstance(r, Type):
self.type = r self.type = r
else: else:
...@@ -454,12 +454,11 @@ class Container(object): ...@@ -454,12 +454,11 @@ class Container(object):
deepcopy(self.strict, memo=memo), deepcopy(self.strict, memo=memo),
deepcopy(self.allow_downcast, memo=memo), deepcopy(self.allow_downcast, memo=memo),
deepcopy(self.name, memo=memo), deepcopy(self.name, memo=memo),
) )
# Work around NumPy deepcopy of ndarray with 0 dimention that # Work around NumPy deepcopy of ndarray with 0 dimention that
# don't return an ndarray. # don't return an ndarray.
if (r.storage[0] is not None and if (r.storage[0] is not None and
not self.type.is_valid_value(r.storage[0])): not self.type.is_valid_value(r.storage[0])):
assert not data_was_in_memo assert not data_was_in_memo
assert self.type.is_valid_value(self.storage[0]) assert self.type.is_valid_value(self.storage[0])
# This should also work for read only container. # This should also work for read only container.
...@@ -672,7 +671,7 @@ class PerformLinker(LocalLinker): ...@@ -672,7 +671,7 @@ class PerformLinker(LocalLinker):
no_recycling = [] no_recycling = []
if self.fgraph is not None and self.fgraph is not fgraph: if self.fgraph is not None and self.fgraph is not fgraph:
return type(self)(allow_gc=self.allow_gc).accept(fgraph, no_recycling) return type(self)(allow_gc=self.allow_gc).accept(fgraph, no_recycling)
#raise Exception("Cannot accept from a Linker that is already tied to another FunctionGraph.") # raise Exception("Cannot accept from a Linker that is already tied to another FunctionGraph.")
self.fgraph = fgraph self.fgraph = fgraph
self.no_recycling = no_recycling self.no_recycling = no_recycling
return self return self
...@@ -721,9 +720,12 @@ class PerformLinker(LocalLinker): ...@@ -721,9 +720,12 @@ class PerformLinker(LocalLinker):
for node in order: for node in order:
if self.allow_gc: if self.allow_gc:
post_thunk_old_storage.append([storage_map[input] post_thunk_old_storage.append(
for input in node.inputs [storage_map[input]
if (input in computed) and (input not in fgraph.outputs) and node == last_user[input]]) for input in node.inputs
if (input in computed) and (
input not in fgraph.outputs) and (
node == last_user[input])])
if no_recycling is True: if no_recycling is True:
# True seems like some special code for *everything*?? -JB # True seems like some special code for *everything*?? -JB
...@@ -855,7 +857,7 @@ class WrapLinker(Linker): ...@@ -855,7 +857,7 @@ class WrapLinker(Linker):
make_all += [l.make_all(**kwargs) for l in self.linkers[1:]] make_all += [l.make_all(**kwargs) for l in self.linkers[1:]]
fns, input_lists, output_lists, thunk_lists, order_lists \ fns, input_lists, output_lists, thunk_lists, order_lists \
= zip(*make_all) = zip(*make_all)
order_list0 = order_lists[0] order_list0 = order_lists[0]
for order_list in order_lists[1:]: for order_list in order_lists[1:]:
......
...@@ -243,7 +243,6 @@ whitelist_flake8 = [ ...@@ -243,7 +243,6 @@ whitelist_flake8 = [
"gof/unify.py", "gof/unify.py",
"gof/graph.py", "gof/graph.py",
"gof/__init__.py", "gof/__init__.py",
"gof/link.py",
"gof/fg.py", "gof/fg.py",
"gof/op.py", "gof/op.py",
"gof/cmodule.py", "gof/cmodule.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论