!14999 fix ci bug nullptr on type id

From: @simson_wu
Reviewed-by: @zhoufeng54,@xsmq
Signed-off-by: @xsmq
This commit is contained in:
mindspore-ci-bot 2021-04-12 16:46:19 +08:00 committed by Gitee
commit c5b9b1b53a
2 changed files with 10 additions and 2 deletions

View File

@ -53,8 +53,14 @@ tensor::TensorPtr TensorConstructUtils::CreateTensor(const TypePtr type_ptr, con
TypeId TensorConstructUtils::ExtractTypeId(const TypePtr type_ptr) {
MS_EXCEPTION_IF_NULL(type_ptr);
auto tensor_type = type_ptr->cast<TensorTypePtr>();
auto type_id = tensor_type->element()->type_id();
TypeId type_id;
if (type_ptr->isa<TensorType>()) {
auto tensor_type = type_ptr->cast<TensorTypePtr>();
MS_EXCEPTION_IF_NULL(tensor_type);
type_id = tensor_type->element()->type_id();
} else {
type_id = type_ptr->type_id();
}
return type_id;
}
} // namespace mindspore

View File

@ -33,6 +33,8 @@ class TensorConstructUtils {
static tensor::TensorPtr CreateZerosTensor(const TypePtr type, const std::vector<int64_t> &shape);
static tensor::TensorPtr CreateOnesTensor(const TypePtr type, const std::vector<int64_t> &shape);
static tensor::TensorPtr CreateTensor(const TypePtr type, const std::vector<int64_t> &shape, void *data);
private:
static TypeId ExtractTypeId(const TypePtr type);
};
} // namespace mindspore