提交 a1875d64 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

PEP8

上级 ed6a7f69
......@@ -52,10 +52,10 @@ class Optimizer(object):
def apply(self, fgraph):
"""WRITEME
Applies the optimization to the provided L{FunctionGraph}. It may use all
the methods defined by the L{FunctionGraph}. If the L{Optimizer} needs
to use a certain tool, such as an L{InstanceFinder}, it can do
so in its L{add_requirements} method.
Applies the optimization to the provided L{FunctionGraph}. It may
use all the methods defined by the L{FunctionGraph}. If the
L{Optimizer} needs to use a certain tool, such as an
L{InstanceFinder}, it can do so in its L{add_requirements} method.
"""
pass
......@@ -208,7 +208,6 @@ class SeqOptimizer(Optimizer, list):
nb_node_after, sub_profs) = prof
blanc = (' ' * level)
print >> stream, blanc, "SeqOptimizer",
if hasattr(opts, "name"):
print >> stream, blanc, opts.name,
......@@ -217,7 +216,8 @@ class SeqOptimizer(Optimizer, list):
print >> stream, (" time %.3fs for %d/%d nodes"
" before/after optimization" % (
sum(prof), nb_node_before, nb_node_after))
print >> stream, blanc, " %.3fs for fgraph.validate()" % (validate_time)
print >> stream, \
blanc, " %.3fs for fgraph.validate()" % (validate_time)
if level == 0:
print >> stream, blanc, " time - (name, class, index)"
ll = []
......@@ -289,7 +289,8 @@ class SeqOptimizer(Optimizer, list):
p = prof2
new_t[idx] += p[1][p[0].index(l)]
if hasattr(l, 'merge_profile'):
assert len(p[5][p[0].index(l)]) == len(new_sub_profile[idx])
assert len(p[5][p[0].index(l)]) == \
len(new_sub_profile[idx])
new_sub_profile[idx] = l.merge_profile(
new_sub_profile[idx], p[5][p[0].index(l)])
else:
......@@ -468,7 +469,8 @@ class MergeFeature(object):
if node in self.nodes_seen:
return
# These asserts ensure that the fgraph has set the clients field properly.
# These asserts ensure that the fgraph has set the clients field
# properly.
# The clients should at least contain `node` itself!
if node.inputs:
assert len(node.inputs[0].clients) > 0
......@@ -677,7 +679,8 @@ class LocalOptimizer(object):
def add_requirements(self, fgraph):
"""
If this local optimization wants to add some requirements to the fgraph,
If this local optimization wants to add some requirements to the
fgraph,
This is the place to do it.
"""
# Added by default
......@@ -755,7 +758,8 @@ class _LocalOpKeyOptGroup(LocalOptGroup):
def __init__(self, optimizers):
if any(not hasattr(opt, 'op_key'), optimizers):
raise TypeError("All LocalOptimizers passed here must have an op_key method.")
raise TypeError(
"All LocalOptimizers passed here must have an op_key method.")
CompositeLocalOptimizer.__init__(self, optimizers)
def op_key(self):
......@@ -1133,8 +1137,8 @@ class NavigatorOptimizer(Optimizer):
def attach_updater(self, fgraph, importer, pruner, chin=None):
"""
Install some FunctionGraph listeners to help the navigator deal with the
ignore_trees-related functionality.
Install some FunctionGraph listeners to help the navigator deal with
the ignore_trees-related functionality.
:param importer: function that will be called whenever when
optimizations add stuff to the graph.
......@@ -1522,7 +1526,8 @@ class EquilibriumOptimizer(NavigatorOptimizer):
count_opt.append((time_lopts[opt], count, opt))
if count_opt:
print >> stream, blanc, 'times applied - optimizer (only those applied):'
print >> stream, blanc, \
'times applied - optimizer (only those applied):'
count_opt.sort()
for (t, count, opt) in count_opt[::-1]:
print >> stream, blanc, ' %.3fs - %d - %s' % (
......@@ -1591,6 +1596,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
### Utilities ###
#################
def _check_chain(r, chain):
"""WRITEME"""
......@@ -1633,8 +1639,8 @@ def check_chain(r, *chain):
def pre_greedy_local_optimizer(list_optimizations, out):
'''
This function traverses the computation graph described by all
``node`` in the graph before the variable out but that are not in the fgraph.
it applies each of the local_optimizations on the traversed graph.
``node`` in the graph before the variable out but that are not in the
fgraph. it applies each of the local_optimizations on the traversed graph.
Its main use is to apply locally constant folding when generating
the graph of the indices of a subtensor.
......@@ -1651,6 +1657,7 @@ def pre_greedy_local_optimizer(list_optimizations, out):
if not getattr(out, 'owner', None):
return [out], optimized_vars
node = out.owner
if hasattr(node, 'fgraph'):
return node.outputs, optimized_vars
for idx, inp in enumerate(node.inputs):
......
......@@ -2212,8 +2212,9 @@ class T_Scan(unittest.TestCase):
cost = expr.sum()
d_cost_wrt_W = tensor.grad(cost, [W])
f = theano.function([W, inpt], d_cost_wrt_W,
givens=OrderedDict([(initial, theano.shared(numpy.zeros(5)))]))
f = theano.function(
[W, inpt], d_cost_wrt_W,
givens=OrderedDict([(initial, theano.shared(numpy.zeros(5)))]))
rval = numpy.asarray([[5187989] * 5] * 5, dtype=theano.config.floatX)
arg1 = numpy.ones((5, 5), dtype=theano.config.floatX)
......@@ -3170,7 +3171,8 @@ class T_Scan(unittest.TestCase):
shared_var = theano.shared(numpy.float32(1.))
def inner_fn():
return [], OrderedDict([(shared_var, shared_var + numpy.float32(1.))])
return [], OrderedDict(
[(shared_var, shared_var + numpy.float32(1.))])
_, updates = theano.scan(inner_fn,
n_steps=10,
truncate_gradient=-1,
......@@ -3243,7 +3245,8 @@ class T_Scan(unittest.TestCase):
seq = tensor.matrix()
initial_value = theano.shared(numpy.zeros((4, 1),
dtype=theano.config.floatX))
outputs_info = [OrderedDict([('initial', initial_value), ('taps', [-4])]), None]
outputs_info = [OrderedDict(
[('initial', initial_value), ('taps', [-4])]), None]
results, updates = theano.scan(fn=onestep,
sequences=seq,
outputs_info=outputs_info)
......@@ -3263,7 +3266,8 @@ class T_Scan(unittest.TestCase):
seq = tensor.matrix()
initial_value = theano.shared(numpy.zeros((4, 1),
dtype=theano.config.floatX))
outputs_info = [OrderedDict([('initial', initial_value), ('taps', [-4])]), None]
outputs_info = [OrderedDict([('initial', initial_value),
('taps', [-4])]), None]
results, _ = theano.scan(fn=onestep,
sequences=seq,
outputs_info=outputs_info)
......@@ -3321,8 +3325,9 @@ class T_Scan(unittest.TestCase):
def test_savemem_does_not_duplicate_number_of_scan_nodes(self):
var = tensor.ones(())
values, _ = theano.scan(lambda x: ([x], (), theano.scan_module.until(x)),
outputs_info=[var], n_steps=2)
values, _ = theano.scan(lambda x: ([x], (),
theano.scan_module.until(x)),
outputs_info=[var], n_steps=2)
tmp_fn = theano.function([var], values)
scan_nodes = [x for x in tmp_fn.maker.fgraph.toposort()
......@@ -3395,7 +3400,6 @@ class T_Scan(unittest.TestCase):
assert numpy.allclose(outs[2], v_w + 3)
assert numpy.allclose(sh.get_value(), v_w + 4)
def test_speed():
#
# This function prints out the speed of very simple recurrent
......@@ -3750,7 +3754,8 @@ def test_compute_test_value():
x = tensor.vector('x')
xv = numpy.ones(3, dtype=theano.config.floatX)
x.tag.test_value = xv
y = theano.shared(numpy.arange(3, dtype=theano.config.floatX), name='y')
y = theano.shared(numpy.arange(3, dtype=theano.config.floatX),
name='y')
z, _ = theano.scan(
fn=lambda u, v: u + v,
sequences=[x, y])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论