1 /**
2 * Copyright 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/log1p.h"
18 #include <memory>
19 #include <set>
20 #include "ops/op_utils.h"
21 #include "utils/check_convert_utils.h"
22 #include "utils/tensor_construct_utils.h"
23 #include "abstract/primitive_infer_map.h"
24
25 namespace mindspore {
26 namespace ops {
27 // log1p
28 namespace {
Log1pInferShape(const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)29 abstract::ShapePtr Log1pInferShape(const PrimitivePtr &primitive, const std::vector<AbstractBasePtr> &input_args) {
30 MS_EXCEPTION_IF_NULL(primitive);
31 auto shape_map = CheckAndConvertUtils::ConvertShapePtrToShapeMap(input_args[0]->BuildShape());
32 auto in_shape = shape_map[kShape];
33 auto min_shape = shape_map[kMinShape];
34 auto max_shape = shape_map[kMaxShape];
35 return std::make_shared<abstract::Shape>(in_shape, min_shape, max_shape);
36 }
37
Log1pInferType(const PrimitivePtr & prim,const std::vector<AbstractBasePtr> & input_args)38 TypePtr Log1pInferType(const PrimitivePtr &prim, const std::vector<AbstractBasePtr> &input_args) {
39 MS_EXCEPTION_IF_NULL(prim);
40 auto prim_name = prim->name();
41 // check
42 std::set<TypePtr> valid_index_types = {kFloat16, kFloat32};
43 auto x_type = input_args[0]->BuildType();
44 (void)CheckAndConvertUtils::CheckTensorTypeValid("x", input_args[0]->BuildType(), valid_index_types, prim_name);
45 return x_type;
46 }
47 } // namespace
48
Log1pInfer(const abstract::AnalysisEnginePtr &,const PrimitivePtr & primitive,const std::vector<AbstractBasePtr> & input_args)49 AbstractBasePtr Log1pInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive,
50 const std::vector<AbstractBasePtr> &input_args) {
51 MS_EXCEPTION_IF_NULL(primitive);
52 return abstract::MakeAbstract(Log1pInferShape(primitive, input_args), Log1pInferType(primitive, input_args));
53 }
54 REGISTER_PRIMITIVE_EVAL_IMPL(Log1p, prim::kPrimLog1p, Log1pInfer, nullptr, true);
55 } // namespace ops
56 } // namespace mindspore
57