!14384 fix np arange when tensor has shape 0 in it

From: @yanglf1121
Reviewed-by: @liangchenghui,@zhunaipan
Signed-off-by: @liangchenghui
This commit is contained in:
mindspore-ci-bot 2021-03-31 15:54:43 +08:00 committed by Gitee
commit adc24f4263
1 changed files with 2 additions and 0 deletions

View File

@ -450,6 +450,8 @@ def _tuple_setitem(tup, idx, value):
def _iota(dtype, num, increasing=True):
"""Creates a 1-D tensor with value: [0,1,...num-1] and dtype."""
# TODO: Change to P.Linspace when the kernel is implemented on CPU.
if num <= 0:
raise ValueError("zero shape Tensor is not currently supported.")
if increasing:
return Tensor(list(range(int(num))), dtype)
return Tensor(list(range(int(num)-1, -1, -1)), dtype)