提交 3dfa558f authored 作者: Frederic Bastien's avatar Frederic Bastien

fix gh-5388. Crash fix in theano.pp(). Make subtensor pp follow the new internal interface.

上级 3c0be3d9
...@@ -969,12 +969,15 @@ class SubtensorPrinter: ...@@ -969,12 +969,15 @@ class SubtensorPrinter:
inputs = list(r.owner.inputs) inputs = list(r.owner.inputs)
input = inputs.pop() input = inputs.pop()
sidxs = [] sidxs = []
inbrack_pstate = pstate.clone(precedence=-1000) old_precedence = getattr(pstate, 'precedence', None)
try:
pstate.precedence = -1000
for entry in idxs: for entry in idxs:
if isinstance(entry, integer_types): if isinstance(entry, integer_types):
sidxs.append(str(entry)) sidxs.append(str(entry))
elif isinstance(entry, scal.Scalar): elif isinstance(entry, scal.Scalar):
sidxs.append(inbrack_pstate.pprinter.process(inputs.pop())) sidxs.append(pstate.pprinter.process(inputs.pop()))
elif isinstance(entry, slice): elif isinstance(entry, slice):
if entry.start is None or entry.start == 0: if entry.start is None or entry.start == 0:
msg1 = "" msg1 = ""
...@@ -992,10 +995,15 @@ class SubtensorPrinter: ...@@ -992,10 +995,15 @@ class SubtensorPrinter:
msg3 = ":%s" % entry.step msg3 = ":%s" % entry.step
sidxs.append("%s:%s%s" % (msg1, msg2, msg3)) sidxs.append("%s:%s%s" % (msg1, msg2, msg3))
return "%s[%s]" % (pstate.pprinter.process( finally:
input, pstate.precedence = old_precedence
pstate.clone(precedence=1000)),
", ".join(sidxs)) try:
pstate.precedence = 1000
sub = pstate.pprinter.process(input, pstate)
finally:
pstate.precedence = old_precedence
return "%s[%s]" % (sub, ", ".join(sidxs))
else: else:
raise TypeError("Can only print Subtensor.") raise TypeError("Can only print Subtensor.")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论