提交 4eadee06 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix error in Advanced indexing with > 2D

上级 ee9eaeb0
......@@ -552,7 +552,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
# build the strides
strides = [1]
for i in range(p - 1, 0, -1):
stride = x.shape[i] * strides[-1]
stride = x.shape[i] * strides[0]
strides.insert(0, stride)
# build the indices and use it
......
......@@ -1603,6 +1603,26 @@ class TestAdvancedSubtensor(unittest.TestCase):
cmd = f2(0, 1, 2) == aa[[0, 1, 2], :, 0:2]
self.assertTrue(cmd.all())
def test_adv_sub_3d(self):
# Reported in https://github.com/Theano/Theano/issues/5674
X = tensor.tensor3("X")
xx = numpy.zeros((3, 2, 2), config.floatX)
for i in range(3):
for j in range(2):
for k in range(2):
xx[i, j, k] = 100 * i + 10 * j + k
b_idx = numpy.zeros((2, 2), 'int32')
b_idx[0, 1] = 1
b_idx[1, 1] = 2
r_idx = numpy.arange(xx.shape[1])[numpy.newaxis, :]
c_idx = numpy.arange(xx.shape[2])[numpy.newaxis, :]
out = X[b_idx, r_idx, c_idx].eval({X: xx})
utt.assert_allclose(out, xx[b_idx, r_idx, c_idx])
def test_grad(self):
ones = numpy.ones((1, 3), dtype=self.dtype)
n = self.shared(ones * 5, broadcastable=(True, False))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论