1 /**
2 * Copyright 2020-2021 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 "ops/add.h"
18 #include <algorithm>
19 #include <memory>
20 #include <vector>
21 #include "ops/op_utils.h"
22 #include "utils/check_convert_utils.h"
23 #include "abstract/primitive_infer_map.h"
24
25 namespace mindspore {
26 namespace ops {
AddInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)27 AbstractBasePtr AddInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
28 const std::vector<AbstractBasePtr> &input_args) {
29 MS_EXCEPTION_IF_NULL(primitive);
30 auto prim_name = primitive->name();
31 const int64_t input_num = 2;
32 (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, input_num, prim_name);
33 for (const auto &item : input_args) {
34 MS_EXCEPTION_IF_NULL(item);
35 }
36 auto output_shape = BroadCastInferShape(prim_name, input_args);
37
38 std::map<std::string, TypePtr> types;
39 (void)types.emplace("x", input_args[0]->BuildType());
40 (void)types.emplace("y", input_args[1]->BuildType());
41 auto output_type = CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim_name);
42 return abstract::MakeAbstract(output_shape, output_type);
43 }
44 REGISTER_PRIMITIVE_C(kNameAdd, Add);
45 } // namespace ops
46 } // namespace mindspore
47