提交 def89798 authored 作者: Amjad Almahairi's avatar Amjad Almahairi

flake8 fixes

上级 85733bda
...@@ -544,8 +544,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -544,8 +544,9 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
we don't print anything below it. we don't print anything below it.
:param scan_ops: Scan ops in the graph will be added inside this list :param scan_ops: Scan ops in the graph will be added inside this list
for later printing purposes. for later printing purposes.
:param scan_inner_to_outer_inputs: a dictionary mapping a scan ops inner function :param scan_inner_to_outer_inputs: a dictionary mapping a scan ops
inputs to the scan op inputs (outer inputs) for printing purposes. inner function inputs to the scan op inputs (outer inputs) for
printing purposes.
""" """
if depth == 0: if depth == 0:
...@@ -681,7 +682,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -681,7 +682,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
theano.scan_module.scan_op.Scan): theano.scan_module.scan_op.Scan):
scan_ops.append(i) scan_ops.append(i)
debugprint(i, new_prefix, depth=depth - 1, done=done, debugprint(
i, new_prefix, depth=depth - 1, done=done,
print_type=print_type, file=file, order=order, print_type=print_type, file=file, order=order,
ids=ids, stop_on_name=stop_on_name, ids=ids, stop_on_name=stop_on_name,
prefix_child=new_prefix_child, scan_ops=scan_ops, prefix_child=new_prefix_child, scan_ops=scan_ops,
...@@ -698,7 +700,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False, ...@@ -698,7 +700,8 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
outer_id_str = get_id_str(outer_r.owner) outer_id_str = get_id_str(outer_r.owner)
else: else:
outer_id_str = get_id_str(outer_r) outer_id_str = get_id_str(outer_r)
print('%s%s %s%s -> %s' % (prefix, r, id_str, type_str, outer_id_str), file=file) print('%s%s %s%s -> %s' % (prefix, r, id_str, type_str,
outer_id_str), file=file)
else: else:
# this is an input variable # this is an input variable
id_str = get_id_str(r) id_str = get_id_str(r)
......
...@@ -168,16 +168,17 @@ N.B.: ...@@ -168,16 +168,17 @@ N.B.:
inner_to_outer_inputs = \ inner_to_outer_inputs = \
dict([(inner_inputs[i], outer_inputs[o]) dict([(inner_inputs[i], outer_inputs[o])
for i, o in for i, o in
s.owner.op.var_mappings['outer_inp_from_inner_inp'].items()]) s.owner.op.var_mappings['outer_inp_from_inner_inp']
.items()])
print("", file=_file) print("", file=_file)
debugmode.debugprint(s, depth=depth, done=done, debugmode.debugprint(
s, depth=depth, done=done,
print_type=print_type, print_type=print_type,
file=_file, ids=ids, file=_file, ids=ids,
scan_ops=scan_ops, scan_ops=scan_ops,
stop_on_name=stop_on_name, stop_on_name=stop_on_name,
scan_inner_to_outer_inputs= scan_inner_to_outer_inputs=inner_to_outer_inputs)
inner_to_outer_inputs)
if hasattr(s.owner.op, 'fn'): if hasattr(s.owner.op, 'fn'):
# If the op was compiled, print the optimized version. # If the op was compiled, print the optimized version.
outputs = s.owner.op.fn.maker.fgraph.outputs outputs = s.owner.op.fn.maker.fgraph.outputs
...@@ -189,14 +190,14 @@ N.B.: ...@@ -189,14 +190,14 @@ N.B.:
if isinstance(i.owner.op, theano.scan_module.scan_op.Scan): if isinstance(i.owner.op, theano.scan_module.scan_op.Scan):
scan_ops.append(i) scan_ops.append(i)
debugmode.debugprint(r=i, prefix=new_prefix, debugmode.debugprint(
r=i, prefix=new_prefix,
depth=depth, done=done, depth=depth, done=done,
print_type=print_type, file=_file, print_type=print_type, file=_file,
ids=ids, stop_on_name=stop_on_name, ids=ids, stop_on_name=stop_on_name,
prefix_child=new_prefix_child, prefix_child=new_prefix_child,
scan_ops=scan_ops, scan_ops=scan_ops,
scan_inner_to_outer_inputs= scan_inner_to_outer_inputs=inner_to_outer_inputs)
inner_to_outer_inputs)
if file is _file: if file is _file:
return file return file
......
...@@ -303,9 +303,10 @@ def test_scan_debugprint1(): ...@@ -303,9 +303,10 @@ def test_scan_debugprint1():
> |<TensorType(float64, vector)> [@Y] -> [@E] > |<TensorType(float64, vector)> [@Y] -> [@E]
> |A_copy [@Z] -> [@N]""" > |A_copy [@Z] -> [@N]"""
for truth,out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
def test_scan_debugprint2(): def test_scan_debugprint2():
coefficients = theano.tensor.vector("coefficients") coefficients = theano.tensor.vector("coefficients")
x = tensor.scalar("x") x = tensor.scalar("x")
...@@ -313,11 +314,14 @@ def test_scan_debugprint2(): ...@@ -313,11 +314,14 @@ def test_scan_debugprint2():
max_coefficients_supported = 10000 max_coefficients_supported = 10000
# Generate the components of the polynomial # Generate the components of the polynomial
components, updates = theano.scan(fn=lambda coefficient, power, free_variable: components, updates = theano.scan(fn=lambda coefficient, power,
free_variable:
coefficient * (free_variable ** power), coefficient * (free_variable ** power),
outputs_info=None, outputs_info=None,
sequences=[coefficients, sequences=[
theano.tensor.arange(max_coefficients_supported)], coefficients,
theano.tensor.arange(
max_coefficients_supported)],
non_sequences=x) non_sequences=x)
# Sum them up # Sum them up
polynomial = components.sum() polynomial = components.sum()
...@@ -327,7 +331,7 @@ def test_scan_debugprint2(): ...@@ -327,7 +331,7 @@ def test_scan_debugprint2():
for line in output_str.split('\n'): for line in output_str.split('\n'):
lines += [line] lines += [line]
expected_output= """Sum{acc_dtype=float64} [@A] '' expected_output = """Sum{acc_dtype=float64} [@A] ''
|for{cpu,scan_fn} [@B] '' |for{cpu,scan_fn} [@B] ''
|Elemwise{minimum,no_inplace} [@C] '' |Elemwise{minimum,no_inplace} [@C] ''
| |Subtensor{int64} [@D] '' | |Subtensor{int64} [@D] ''
...@@ -365,7 +369,7 @@ def test_scan_debugprint2(): ...@@ -365,7 +369,7 @@ def test_scan_debugprint2():
> |x_copy [@BA] -> [@W] > |x_copy [@BA] -> [@W]
> |<TensorType(int16, scalar)> [@BB] -> [@U]""" > |<TensorType(int16, scalar)> [@BB] -> [@U]"""
for truth,out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -379,7 +383,8 @@ def test_scan_debugprint3(): ...@@ -379,7 +383,8 @@ def test_scan_debugprint3():
# compute A**k # compute A**k
def compute_A_k(A, k): def compute_A_k(A, k):
# Symbolic description of the result # Symbolic description of the result
result, updates = theano.scan(fn=lambda prior_result, A: prior_result * A, result, updates = theano.scan(fn=lambda prior_result,
A: prior_result * A,
outputs_info=tensor.ones_like(A), outputs_info=tensor.ones_like(A),
non_sequences=A, non_sequences=A,
n_steps=k) n_steps=k)
...@@ -389,11 +394,15 @@ def test_scan_debugprint3(): ...@@ -389,11 +394,15 @@ def test_scan_debugprint3():
return A_k return A_k
# Generate the components of the polynomial # Generate the components of the polynomial
components, updates = theano.scan(fn=lambda coefficient, power, some_A, some_k: components, updates = theano.scan(fn=lambda coefficient,
coefficient * (compute_A_k(some_A, some_k) ** power), power, some_A, some_k:
coefficient *
(compute_A_k(some_A, some_k) ** power),
outputs_info=None, outputs_info=None,
sequences=[coefficients, sequences=[
theano.tensor.arange(max_coefficients_supported)], coefficients,
theano.tensor.arange(
max_coefficients_supported)],
non_sequences=[A, k]) non_sequences=[A, k])
# Sum them up # Sum them up
polynomial = components.sum() polynomial = components.sum()
...@@ -405,7 +414,7 @@ def test_scan_debugprint3(): ...@@ -405,7 +414,7 @@ def test_scan_debugprint3():
for line in output_str.split('\n'): for line in output_str.split('\n'):
lines += [line] lines += [line]
expected_output="""Sum{acc_dtype=float64} [@A] '' expected_output = """Sum{acc_dtype=float64} [@A] ''
|for{cpu,scan_fn} [@B] '' |for{cpu,scan_fn} [@B] ''
|Elemwise{minimum,no_inplace} [@C] '' |Elemwise{minimum,no_inplace} [@C] ''
| |Subtensor{int64} [@D] '' | |Subtensor{int64} [@D] ''
...@@ -478,7 +487,7 @@ def test_scan_debugprint3(): ...@@ -478,7 +487,7 @@ def test_scan_debugprint3():
> |<TensorType(float64, vector)> [@CC] -> [@BG] > |<TensorType(float64, vector)> [@CC] -> [@BG]
> |A_copy [@CD] -> [@BP]""" > |A_copy [@CD] -> [@BP]"""
for truth,out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -490,7 +499,8 @@ def test_scan_debugprint4(): ...@@ -490,7 +499,8 @@ def test_scan_debugprint4():
a0 = theano.shared(numpy.arange(2)) a0 = theano.shared(numpy.arange(2))
b0 = theano.shared(numpy.arange(2)) b0 = theano.shared(numpy.arange(2))
(a, b), _ = theano.scan(fn, outputs_info=[{'initial': a0, 'taps': [-2, -1]}, (a, b), _ = theano.scan(fn, outputs_info=[
{'initial': a0, 'taps': [-2, -1]},
{'initial': b0, 'taps': [-2, -1]}], {'initial': b0, 'taps': [-2, -1]}],
n_steps=5) n_steps=5)
...@@ -551,11 +561,7 @@ def test_scan_debugprint4(): ...@@ -551,11 +561,7 @@ def test_scan_debugprint4():
>Elemwise{add,no_inplace} [@BC] '' >Elemwise{add,no_inplace} [@BC] ''
>Elemwise{add,no_inplace} [@BF] ''""" >Elemwise{add,no_inplace} [@BF] ''"""
# output = "\n".join(lines) for truth, out in zip(expected_output.split("\n"), lines):
# with open('output5.txt', 'w') as f:
# f.write(output)
for truth,out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
...@@ -695,5 +701,5 @@ def test_scan_debugprint5(): ...@@ -695,5 +701,5 @@ def test_scan_debugprint5():
for{cpu,scan_fn} [@BP] '' for{cpu,scan_fn} [@BP] ''
>Elemwise{mul,no_inplace} [@CS] ''""" >Elemwise{mul,no_inplace} [@CS] ''"""
for truth,out in zip(expected_output.split("\n"), lines): for truth, out in zip(expected_output.split("\n"), lines):
assert truth.strip() == out.strip() assert truth.strip() == out.strip()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论