提交 7ae8a4ec authored 作者: Ian Goodfellow's avatar Ian Goodfellow

fixed bug where it was possible to make Dimshuffle ops with duplicate output dimensions

added test for same bug
上级 d98a89d3
...@@ -101,6 +101,11 @@ class DimShuffle(Op): ...@@ -101,6 +101,11 @@ class DimShuffle(Op):
self.new_order = new_order self.new_order = new_order
self.inplace = inplace self.inplace = inplace
for i in xrange(len(new_order)-1):
j = new_order[i]
if j != 'x' and j in new_order[i+1:]:
raise ValueError("The same input dimension may not appear twice in the list of output dimensions", (new_order))
# list of dimensions of the input to drop # list of dimensions of the input to drop
self.drop = [] self.drop = []
i2j = {} # this maps i before dropping dimensions to j after dropping dimensions so self.shuffle can be set properly later on i2j = {} # this maps i before dropping dimensions to j after dropping dimensions so self.shuffle can be set properly later on
......
...@@ -3342,6 +3342,20 @@ def test_unalign(): ...@@ -3342,6 +3342,20 @@ def test_unalign():
if not should_raise: if not should_raise:
raise Exception("Theano raised an exception when none was expected") raise Exception("Theano raised an exception when none was expected")
def test_dimshuffle_duplicate():
x = theano.tensor.vector()
success = False
try:
y = theano.tensor.DimShuffle((False, ), (0, 0))(x)
except ValueError, e:
assert str(e).find("may not appear twice") != -1
success = True
assert success
if __name__ == '__main__': if __name__ == '__main__':
if 1: if 1:
unittest.main() unittest.main()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论