• 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/fill_infer.h"
18 #include "nnacl/infer/infer_register.h"
19 
FillInferShape(const TensorC * const * inputs,size_t inputs_size,TensorC ** outputs,size_t outputs_size,OpParameter * parameter)20 int FillInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
21                    OpParameter *parameter) {
22   int check_ret = CheckAugmentNullSize(inputs, inputs_size, outputs, outputs_size, parameter, 2, 1);
23   if (check_ret != NNACL_OK) {
24     return check_ret;
25   }
26 
27   const TensorC *input = inputs[0];
28   TensorC *output = outputs[0];
29   SetDataTypeFormat(output, input);
30   if (!InferFlag(inputs, inputs_size)) {
31     return NNACL_INFER_INVALID;
32   }
33 
34   const TensorC *dst_shape_tensor = inputs[1];
35   if (dst_shape_tensor->data_type_ != kNumberTypeInt && dst_shape_tensor->data_type_ != kNumberTypeInt32) {
36     return NNACL_ERR;
37   }
38   const int32_t *dst_shape = (int32_t *)(dst_shape_tensor->data_);
39   int num_dims = 1;
40   if (dst_shape_tensor->shape_size_ != DIMENSION_1D) {
41     return NNACL_ERR;
42   }
43   for (size_t i = 0; i < dst_shape_tensor->shape_size_; ++i) {
44     if (INT_MUL_OVERFLOW(num_dims, dst_shape_tensor->shape_[i])) {
45       return NNACL_ERRCODE_MUL_OVERFLOW;
46     }
47     NNACL_CHECK_FALSE(dst_shape_tensor->shape_[i] < 0, NNACL_ERR);
48     num_dims *= dst_shape_tensor->shape_[i];
49   }
50   if (num_dims != 0 && dst_shape == NULL) {
51     return NNACL_INFER_INVALID;
52   }
53   if (num_dims > MAX_SHAPE_SIZE) {
54     return NNACL_ERR;
55   }
56   int output_shape[MAX_SHAPE_SIZE] = {0};
57   size_t output_shape_size = 0;
58   for (int i = 0; i < num_dims; i++) {
59     ShapePush(output_shape, &output_shape_size, dst_shape[i]);
60   }
61   SetShapeArray(output, output_shape, output_shape_size);
62   return NNACL_OK;
63 }
64 
65 REG_INFER(Fill, PrimType_Fill, FillInferShape)
66