提交 690133b4 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!2724 fix IndexError to TypeError

Merge pull request !2724 from amongo/FixTensor0DimIndexError
...@@ -207,8 +207,8 @@ def tensor_index_by_slice(data, slice_index): ...@@ -207,8 +207,8 @@ def tensor_index_by_slice(data, slice_index):
"""Tensor getitem by a single slice""" """Tensor getitem by a single slice"""
shape = F.shape(data) shape = F.shape(data)
if not shape: if not shape:
const_utils.raise_index_error("When tensor is indexed by a slice, the dimension of the tensor\ const_utils.raise_index_error("When tensor is indexed by a slice, the dimension of the tensor"
cannot be 0.") "cannot be 0.")
begin_strides, end_strides, step_strides = const_utils.get_stride_info_from_slice(shape, slice_index) begin_strides, end_strides, step_strides = const_utils.get_stride_info_from_slice(shape, slice_index)
return F.strided_slice(data, begin_strides, end_strides, step_strides) return F.strided_slice(data, begin_strides, end_strides, step_strides)
...@@ -217,8 +217,8 @@ def _tensor_index_by_integer(data, number): ...@@ -217,8 +217,8 @@ def _tensor_index_by_integer(data, number):
"""Tensor getitem by a single integer number""" """Tensor getitem by a single integer number"""
shape = F.shape(data) shape = F.shape(data)
if not shape: if not shape:
return const_utils.raise_index_error("When tensor is indexed by an integer,\ return const_utils.raise_type_error("When tensor is indexed by an integer,"
the dimension of the tensor cannot be 0.") "the dimension of the tensor cannot be 0.")
if number >= shape[0]: if number >= shape[0]:
return const_utils.raise_index_error("index {} is out of bounds for axis 0 with size {}".format( return const_utils.raise_index_error("index {} is out of bounds for axis 0 with size {}".format(
number, shape[0])) number, shape[0]))
......
...@@ -44,6 +44,10 @@ SET_ITEM_BY_TUPLE_OF_TENSOR = 1 ...@@ -44,6 +44,10 @@ SET_ITEM_BY_TUPLE_OF_TENSOR = 1
def raise_index_error(msg): def raise_index_error(msg):
raise IndexError(msg) raise IndexError(msg)
@constexpr
def raise_type_error(msg):
raise TypeError(msg)
@constexpr @constexpr
def check_equal(param1, param2, msg="{},{}"): def check_equal(param1, param2, msg="{},{}"):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册