From d0766d2aad33c4afc064fc67bbe6f0877543de0a Mon Sep 17 00:00:00 2001 From: simson Date: Mon, 12 Apr 2021 15:56:31 +0800 Subject: [PATCH] fix ci bug nullptr on type id --- mindspore/core/utils/tensor_construct_utils.cc | 10 ++++++++-- mindspore/core/utils/tensor_construct_utils.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mindspore/core/utils/tensor_construct_utils.cc b/mindspore/core/utils/tensor_construct_utils.cc index a34b205b28..cb8bfc2549 100644 --- a/mindspore/core/utils/tensor_construct_utils.cc +++ b/mindspore/core/utils/tensor_construct_utils.cc @@ -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(); - auto type_id = tensor_type->element()->type_id(); + TypeId type_id; + if (type_ptr->isa()) { + auto tensor_type = type_ptr->cast(); + 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 diff --git a/mindspore/core/utils/tensor_construct_utils.h b/mindspore/core/utils/tensor_construct_utils.h index 72dac8f4cc..ec08c122e5 100644 --- a/mindspore/core/utils/tensor_construct_utils.h +++ b/mindspore/core/utils/tensor_construct_utils.h @@ -33,6 +33,8 @@ class TensorConstructUtils { static tensor::TensorPtr CreateZerosTensor(const TypePtr type, const std::vector &shape); static tensor::TensorPtr CreateOnesTensor(const TypePtr type, const std::vector &shape); static tensor::TensorPtr CreateTensor(const TypePtr type, const std::vector &shape, void *data); + + private: static TypeId ExtractTypeId(const TypePtr type); }; } // namespace mindspore