提交 0a532cbd authored 作者: Eric Larsen's avatar Eric Larsen 提交者: Frederic

corrections to infer_shape in Reshape and Tile

上级 14181bd4
...@@ -5548,9 +5548,18 @@ class Tile(Op): ...@@ -5548,9 +5548,18 @@ class Tile(Op):
def infer_shape(self, node, in_shapes): def infer_shape(self, node, in_shapes):
# Note: in contrast with numpy, it is assumed that x.shape and reps # Note: in contrast with numpy, it is assumed that x.shape and reps
# have equal length; see alsor tile function below # have equal length; see also tile function below
# Note: if reps were to be allowed not to be a constant and x.shape
# and reps to be unequal, the following block of code could be used:
## prepend 1 to x.shape if needed
# if self.ndim > x.ndim:
# shp = concatenate(ones(self.ndim - x.ndim), shp)
## prepend 1 to reps if needed
# reps = concatenate(ones(self.ndim - reps.shape[0]), reps)
x, reps = node.inputs x, reps = node.inputs
shp = x.shape shp = in_shapes[0]
tiled_shp = shp * reps tiled_shp = shp * reps
out_shape = [] out_shape = []
for i in range(self.ndim): for i in range(self.ndim):
...@@ -5575,10 +5584,12 @@ def tile(x, reps, ndim=None): ...@@ -5575,10 +5584,12 @@ def tile(x, reps, ndim=None):
TODO: expand this. TODO: expand this.
""" """
if isinstance(reps, theano.tensor.TensorVariable): try:
raise ValueError("'reps' argument to 'tile' must be a constant (e.g. " assert python_all([int(i) == i for i in iter(reps)])
except (TypeError, AssertionError):
raise ValueError("reps argument to tile must be a constant (e.g. "
"tuple, list of integers)") "tuple, list of integers)")
elif len(reps) != x.ndim: if len(reps) != x.ndim:
raise ValueError("len(reps) != x.ndim not currently supported") raise ValueError("len(reps) != x.ndim not currently supported")
elif (ndim is not None) and ndim != x.ndim: elif (ndim is not None) and ndim != x.ndim:
raise ValueError("if specified, ndim must be equal to both x.ndim and " raise ValueError("if specified, ndim must be equal to both x.ndim and "
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论