• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "nnacl/infer/power_infer.h"
18 #include "nnacl/infer/infer_register.h"
19 #include "nnacl/tensor_c_utils.h"
20 
PowerInferShape(const TensorC * const * inputs,size_t inputs_size,TensorC ** outputs,size_t outputs_size,OpParameter * parameter)21 int PowerInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
22                     OpParameter *parameter) {
23   int check_ret = CheckAugmentWithMinSize(inputs, inputs_size, outputs, outputs_size, parameter, 1, 1);
24   if (check_ret != NNACL_OK) {
25     return check_ret;
26   }
27 
28   const TensorC *x_tensor = inputs[0];
29   TensorC *exp_tensor = NULL;
30   if (inputs_size == 2) {
31     exp_tensor = (TensorC *)inputs[1];
32     PowParameter *param = (PowParameter *)parameter;
33     float *exp_data = (float *)(exp_tensor->data_);
34     if (exp_data == NULL) {
35       return NNACL_INFER_INVALID;
36     }
37     param->power_ = *exp_data;
38   }
39   TensorC *output_tensor = outputs[0];
40 
41   SetDataTypeFormat(output_tensor, x_tensor);
42   if (!InferFlag(inputs, inputs_size)) {
43     return NNACL_INFER_INVALID;
44   }
45   if (exp_tensor != NULL) {
46     bool exp_x_equal = ShapeEqual(exp_tensor->shape_, exp_tensor->shape_size_, x_tensor->shape_, x_tensor->shape_size_);
47     if (!exp_x_equal && GetElementNum(exp_tensor) != 1) {
48       return NNACL_INPUT_TENSOR_ERROR;
49     }
50   }
51 
52   SetShapeTensor(output_tensor, x_tensor);
53   return NNACL_OK;
54 }
55 
56 REG_INFER(Pow, PrimType_PowFusion, PowerInferShape)
57