1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "ir/meta_tensor.h" 18 19 #include <functional> 20 #include <numeric> 21 #include <vector> 22 #include <sstream> 23 #include <string> 24 25 #include "abstract/abstract_value.h" 26 27 namespace mindspore { 28 namespace tensor { ToAbstract()29abstract::AbstractBasePtr MetaTensor::ToAbstract() { 30 auto tens = shared_from_base<MetaTensor>(); 31 auto dtype = tens->Dtype(); 32 if (!IsSubType(dtype, kNumber)) { 33 MS_LOG(EXCEPTION) << "Expect MetaTensor type kNumber but got: " << dtype->ToString() << "."; 34 } 35 auto tensor_shape = tens->shape(); 36 auto abs_tensor = std::make_shared<abstract::AbstractTensor>(dtype, tensor_shape); 37 38 // if is parameter always no value. 39 if (is_parameter_) { 40 auto param_name = param_info_->name(); 41 auto ref_key = std::make_shared<RefKey>(param_name); 42 auto abs_ref_key = ref_key->ToAbstract(); 43 abs_tensor = std::make_shared<abstract::AbstractRef>(abs_ref_key, abs_tensor); 44 } else { 45 abs_tensor->set_value(shared_from_base<MetaTensor>()); 46 } 47 return abs_tensor; 48 } 49 Dtype() const50TypePtr MetaTensor::Dtype() const { return TypeIdToType(data_type_); } 51 } // namespace tensor 52 } // namespace mindspore 53