提交 990f46fd authored 作者: James Bergstra's avatar James Bergstra

fixed IncSubtensor.perform implementation for case of incrementing a single scalar

上级 d020e83b
...@@ -1935,7 +1935,12 @@ class IncSubtensor(Op): ...@@ -1935,7 +1935,12 @@ class IncSubtensor(Op):
if not self.inplace: if not self.inplace:
x = x.copy() x = x.copy()
sub_x = x.__getitem__(cdata) sub_x = x.__getitem__(cdata)
sub_x += y if sub_x.shape:
# we've sliced out an N-D tensor with N > 0
sub_x += y
else:
# scalar case
x.__setitem__(cdata, sub_x + y)
out[0] = x out[0] = x
def split(x, splits_size, n_splits, axis=0): def split(x, splits_size, n_splits, axis=0):
......
...@@ -852,7 +852,10 @@ class T_subtensor(unittest.TestCase): ...@@ -852,7 +852,10 @@ class T_subtensor(unittest.TestCase):
n = as_tensor_variable(data) n = as_tensor_variable(data)
t = n[1,0] t = n[1,0]
gn = grad(sum(exp(t)), n) gn = grad(sum(exp(t)), n)
gval = eval_outputs([gn]) f = function([], gn, mode=None)
print 'toposort', f.maker.env.toposort()
gval = f()
print gval
good = numpy.zeros_like(data) good = numpy.zeros_like(data)
good[1,0] = numpy.exp(data[1,0]) good[1,0] = numpy.exp(data[1,0])
self.failUnless(numpy.all(gval == good), (gval, good)) self.failUnless(numpy.all(gval == good), (gval, good))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论