Skip to content

Commit

Permalink
range can not return shape when enable_static (#42275)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiningZhang committed Apr 26, 2022
1 parent eb64983 commit 3cdc7a0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python/paddle/fluid/layers/tensor.py
Expand Up @@ -1470,6 +1470,11 @@ def range(start, end, step, dtype, name=None):
# [3, 4, 5, 6]
"""
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)

Expand Down Expand Up @@ -1500,11 +1505,6 @@ def range(start, end, step, dtype, 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())
Expand All @@ -1516,6 +1516,8 @@ def range(start, end, step, dtype, 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


Expand Down

0 comments on commit 3cdc7a0

Please sign in to comment.