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

improving coding

上级 d2f81044
......@@ -4126,14 +4126,13 @@ class Reshape(Op):
x = as_tensor_variable(x)
shp_orig = shp
shp = as_tensor_variable(shp, ndim=1)
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
if not (shp.dtype.startswith('int') or
(isinstance(shp, TensorConstant) and shp.data.size == 0)):
# It raises an error if shp is not of integer type,
# except when shp is constant and empty
# (in this case, shp.dtype does not matter anymore).
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):
bcast = [s == 1 for s in shp.data]
return gof.Apply(self, [x, shp], [tensor(x.type.dtype, bcast)])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论