IndexError to TypeError

pull/2724/head
huangdongrun 5 years ago
parent f65756162e
commit 9cebb1630b

@ -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):
"""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
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="{},{}"):

Loading…
Cancel
Save