提交 26d6d1c2 authored 作者: Sina Honari's avatar Sina Honari

improving coding

上级 d2f81044
...@@ -4126,14 +4126,13 @@ class Reshape(Op): ...@@ -4126,14 +4126,13 @@ 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') and not(isinstance(shp, if not (shp.dtype.startswith('int') or
TensorConstant) and (isinstance(shp, TensorConstant) and shp.data.size == 0)):
shp.data.size == 0): # It raises an error if shp is not of integer type,
# if shp is an instace of TensorConstant and # except when shp is constant and empty
# shp.data is empty, then shp.dtype is float64 # (in this case, shp.dtype does not matter anymore).
raise TypeError("Shape must be integers", shp, shp.dtype) raise TypeError("Shape must be integers", shp, shp.dtype)
if not(isinstance(shp, TensorConstant) and not shp.data.size == 0): assert shp.ndim == 1
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论