提交 c331e558 authored 作者: James Bergstra's avatar James Bergstra

more conservative op.default_output

上级 e3dad04e
...@@ -49,14 +49,17 @@ class Apply(object2): ...@@ -49,14 +49,17 @@ class Apply(object2):
Returns the default output for this Node, typically self.outputs[0]. Returns the default output for this Node, typically self.outputs[0].
Depends on the value of node.op.default_output Depends on the value of node.op.default_output
""" """
do = self.op.default_output do = getattr(self.op, 'default_output', None)
if do < 0: if do is None:
raise AttributeError("%s does not have a default output." % self.op) if len(self.outputs) == 1:
elif do > len(self.outputs): return self.outputs[0]
raise AttributeError("default output for %s is out of range." % self.op) else:
raise AttributeError("%s.default_output should be an output index." % self.op)
elif do < 0 or do >= len(self.outputs):
raise AttributeError("%s.default_output is out of range." % self.op)
return self.outputs[do] return self.outputs[do]
out = property(default_output, out = property(default_output,
doc = "Same as self.outputs[0] if this Op's has_default_output field is True.") doc = "Shortcut to the as self.outputs[0] if this Op's has_default_output field is True.")
def __str__(self): def __str__(self):
return op_as_string(self.inputs, self) return op_as_string(self.inputs, self)
def __repr__(self): def __repr__(self):
...@@ -561,7 +564,7 @@ def as_string(i, o, ...@@ -561,7 +564,7 @@ def as_string(i, o,
if r.owner is not None and r not in i and r not in orph: if r.owner is not None and r not in i and r not in orph:
op = r.owner op = r.owner
idx = op.outputs.index(r) idx = op.outputs.index(r)
if idx == op.op.default_output: if len(op.outputs) == 1:
idxs = "" idxs = ""
else: else:
idxs = "::%i" % idx idxs = "::%i" % idx
......
...@@ -13,8 +13,9 @@ from copy import copy ...@@ -13,8 +13,9 @@ from copy import copy
class Op(object2): class Op(object2):
default_output = 0 default_output = None
"""@todo
"""
############# #############
# make_node # # make_node #
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论