• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2022 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 #include "ops/tan.h"
17 
18 #include <memory>
19 #include <set>
20 #include <vector>
21 
22 #include "abstract/abstract_value.h"
23 #include "abstract/dshape.h"
24 #include "abstract/ops/op_infer.h"
25 #include "abstract/ops/primitive_infer_map.h"
26 #include "abstract/utils.h"
27 #include "base/base.h"
28 #include "ir/anf.h"
29 #include "ir/dtype/number.h"
30 #include "ir/primitive.h"
31 #include "mindapi/src/helper.h"
32 #include "mindspore/core/ops/math_ops.h"
33 #include "ops/op_name.h"
34 #include "ops/primitive_c.h"
35 #include "utils/check_convert_utils.h"
36 #include "utils/log_adapter.h"
37 
38 namespace mindspore {
39 namespace ops {
40 namespace {
TanInferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)41 abstract::ShapePtr TanInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
42   MS_EXCEPTION_IF_NULL(primitive);
43   auto prim_name = primitive->name();
44   (void)CheckAndConvertUtils::CheckArgsType(prim_name, input_args, 0, kObjectTypeTensorType);
45   auto x = input_args[0]->GetShape();
46   MS_EXCEPTION_IF_NULL(x);
47   auto shape_element = x->cast<abstract::ShapePtr>();
48   MS_EXCEPTION_IF_NULL(shape_element);
49   return shape_element;
50 }
51 
TanInferType(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)52 TypePtr TanInferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
53   MS_EXCEPTION_IF_NULL(primitive);
54   auto prim_name = primitive->name();
55   const std::set<TypePtr> valid_types = {kInt32, kInt64, kFloat16, kFloat32, kFloat64, kComplex64, kComplex128};
56   auto x_type = input_args[kInputIndex0]->GetType();
57   (void)CheckAndConvertUtils::CheckTensorTypeValid("x", x_type, valid_types, prim_name);
58   return input_args[kInputIndex0]->GetType();
59 }
60 }  // namespace
61 
62 MIND_API_OPERATOR_IMPL(Tan, BaseOperator);
TanInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)63 AbstractBasePtr TanInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
64                          const std::vector<AbstractBasePtr> &input_args) {
65   MS_EXCEPTION_IF_NULL(primitive);
66   const int64_t input_num = 1;
67   CheckAndConvertUtils::CheckInputArgs(input_args, kEqual, input_num, primitive->name());
68   auto types = TanInferType(primitive, input_args);
69   auto shapes = TanInferShape(primitive, input_args);
70   return abstract::MakeAbstract(shapes, types);
71 }
72 
73 // AG means auto generated
74 class MIND_API AGTanInfer : public abstract::OpInferBase {
75  public:
InferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const76   BaseShapePtr InferShape(const PrimitivePtr &primitive,
77                           const std::vector<AbstractBasePtr> &input_args) const override {
78     return TanInferShape(primitive, input_args);
79   }
80 
InferType(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const81   TypePtr InferType(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) const override {
82     return TanInferType(primitive, input_args);
83   }
InferShapeAndType(const abstract::AnalysisEnginePtr & engine,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args) const84   AbstractBasePtr InferShapeAndType(const abstract::AnalysisEnginePtr &engine, const PrimitivePtr &primitive,
85                                     const std::vector<AbstractBasePtr> &input_args) const override {
86     return TanInfer(engine, primitive, input_args);
87   }
88 };
89 
90 REGISTER_PRIMITIVE_OP_INFER_IMPL(Tan, prim::kPrimTan, AGTanInfer, false);
91 }  // namespace ops
92 }  // namespace mindspore
93