未验证 提交 d5b4570d 编写于 作者: S ShiningZhang 提交者: GitHub

fix bug: arange can not return shape when enable_static (#42182)

* fix bug: arange can not return shape when enable_static

* fix bug: test_arange
上级 2fe4bf2f
......@@ -827,6 +827,11 @@ def arange(start=0, end=None, step=1, dtype=None, name=None):
end = start
start = 0
out_shape = None
if not isinstance(start, Variable) and not isinstance(
end, Variable) and not isinstance(step, Variable):
out_shape = [int(math.ceil((end - start) / step))]
if not isinstance(dtype, core.VarDesc.VarType):
dtype = convert_np_dtype_to_dtype_(dtype)
......@@ -857,11 +862,6 @@ def arange(start=0, end=None, step=1, dtype=None, name=None):
out.stop_gradient = True
return out
out_shape = None
if not isinstance(start, Variable) and not isinstance(
end, Variable) and not isinstance(step, Variable):
out_shape = [int(math.ceil((end - start) / step))]
check_dtype(dtype, 'dtype', ['float32', 'float64', 'int32', 'int64'],
'range/arange')
helper = LayerHelper('range', **locals())
......@@ -873,6 +873,8 @@ def arange(start=0, end=None, step=1, dtype=None, name=None):
'Step': step},
outputs={'Out': out})
out.stop_gradient = True
if out_shape is not None:
out.desc.set_shape(out_shape)
return out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册