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 <set>
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include <memory>
22
23 #include "ops/merge.h"
24 #include "ops/op_utils.h"
25
26 namespace mindspore {
27 namespace ops {
MergeInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)28 AbstractBasePtr MergeInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
29 const std::vector<AbstractBasePtr> &input_args) {
30 MS_EXCEPTION_IF_NULL(primitive);
31 auto op_name = primitive->name();
32 auto inputs_type = input_args[0]->BuildType()->cast<TuplePtr>()->elements();
33 auto inputs_shape = input_args[0]->BuildShape()->cast<abstract::TupleShapePtr>()->shape();
34 std::map<std::string, TypePtr> args;
35 for (size_t i = 0; i != inputs_type.size(); i++) {
36 (void)args.insert(std::make_pair("input[" + std::to_string(i) + "]", inputs_type[i]));
37 }
38 std::set<TypePtr> template_type = common_valid_types;
39 (void)template_type.emplace(kBool);
40 auto infered_type = CheckAndConvertUtils::CheckScalarOrTensorTypesSame(args, template_type, op_name);
41 std::vector<int64_t> in_shape0 = inputs_shape[0]->cast<abstract::ShapePtr>()->shape();
42
43 auto output1 = std::make_shared<abstract::AbstractTensor>(infered_type, in_shape0);
44 auto output2 = std::make_shared<abstract::AbstractTensor>(kInt32, std::vector<int64_t>{1});
45
46 AbstractBasePtrList output = {output1, output2};
47 return std::make_shared<abstract::AbstractTuple>(output);
48 }
49 REGISTER_PRIMITIVE_C(kNameMerge, Merge);
50 } // namespace ops
51 } // namespace mindspore
52