提交 2d6d3cc8 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!2339 support catch IndexError in C++

Merge pull request !2339 from zhangbuxue/support_catch_index_error_in_c++
...@@ -540,6 +540,9 @@ bool ExecutorPy::Compile(const py::object &obj, const py::tuple &args, const py: ...@@ -540,6 +540,9 @@ bool ExecutorPy::Compile(const py::object &obj, const py::tuple &args, const py:
} catch (const py::value_error &ex) { } catch (const py::value_error &ex) {
ReleaseResource(phase); ReleaseResource(phase);
throw py::value_error(ex); throw py::value_error(ex);
} catch (const py::index_error &ex) {
ReleaseResource(phase);
throw py::index_error(ex);
} catch (const std::exception &ex) { } catch (const std::exception &ex) {
ReleaseResource(phase); ReleaseResource(phase);
// re-throw this exception to Python interpreter to handle it // re-throw this exception to Python interpreter to handle it
......
...@@ -80,6 +80,17 @@ class NetWork_3(Cell): ...@@ -80,6 +80,17 @@ class NetWork_3(Cell):
return res return res
class NetWorkOutOfBounds(Cell):
""" NetWork_3 definition """
def __init__(self):
super(NetWorkOutOfBounds, self).__init__()
self.addN = P.AddN()
def construct(self, tensor_tuple):
return tensor_tuple[100]
test_cases = [ test_cases = [
('SlicePositive', { ('SlicePositive', {
'block': NetWork_1(), 'block': NetWork_1(),
...@@ -104,16 +115,23 @@ test_cases = [ ...@@ -104,16 +115,23 @@ test_cases = [
test_cases_for_verify_exception = [ test_cases_for_verify_exception = [
('SliceStartCross', { ('SliceStartCross', {
'block': (NetWork_3(), {'exception': RuntimeError}), 'block': (NetWork_3(), {'exception': RuntimeError}),
'desc_inputs': [*(Tensor(np.ones([2, 3, 4], np.int32)), 'desc_inputs': [Tensor(np.ones([2, 3, 4], np.int32)),
Tensor(np.zeros([2, 3, 4], np.int32)), Tensor(np.zeros([2, 3, 4], np.int32)),
Tensor(np.ones([2, 3, 4], np.int32)))], Tensor(np.ones([2, 3, 4], np.int32))],
}), }),
('SliceStepZero', { ('SliceStepZero', {
'block': (NetWork_3(), {'exception': RuntimeError}), 'block': (NetWork_3(), {'exception': RuntimeError}),
'desc_inputs': [*(Tensor(np.ones([2, 3, 4], np.int32)), 'desc_inputs': [Tensor(np.ones([2, 3, 4], np.int32)),
Tensor(np.zeros([2, 3, 4], np.int32)), Tensor(np.zeros([2, 3, 4], np.int32)),
Tensor(np.ones([2, 3, 4], np.int32)))], Tensor(np.ones([2, 3, 4], np.int32))],
}),
('SliceOutOfBounds', {
'block': (NetWorkOutOfBounds(), {'exception': IndexError}),
'desc_inputs': [(Tensor(np.ones([2, 3, 4], np.int32)),
Tensor(np.zeros([2, 3, 4], np.int32)),
Tensor(np.ones([2, 3, 4], np.int32)))],
}), }),
] ]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册