Merge pull request !21536 from zhaodezan/master_fix_magic
This commit is contained in:
i-robot 2021-08-10 03:05:26 +00:00 committed by Gitee
commit d162fb0c92
6 changed files with 42 additions and 26 deletions

View File

@ -55,10 +55,10 @@ int ArithmeticGradInferShape(const TensorC *const *inputs, size_t inputs_size, T
if (GetElementNum(dx1) < GetElementNum(dx2)) {
param->ndim_ = in_shape1_size;
param->in_elements_num0_ = param->ndim_;
param->in_elements_num1_ = param->ndim_;
param->out_elements_num_ = param->ndim_;
int fill_dim_num = in_shape1_size - in_shape0_size; // This will not work for batch!
param->in_elements_num0_ = (int)param->ndim_;
param->in_elements_num1_ = (int)param->ndim_;
param->out_elements_num_ = (int)param->ndim_;
size_t fill_dim_num = in_shape1_size - in_shape0_size; // This will not work for batch!
int j = 0;
for (unsigned int i = 0; i < in_shape1_size; i++) {
if (i < fill_dim_num) {
@ -76,7 +76,7 @@ int ArithmeticGradInferShape(const TensorC *const *inputs, size_t inputs_size, T
param->out_elements_num_ = param->ndim_;
param->broadcasting_ = true;
int j = 0;
int fill_dim_num = in_shape0_size - in_shape1_size;
size_t fill_dim_num = in_shape0_size - in_shape1_size;
for (unsigned int i = 0; i < in_shape0_size; i++) {
if (i < fill_dim_num) {
param->in_shape1_[i] = 1;

View File

@ -107,7 +107,7 @@ int TensorListSetItemInferShape(const TensorC *const *inputs, size_t inputs_size
}
out_shape.shape_[index] = (int *)(value_tensor->shape_);
out_shape.shape_size_[index] = value_tensor->shape_size_;
out_shape.shape_size_[index] = (int)value_tensor->shape_size_;
int ret = MallocTensorListData(output0, input0->tensors_data_type_, &out_shape);
if (ret != NNACL_OK) {
free(out_shape.shape_);

View File

@ -40,7 +40,7 @@ int Conv2dGradInputInferShape(const TensorC *const *inputs, size_t inputs_size,
if (inputs[2]->shape_size_ < 1 || inputs[2]->data_ == NULL) {
return NNACL_ERR;
}
size_t data_size = inputs[2]->shape_[0];
size_t data_size = (size_t)inputs[2]->shape_[0];
if (data_size != 4) {
return NNACL_ERR;
}

View File

@ -190,6 +190,9 @@ int ReshapeInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC
return NNACL_INFER_INVALID;
}
int shape_size = GetElementNum(shape_tensor);
if (shape_size > MAX_SHAPE_SIZE) {
return NNACL_ERR;
}
int calRet = CalShapeByType(inputs, shape_size, out_shape, &out_shape_size);
if (calRet != NNACL_OK) {
return calRet;

View File

@ -32,6 +32,35 @@ static bool CheckInputsDataType(const TensorC *const *inputs, size_t inputs_size
return true;
}
int InitBeginAndSizeParam(const TensorC *const *inputs, SliceParameter *param) {
/* init begin parameter */
int slice_begin_size = GetElementNum(inputs[1]);
int *begin_ptr = (int *)(inputs[1]->data_);
if (slice_begin_size != param->param_length_ || begin_ptr == NULL) {
return NNACL_INFER_INVALID;
}
if (slice_begin_size > MAX_AXIS_SIZE) {
return NNACL_ERR;
}
for (size_t i = 0; i < slice_begin_size; i++) {
param->begin_[i] = begin_ptr[i];
}
/* init size parameter */
int slice_size_size = GetElementNum(inputs[2]);
int *size_ptr = (int *)(inputs[2]->data_);
if (slice_size_size != param->param_length_ || size_ptr == NULL) {
return NNACL_INFER_INVALID;
}
if (slice_size_size > MAX_AXIS_SIZE) {
return NNACL_ERR;
}
for (size_t i = 0; i < slice_size_size; i++) {
param->size_[i] = size_ptr[i];
}
return NNACL_OK;
}
int SliceInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
OpParameter *parameter) {
int ret = CheckAugmentWithMinSize(inputs, inputs_size, outputs, outputs_size, parameter, 3, 1);
@ -57,24 +86,8 @@ int SliceInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **
param->param_length_ = (int)(input->shape_size_);
output->shape_size_ = input->shape_size_;
/* init begin parameter */
int slice_begin_size = GetElementNum(inputs[1]);
int *begin_ptr = (int *)(inputs[1]->data_);
if (slice_begin_size != param->param_length_ || begin_ptr == NULL) {
return NNACL_INFER_INVALID;
}
for (size_t i = 0; i < slice_begin_size; i++) {
param->begin_[i] = begin_ptr[i];
}
/* init size parameter */
int slice_size_size = GetElementNum(inputs[2]);
int *size_ptr = (int *)(inputs[2]->data_);
if (slice_size_size != param->param_length_ || size_ptr == NULL) {
return NNACL_INFER_INVALID;
}
for (size_t i = 0; i < slice_size_size; i++) {
param->size_[i] = size_ptr[i];
if (InitBeginAndSizeParam(inputs, param) != NNACL_OK) {
return NNACL_ERR;
}
/* infer output shape information */

View File

@ -40,7 +40,7 @@ int SqueezeInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC
size_t out_shape_size = 0;
for (size_t i = 0; i < param->axis_size_; i++) {
param->axis_[i] = param->axis_[i] >= 0 ? param->axis_[i] : param->axis_[i] + input->shape_size_;
param->axis_[i] = param->axis_[i] >= 0 ? param->axis_[i] : param->axis_[i] + (int)input->shape_size_;
}
if (param->axis_size_ == 0) {