提交 ce20b8ba authored 作者: Ian Goodfellow's avatar Ian Goodfellow

merged

...@@ -438,6 +438,8 @@ class AllocDiag(Op): ...@@ -438,6 +438,8 @@ class AllocDiag(Op):
if x.type.ndim != 1: if x.type.ndim != 1:
raise TypeError('AllocDiag only works on vectors', _x) raise TypeError('AllocDiag only works on vectors', _x)
return Apply(self, [x], [tensor.matrix(dtype=x.type.dtype)]) return Apply(self, [x], [tensor.matrix(dtype=x.type.dtype)])
def grad(self, inputs, g_outputs):
return [extract_diag(g_outputs[0])]
def perform(self, node, (x,), (z,)): def perform(self, node, (x,), (z,)):
if x.ndim != 1: if x.ndim != 1:
raise TypeError(x) raise TypeError(x)
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论