From f7c7c98a51f58ec3b2069e6e373214b48afdbd5d Mon Sep 17 00:00:00 2001 From: quinlan-w <39792792+quinlan-w@users.noreply.github.com> Date: Sun, 15 May 2022 22:51:04 +0800 Subject: [PATCH] fix pad bug, which could drop accuracy (#1341) Co-authored-by: Zhiquan Wang --- source/device/cpu/op/pad/pad_ref.c | 32 ++++++------------------------ 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/source/device/cpu/op/pad/pad_ref.c b/source/device/cpu/op/pad/pad_ref.c index fc5c93ec..85365bc8 100644 --- a/source/device/cpu/op/pad/pad_ref.c +++ b/source/device/cpu/op/pad/pad_ref.c @@ -73,21 +73,11 @@ static void ref_pad_fp32(float* input, float* output, int in_h, int in_w, int ou { outptr[x] = v; } - if (in_w < 12) + for (x = 0; x < in_w; x++) { - for (; x < (left + in_w); x++) - { - outptr[x] = ptr[x - left]; - } + outptr[left + x] = ptr[x]; } - else - { - for (x = 0; x < in_w; x++) - { - outptr[left + x] = ptr[x]; - } - } - for (; x < out_w; x++) + for (x = out_w - left; x < out_w; x++) { outptr[x] = v; } @@ -331,21 +321,11 @@ static void ref_pad_uint8(uint8_t* input, uint8_t* output, int in_h, int in_w, i { outptr[x] = v; } - if (in_w < 12) + for (x = 0; x < in_w; x++) { - for (; x < (left + in_w); x++) - { - outptr[x] = ptr[x - left]; - } + outptr[left + x] = ptr[x]; } - else - { - for (x = 0; x < in_w; x++) - { - outptr[left + x] = ptr[x]; - } - } - for (; x < out_w; x++) + for (x = out_w - left; x < out_w; x++) { outptr[x] = v; } -- GitLab