提交 3a2138de authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix gradient of set_subtensor1

Reported by Bitton Tenessi
上级 dbb03761
...@@ -1808,15 +1808,30 @@ class AdvancedIncSubtensor1(Op): ...@@ -1808,15 +1808,30 @@ class AdvancedIncSubtensor1(Op):
def grad(self, inputs, grads): def grad(self, inputs, grads):
g_output, = grads g_output, = grads
x, y = inputs[:2] x, y, idx_list = inputs
idx_list = inputs[2:] if x.dtype in theano.tensor.discrete_dtypes:
# The output dtype is the same as x
gx = g_output gx = x.zeros_like(dtype=theano.config.floatX)
gy = advanced_subtensor1(g_output, *idx_list) if y.dtype in theano.tensor.discrete_dtypes:
gy = y.zeros_like(dtype=theano.config.floatX)
else:
gy = y.zeros_like()
elif x.dtype in theano.tensor.complex_dtypes:
raise NotImplementedError("No support for complex grad yet")
else:
if self.set_instead_of_inc:
gx = advanced_set_subtensor1(
g_output,
y.zeros_like(),
idx_list)
else:
gx = g_output
gy = advanced_subtensor1(g_output, idx_list)
return [gx, gy] + [DisconnectedType()()] * len(idx_list) return [gx, gy] + [DisconnectedType()()]
advanced_inc_subtensor1 = AdvancedIncSubtensor1() advanced_inc_subtensor1 = AdvancedIncSubtensor1()
advanced_set_subtensor1 = AdvancedIncSubtensor1(set_instead_of_inc=True)
def as_index_variable(idx): def as_index_variable(idx):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论