提交 0ed10855 authored 作者: Sina Honari's avatar Sina Honari

theano.tensor.constant reshape fix

上级 7ba9c052
...@@ -4126,9 +4126,14 @@ class Reshape(Op): ...@@ -4126,9 +4126,14 @@ class Reshape(Op):
x = as_tensor_variable(x) x = as_tensor_variable(x)
shp_orig = shp shp_orig = shp
shp = as_tensor_variable(shp, ndim=1) shp = as_tensor_variable(shp, ndim=1)
if not shp.dtype.startswith('int'): if not shp.dtype.startswith('int') and not(isinstance(shp,
TensorConstant)
and shp.data.size == 0):
# if shp is an instace of TensorConstant and
# shp.data is empty, then shp.dtype is float64
raise TypeError("Shape must be integers", shp, shp.dtype) raise TypeError("Shape must be integers", shp, shp.dtype)
assert shp.ndim == 1 if not(isinstance(shp, TensorConstant) and not shp.data.size == 0):
assert shp.ndim == 1
if isinstance(shp, TensorConstant): if isinstance(shp, TensorConstant):
bcast = [s == 1 for s in shp.data] bcast = [s == 1 for s in shp.data]
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)]) return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论