提交 281cdcbf authored 作者: Ian Goodfellow's avatar Ian Goodfellow

changed Rop to have list-in, list-out behavior

上级 7d84b870
...@@ -48,7 +48,11 @@ def Rop(f, wrt, eval_points): ...@@ -48,7 +48,11 @@ def Rop(f, wrt, eval_points):
indices that specify both the position within a list and all indices that specify both the position within a list and all
coordinates of the tensor element in the last coordinates of the tensor element in the last
""" """
if not isinstance(wrt, (list, tuple)):
using_list = isinstance(wrt, list)
using_tuple = isinstance(wrt, tuple)
if not (using_list or using_tuple):
wrt = [ wrt ] wrt = [ wrt ]
if not isinstance(eval_points, (list, tuple)): if not isinstance(eval_points, (list, tuple)):
...@@ -112,8 +116,14 @@ def Rop(f, wrt, eval_points): ...@@ -112,8 +116,14 @@ def Rop(f, wrt, eval_points):
rval.append(seen_nodes[out.owner][out.owner.outputs.index(out)] ) rval.append(seen_nodes[out.owner][out.owner.outputs.index(out)] )
if len(rval) == 1: if len(rval) == 1:
if using_list:
return rval
if using_tuple:
return tuple(rval)
return rval[0] return rval[0]
else: else:
if using_tuple:
return tuple(rval)
return rval return rval
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论