!3528 Fix the difference of Error type between graph&pynative mode

Merge pull request !3528 from Simson/push-to-opensource
This commit is contained in:
mindspore-ci-bot 2020-07-28 09:26:49 +08:00 committed by Gitee
commit 72e45841a2
2 changed files with 5 additions and 4 deletions

View File

@ -150,11 +150,12 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr
for (size_t index = 0; index < args_size; index++) {
MS_EXCEPTION_IF_NULL(args_spec_list[index]);
if (!args_spec_list[index]->isa<AbstractScalar>() && !args_spec_list[index]->isa<AbstractNone>()) {
MS_LOG(EXCEPTION) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone.";
MS_EXCEPTION(TypeError) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone.";
}
if (args_spec_list[index]->isa<AbstractScalar>() &&
!dyn_cast<AbstractScalar>(args_spec_list[index])->BuildValue()->isa<Int32Imm>()) {
MS_LOG(EXCEPTION) << "MakeSlice eval " << index << " parameter is an AbstractScalar, but is not an int32 number.";
MS_EXCEPTION(TypeError) << "MakeSlice eval " << index
<< " parameter is an AbstractScalar, but is not an int32 number.";
}
}
// Slice: start, end, step

View File

@ -114,13 +114,13 @@ test_cases = [
test_cases_for_verify_exception = [
('SliceStartCross', {
'block': (NetWork_3(), {'exception': RuntimeError}),
'block': (NetWork_3(), {'exception': TypeError}),
'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))],
}),
('SliceStepZero', {
'block': (NetWork_3(), {'exception': RuntimeError}),
'block': (NetWork_3(), {'exception': TypeError}),
'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))],