提交 404ec250 authored 作者: David Warde-Farley's avatar David Warde-Farley 提交者: Arnaud Bergeron

Auto-fix filter()s.

Fix name clash caused by shadowed filter().
上级 1e457cc6
...@@ -59,7 +59,7 @@ LONG_DESCRIPTION = (codecs.open("DESCRIPTION.txt",encoding='utf-8').read() + ...@@ -59,7 +59,7 @@ LONG_DESCRIPTION = (codecs.open("DESCRIPTION.txt",encoding='utf-8').read() +
URL = "http://deeplearning.net/software/theano/" URL = "http://deeplearning.net/software/theano/"
DOWNLOAD_URL = "" DOWNLOAD_URL = ""
LICENSE = 'BSD' LICENSE = 'BSD'
CLASSIFIERS = filter(None, CLASSIFIERS.split('\n')) CLASSIFIERS = [_f for _f in CLASSIFIERS.split('\n') if _f]
AUTHOR = "LISA laboratory, University of Montreal" AUTHOR = "LISA laboratory, University of Montreal"
AUTHOR_EMAIL = "theano-dev@googlegroups.com" AUTHOR_EMAIL = "theano-dev@googlegroups.com"
PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"] PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
......
...@@ -62,7 +62,7 @@ if 0: ...@@ -62,7 +62,7 @@ if 0:
nodes = [node] nodes = [node]
while candidates: while candidates:
for node in nodes: for node in nodes:
candidates = filter(node, depth) candidates = list(filter(node, depth))
depth += 1 depth += 1
_nodes = nodes _nodes = nodes
nodes = reduce(list.__iadd__, nodes = reduce(list.__iadd__,
......
...@@ -432,4 +432,4 @@ def remove(predicate, coll): ...@@ -432,4 +432,4 @@ def remove(predicate, coll):
>>> remove(even, [1, 2, 3, 4]) >>> remove(even, [1, 2, 3, 4])
[1, 3] [1, 3]
""" """
return filter(lambda x: not predicate(x), coll) return [x for x in coll if not predicate(x)]
...@@ -556,7 +556,7 @@ class CondMerge(gof.Optimizer): ...@@ -556,7 +556,7 @@ class CondMerge(gof.Optimizer):
def apply(self, fgraph): def apply(self, fgraph):
nodelist = list(fgraph.toposort()) nodelist = list(fgraph.toposort())
cond_nodes = filter(lambda s: isinstance(s.op, IfElse), nodelist) cond_nodes = [s for s in nodelist if isinstance(s.op, IfElse)]
if len(cond_nodes) < 2: if len(cond_nodes) < 2:
return False return False
merging_node = cond_nodes[0] merging_node = cond_nodes[0]
......
...@@ -120,7 +120,7 @@ def run_mercurial_command(hg_command): ...@@ -120,7 +120,7 @@ def run_mercurial_command(hg_command):
def parse_stdout_filelist(hg_out_filelist): def parse_stdout_filelist(hg_out_filelist):
files = hg_out_filelist.split() files = hg_out_filelist.split()
files = [f.strip(string.whitespace + "'") for f in files] files = [f.strip(string.whitespace + "'") for f in files]
files = filter(operator.truth, files) # get rid of empty entries files = list(filter(operator.truth, files)) # get rid of empty entries
return files return files
......
...@@ -464,8 +464,7 @@ def scan(fn, ...@@ -464,8 +464,7 @@ def scan(fn,
not isinstance(x, SharedVariable) and not isinstance(x, SharedVariable) and
not isinstance(x, gof.Constant)), not isinstance(x, gof.Constant)),
gof.graph.inputs(fake_outputs)) gof.graph.inputs(fake_outputs))
extra_inputs = filter(lambda x: x not in args + fake_nonseqs, extra_inputs = [x for x in all_inputs if x not in args + fake_nonseqs]
all_inputs)
non_seqs += extra_inputs non_seqs += extra_inputs
# Note we do not use all_inputs directly since the order of variables # Note we do not use all_inputs directly since the order of variables
# in args is quite important # in args is quite important
......
...@@ -27,7 +27,7 @@ class InitGraph(type): ...@@ -27,7 +27,7 @@ class InitGraph(type):
return isinstance(v, theano.Variable) and not k.startswith('_') return isinstance(v, theano.Variable) and not k.startswith('_')
r = {} r = {}
for key, val in dct.items(): for key, val in dct.items():
if filter(key, val): if list(filter(key, val)):
r[key] = val r[key] = val
return r return r
build_graph_rval = cls.build_graph() build_graph_rval = cls.build_graph()
......
...@@ -290,7 +290,7 @@ def get_updates_and_outputs(ls): ...@@ -290,7 +290,7 @@ def get_updates_and_outputs(ls):
else: else:
return [x] return [x]
def filter(x): def _filter(x):
""" """
Ensure `x` is made only of allowed data types. Ensure `x` is made only of allowed data types.
...@@ -304,12 +304,12 @@ def get_updates_and_outputs(ls): ...@@ -304,12 +304,12 @@ def get_updates_and_outputs(ls):
elif isinstance(x, dict): elif isinstance(x, dict):
iter_on = x.iteritems() iter_on = x.iteritems()
if iter_on is not None: if iter_on is not None:
return all(filter(y) for y in iter_on) return all(_filter(y) for y in iter_on)
else: else:
return (isinstance(x, theano.Variable) or return (isinstance(x, theano.Variable) or
isinstance(x, theano.scan_module.until)) isinstance(x, theano.scan_module.until))
if not filter(ls): if not _filter(ls):
raise ValueError( raise ValueError(
'The return value of your scan lambda expression may only be ' 'The return value of your scan lambda expression may only be '
'made of lists, tuples, or dictionaries containing Theano ' 'made of lists, tuples, or dictionaries containing Theano '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论