提交 752cc01a authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5380 from happygds/happygds-patch-1

compatible when axis < 0 in tensor.roll(x, shift, axis=None)
......@@ -4219,6 +4219,9 @@ def roll(x, shift, axis=None):
else:
axis = 0
if axis < 0:
axis += x.ndim
# Shift may be larger than the size of the axis. If so, since the
# roll operation is cyclic, we can take the shift modulo the size
# of the axis
......
......@@ -3838,6 +3838,15 @@ class T_Join_and_Split(unittest.TestCase):
want = numpy.roll(a.get_value(borrow=True), -2, 1)
out = theano.function([], b)()
assert (out == want).all()
# Test example when axis < 0 - ensure that behavior matches numpy.roll behavior
a = self.shared(numpy.arange(24).reshape((3, 2, 4)).astype(self.floatX))
b = roll(a, get_shift(-2), -2)
want = numpy.roll(a.get_value(borrow=True), -2, -2)
out = theano.function([], b)()
assert (out == want).all()
# Test rolling on axis 0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论