提交 63b0d7ea authored 作者: Nicolas Bouchard's avatar Nicolas Bouchard

Fix RepeatOp.grad

上级 f815e119
...@@ -259,20 +259,18 @@ def squeeze(x, out_nd): ...@@ -259,20 +259,18 @@ def squeeze(x, out_nd):
class RepeatOp(theano.Op): class RepeatOp(theano.Op):
"""Repeat elements of an array. """Repeat elements of an array.
It returns an array which has the same shape as x, except It returns an array which has the same shape as `x`, except
along the given axis. The axis is used to speficy along which along the given axis. The axis is used to speficy along which
axis to repeat values. By default, use the flattened input axis to repeat values. By default, use the flattened input
array, and return a flat output array. array, and return a flat output array.
The number of repetitions for each element is repeat. The number of repetitions for each element is `repeat`.
repeats is broadcasted to fit the shape of the given axis. `repeats` is broadcasted to fit the length of the given `axis`.
Parameter: :param x: Input data, tensor variable.
x -- Input data, tensor variable. :param repeats: int, scalar or tensor variable.
repeats -- int, tensor variable.
Keywords arguments: :param axis: int, optional.
axis -- int, optional.
""" """
def __init__(self, axis=None): def __init__(self, axis=None):
...@@ -316,6 +314,9 @@ class RepeatOp(theano.Op): ...@@ -316,6 +314,9 @@ class RepeatOp(theano.Op):
return [gz.reshape(shape, x.ndim + 1).sum(axis=axis), None] return [gz.reshape(shape, x.ndim + 1).sum(axis=axis), None]
elif repeats.ndim == 1: elif repeats.ndim == 1:
# For this implementation, we would need to specify the length
# of repeats in order to split gz in the right way to sum
# the good part.
raise NotImplementedError() raise NotImplementedError()
else: else:
raise ValueError() raise ValueError()
...@@ -344,21 +345,18 @@ class RepeatOp(theano.Op): ...@@ -344,21 +345,18 @@ class RepeatOp(theano.Op):
def repeat(x, repeats, axis=None): def repeat(x, repeats, axis=None):
"""Repeat elements of an array. """Repeat elements of an array.
It returns an array which has the same shape as x, except It returns an array which has the same shape as `x`, except
along the given axis. The axis is used to speficy along which along the given axis. The axis is used to speficy along which
axis to repeat values. By default, use the flattened input axis to repeat values. By default, use the flattened input
array, and return a flat output array. array, and return a flat output array.
The number of repetitions for each element is repeat. The number of repetitions for each element is `repeat`.
repeats is broadcasted to fit the shape of the given axis. `repeats` is broadcasted to fit the length of the given `axis`.
Parameter: :param x: Input data, tensor variable.
x -- Input data, tensor variable. :param repeats: int, scalar or tensor variable.
repeats -- int, tensor variable.
Keywords arguments:
axis -- int, optional.
:param axis: int, optional.
""" """
return RepeatOp(axis=axis)(x, repeats) return RepeatOp(axis=axis)(x, repeats)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论