!20745 fix cpu realdiv, reduce, strideslice bug

Merge pull request !20745 from 范吉斌/bug_master
This commit is contained in:
i-robot 2021-07-23 02:37:57 +00:00 committed by Gitee
commit 77edfdbdef
3 changed files with 7 additions and 5 deletions

View File

@ -104,6 +104,8 @@ void ElementRealDiv(const T *input1, const T *input2, T *out, size_t size, size_
for (size_t i = 0; i < size; ++i) {
auto dividend = input1[idx_1];
auto divisor = input2[idx_2];
idx_1 += delta_1;
idx_2 += delta_2;
if (divisor == zero) {
if (dividend == zero) {
out[i] = std::numeric_limits<T>::quiet_NaN();
@ -117,8 +119,6 @@ void ElementRealDiv(const T *input1, const T *input2, T *out, size_t size, size_
continue;
}
out[i] = dividend / divisor;
idx_1 += delta_1;
idx_2 += delta_2;
}
}

View File

@ -79,8 +79,9 @@ template <typename T>
void ReduceCPUKernel<T>::SimpleReduce(size_t start, size_t end, size_t stride, const T *input_addr, T *output_addr) {
auto pos = start * stride;
for (size_t i = start; i < end; ++i) {
output_addr[i] = 0;
for (size_t j = 0; j < stride; ++j) {
output_addr[i] = input_addr[pos];
pos++;
for (size_t j = 1; j < stride; ++j) {
reduce_func_(input_addr, pos, &output_addr[i]);
pos++;
}

View File

@ -31,7 +31,8 @@ enum PosType { kBegin, kEnd };
int NormalizePos(int pos, int dim_len, PosType pos_type) {
if (pos < 0) {
int normal_pos = pos + dim_len;
normal_pos = std::max(normal_pos, 0);
int threshold = pos_type == kBegin ? 0 : -1;
normal_pos = std::max(normal_pos, threshold);
return normal_pos;
}
int max_pos = pos_type == kBegin ? dim_len - 1 : dim_len;