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/exp.h"
18 #include <map>
19 #include <string>
20 #include <vector>
21 #include <set>
22 #include <memory>
23 #include "ops/op_utils.h"
24 #include "utils/check_convert_utils.h"
25 #include "abstract/primitive_infer_map.h"
26
27 namespace mindspore {
28 namespace ops {
29 namespace {
InferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)30 abstract::ShapePtr InferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
31 MS_EXCEPTION_IF_NULL(primitive);
32 auto prim_name = primitive->name();
33 (void)CheckAndConvertUtils::CheckInteger("input numbers", int64_t(input_args.size()), kEqual, 1, prim_name);
34 for (const auto &item : input_args) {
35 MS_EXCEPTION_IF_NULL(item);
36 }
37 auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape());
38 auto in_shape = shape_map[kShape];
39 auto min_shape = shape_map[kMinShape];
40 auto max_shape = shape_map[kMaxShape];
41 if (min_shape.size() != 0 && max_shape.size() != 0) {
42 return std::make_shared<abstract::Shape>(in_shape, min_shape, max_shape);
43 }
44 return std::make_shared<abstract::Shape>(in_shape);
45 }
46
InferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)47 TypePtr InferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
48 MS_EXCEPTION_IF_NULL(prim);
49 (void)CheckAndConvertUtils::CheckInteger("input number", SizeToLong(input_args.size()), kEqual, 1, prim->name());
50 for (const auto &item : input_args) {
51 MS_EXCEPTION_IF_NULL(item);
52 }
53 std::map<std::string, TypePtr> types;
54 (void)types.emplace("x", input_args[0]->BuildType());
55 std::set<TypePtr> valid_params_types = {kTensorType};
56 (void)CheckAndConvertUtils::CheckSubClass("x_type", input_args[0]->BuildType(), valid_params_types, prim->name());
57 return CheckAndConvertUtils::CheckTensorTypeSame(types, common_valid_types, prim->name());
58 }
59 } // namespace
ExpInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)60 AbstractBasePtr ExpInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
61 const std::vector<AbstractBasePtr> &input_args) {
62 return abstract::MakeAbstract(InferShape(primitive, input_args), InferType(primitive, input_args));
63 }
64 REGISTER_PRIMITIVE_C(kNameExp, Exp);
65 } // namespace ops
66 } // namespace mindspore
67