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 <vector>
19 #include <memory>
20 #include "ops/logical_and.h"
21
22 #include "ops/op_utils.h"
23 #include "utils/check_convert_utils.h"
24 #include "abstract/primitive_infer_map.h"
25
26 namespace mindspore {
27 namespace ops {
28 namespace {
InferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)29 abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
30 MS_EXCEPTION_IF_NULL(primitive);
31 auto op_name = primitive->name();
32 return BroadCastInferShape(op_name, input_args);
33 }
34
InferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)35 TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
36 for (const auto &item : input_args) {
37 MS_EXCEPTION_IF_NULL(item);
38 }
39 std::map<std::string, TypePtr> types;
40 const std::set<TypePtr> valid_types = {kBool};
41 (void)types.emplace("x", input_args[0]->BuildType());
42 (void)types.emplace("y", input_args[1]->BuildType());
43 return CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name());
44 }
45 } // namespace
46
LogicalAndInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)47 AbstractBasePtr LogicalAndInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
48 const std::vector<AbstractBasePtr> &input_args) {
49 return std::make_shared<abstract::AbstractTensor>(InferType(primitive, input_args),
50 InferShape(primitive, input_args)->shape());
51 }
52 REGISTER_PRIMITIVE_C(kNameLogicalAnd, LogicalAnd);
53 } // namespace ops
54 } // namespace mindspore
55