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