提交 6f249902 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix crash in GPU advanced indexing with no arrays

上级 b6a4757f
......@@ -544,6 +544,12 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
idx_ = ([slice(None)] * p + nidx[p:])
x = x.__getitem__(idx_)
if p == 0:
# The only indexing was through slices and indices.
# This can happen with symbolic slices for instance.
out[0] = x
return
# flatten the array-indexed dimensions
shape = ((np.prod(x.shape[0: p]),) +
x.shape[p:])
......
......@@ -1623,6 +1623,14 @@ class TestAdvancedSubtensor(unittest.TestCase):
out = X[b_idx, r_idx, c_idx].eval({X: xx})
utt.assert_allclose(out, xx[b_idx, r_idx, c_idx])
def test_adv_sub_slice(self):
# Reported in https://github.com/Theano/Theano/issues/5898
var = self.shared(np.zeros([3, 3], dtype=config.floatX))
slc = tensor.slicetype()
f = theano.function([slc], var[slc])
s = slice(1, 3)
f(s)
def test_grad(self):
ones = np.ones((1, 3), dtype=self.dtype)
n = self.shared(ones * 5, broadcastable=(True, False))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论