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 "ops/logical_not.h"
18
19 #include <set>
20
21 #include "ops/op_utils.h"
22
23 namespace mindspore {
24 namespace ops {
25 namespace {
LogicalNotInferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)26 abstract::ShapePtr LogicalNotInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
27 MS_EXCEPTION_IF_NULL(primitive);
28 auto in_shape = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape())[kShape];
29 return std::make_shared<abstract::Shape>(in_shape);
30 }
31
LogicalNotInferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)32 TypePtr LogicalNotInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
33 MS_EXCEPTION_IF_NULL(prim);
34 auto op_name = prim->name();
35 MS_EXCEPTION_IF_NULL(input_args[0]);
36 auto infer_dtype = input_args[0]->BuildType();
37 std::set<TypePtr> local_bool = {kBool};
38 return CheckAndConvertUtils::CheckTensorTypeValid("x", infer_dtype, local_bool, op_name);
39 }
40 } // namespace
LogicalNotInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)41 AbstractBasePtr LogicalNotInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
42 const std::vector<AbstractBasePtr> &input_args) {
43 return std::make_shared<abstract::AbstractTensor>(LogicalNotInferType(primitive, input_args),
44 LogicalNotInferShape(primitive, input_args)->shape());
45 }
46 REGISTER_PRIMITIVE_C(kNameLogicalNot, LogicalNot);
47 } // namespace ops
48 } // namespace mindspore
49