| 1 | // Tencent is pleased to support the open source community by making ncnn available. |
| 2 | // |
| 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | // |
| 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except |
| 6 | // in compliance with the License. You may obtain a copy of the License at |
| 7 | // |
| 8 | // https://opensource.org/licenses/BSD-3-Clause |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software distributed |
| 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | // specific language governing permissions and limitations under the License. |
| 14 | |
| 15 | #include "testutil.h" |
| 16 | |
| 17 | static int test_padding(const ncnn::Mat& a, int top, int bottom, int left, int right, int front, int behind, int type, float value, int per_channel_pad_data_size) |
| 18 | { |
| 19 | ncnn::ParamDict pd; |
| 20 | pd.set(0, top); |
| 21 | pd.set(1, bottom); |
| 22 | pd.set(2, left); |
| 23 | pd.set(3, right); |
| 24 | pd.set(4, type); |
| 25 | pd.set(5, value); |
| 26 | pd.set(6, per_channel_pad_data_size); |
| 27 | pd.set(7, front); |
| 28 | pd.set(8, behind); |
| 29 | |
| 30 | std::vector<ncnn::Mat> weights(per_channel_pad_data_size ? 1 : 0); |
| 31 | if (per_channel_pad_data_size) |
| 32 | weights[0] = RandomMat(per_channel_pad_data_size); |
| 33 | |
| 34 | int ret = test_layer("Padding", pd, weights, a); |
| 35 | if (ret != 0) |
| 36 | { |
| 37 | fprintf(stderr, "test_padding failed a.dims=%d a=(%d %d %d %d) top=%d bottom=%d left=%d right=%d front=%d behind=%d type=%d value=%f per_channel_pad_data_size=%d\n", a.dims, a.w, a.h, a.d, a.c, top, bottom, left, right, front, behind, type, value, per_channel_pad_data_size); |
| 38 | } |
| 39 | |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | static int test_padding_0() |
| 44 | { |
| 45 | ncnn::Mat a = RandomMat(9, 10, 11, 96); |
| 46 | ncnn::Mat b = RandomMat(10, 12, 13, 44); |
| 47 | ncnn::Mat c = RandomMat(8, 7, 9, 13); |
| 48 | |
| 49 | return 0 |
| 50 | || test_padding(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 51 | || test_padding(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 52 | || test_padding(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 53 | |
| 54 | || test_padding(a, 2, 2, 2, 2, 2, 2, 0, 1.f, 0) |
| 55 | || test_padding(b, 2, 2, 2, 2, 2, 2, 0, 2.f, 0) |
| 56 | || test_padding(c, 2, 2, 2, 2, 2, 2, 0, -3.f, 0) |
| 57 | |
| 58 | || test_padding(a, 2, 1, 2, 1, 2, 1, 0, 0.f, a.c) |
| 59 | || test_padding(b, 2, 1, 2, 1, 2, 1, 0, 0.f, b.c) |
| 60 | || test_padding(c, 2, 1, 2, 1, 2, 1, 0, 0.f, c.c) |
| 61 | |
| 62 | || test_padding(a, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 63 | || test_padding(b, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 64 | || test_padding(c, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 65 | |
| 66 | || test_padding(a, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 67 | || test_padding(b, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 68 | || test_padding(c, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 69 | |
| 70 | || test_padding(a, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 71 | || test_padding(b, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 72 | || test_padding(c, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 73 | |
| 74 | || test_padding(a, 1, 1, 1, 1, 1, 1, 0, -1.f, 0) |
| 75 | || test_padding(b, 1, 1, 1, 1, 1, 1, 0, -2.f, 0) |
| 76 | || test_padding(c, 1, 1, 1, 1, 1, 1, 0, 3.f, 0); |
| 77 | } |
| 78 | |
| 79 | static int test_padding_1() |
| 80 | { |
| 81 | ncnn::Mat a = RandomMat(9, 11, 96); |
| 82 | ncnn::Mat b = RandomMat(10, 13, 44); |
| 83 | ncnn::Mat c = RandomMat(8, 9, 13); |
| 84 | |
| 85 | return 0 |
| 86 | || test_padding(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 87 | || test_padding(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 88 | || test_padding(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 89 | |
| 90 | || test_padding(a, 2, 2, 2, 2, 0, 0, 0, 1.f, 0) |
| 91 | || test_padding(b, 2, 2, 2, 2, 0, 0, 0, 2.f, 0) |
| 92 | || test_padding(c, 2, 2, 2, 2, 0, 0, 0, -3.f, 0) |
| 93 | |
| 94 | || test_padding(a, 2, 1, 2, 1, 0, 0, 0, 0.f, a.c) |
| 95 | || test_padding(b, 2, 1, 2, 1, 0, 0, 0, 0.f, b.c) |
| 96 | || test_padding(c, 2, 1, 2, 1, 0, 0, 0, 0.f, c.c) |
| 97 | |
| 98 | || test_padding(a, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 99 | || test_padding(b, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 100 | || test_padding(c, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 101 | |
| 102 | || test_padding(a, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 103 | || test_padding(b, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 104 | || test_padding(c, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 105 | |
| 106 | || test_padding(a, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 107 | || test_padding(b, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 108 | || test_padding(c, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 109 | |
| 110 | || test_padding(a, 1, 1, 1, 1, 1, 1, 0, -1.f, 0) |
| 111 | || test_padding(b, 1, 1, 1, 1, 1, 1, 0, -2.f, 0) |
| 112 | || test_padding(c, 1, 1, 1, 1, 1, 1, 0, 3.f, 0) |
| 113 | |
| 114 | || test_padding(a, 2, 1, 0, 0, 2, 3, 0, 0.f, a.c + 5) |
| 115 | || test_padding(b, 2, 1, 0, 0, 2, 3, 0, 0.f, b.c + 5) |
| 116 | || test_padding(c, 2, 1, 0, 0, 2, 3, 0, 0.f, c.c + 5) |
| 117 | |
| 118 | || test_padding(a, 1, 2, 3, 4, 32, 16, 0, 0.f, a.c + 48) |
| 119 | || test_padding(b, 1, 2, 3, 4, 32, 16, 0, 0.f, b.c + 48) |
| 120 | || test_padding(c, 1, 2, 3, 4, 32, 16, 0, 0.f, c.c + 48) |
| 121 | |
| 122 | || test_padding(a, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 123 | || test_padding(b, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 124 | || test_padding(c, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 125 | |
| 126 | || test_padding(a, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 127 | || test_padding(b, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 128 | || test_padding(c, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 129 | |
| 130 | || test_padding(a, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 131 | || test_padding(b, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 132 | || test_padding(c, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 133 | |
| 134 | || test_padding(a, 4, 2, 1, 3, 3, 5, 2, 0.f, 0) |
| 135 | || test_padding(b, 4, 2, 1, 3, 3, 5, 2, 0.f, 0) |
| 136 | || test_padding(c, 4, 2, 1, 3, 3, 5, 2, 0.f, 0); |
| 137 | } |
| 138 | |
| 139 | static int test_padding_2() |
| 140 | { |
| 141 | ncnn::Mat a = RandomMat(15, 96); |
| 142 | ncnn::Mat b = RandomMat(19, 44); |
| 143 | ncnn::Mat c = RandomMat(17, 15); |
| 144 | |
| 145 | return 0 |
| 146 | || test_padding(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 147 | || test_padding(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 148 | || test_padding(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 149 | |
| 150 | || test_padding(a, 0, 0, 1, 1, 0, 0, 0, 1.f, 0) |
| 151 | || test_padding(b, 0, 0, 1, 1, 0, 0, 0, 2.f, 0) |
| 152 | || test_padding(c, 0, 0, 1, 1, 0, 0, 0, -3.f, 0) |
| 153 | |
| 154 | || test_padding(a, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 155 | || test_padding(b, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 156 | || test_padding(c, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 157 | |
| 158 | || test_padding(a, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 159 | || test_padding(b, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 160 | || test_padding(c, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 161 | |
| 162 | || test_padding(a, 2, 2, 2, 2, 0, 0, 0, 1.f, 0) |
| 163 | || test_padding(b, 2, 2, 2, 2, 0, 0, 0, 2.f, 0) |
| 164 | || test_padding(c, 2, 2, 2, 2, 0, 0, 0, -3.f, 0) |
| 165 | |
| 166 | || test_padding(a, 16, 16, 2, 5, 0, 0, 0, -1.f, 0) |
| 167 | || test_padding(b, 16, 16, 2, 5, 0, 0, 0, -2.f, 0) |
| 168 | || test_padding(c, 16, 16, 2, 5, 0, 0, 0, 3.f, 0) |
| 169 | |
| 170 | || test_padding(a, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 171 | || test_padding(b, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 172 | || test_padding(c, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 173 | |
| 174 | || test_padding(a, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 175 | || test_padding(b, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 176 | || test_padding(c, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 177 | |
| 178 | || test_padding(a, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 179 | || test_padding(b, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 180 | || test_padding(c, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 181 | |
| 182 | || test_padding(a, 2, 6, 1, 0, 0, 0, 2, 0.f, 0) |
| 183 | || test_padding(b, 2, 6, 1, 0, 0, 0, 2, 0.f, 0) |
| 184 | || test_padding(c, 2, 6, 1, 0, 0, 0, 2, 0.f, 0); |
| 185 | } |
| 186 | |
| 187 | static int test_padding_3() |
| 188 | { |
| 189 | ncnn::Mat a = RandomMat(128); |
| 190 | ncnn::Mat b = RandomMat(124); |
| 191 | ncnn::Mat c = RandomMat(127); |
| 192 | |
| 193 | return 0 |
| 194 | || test_padding(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 195 | || test_padding(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 196 | || test_padding(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 197 | |
| 198 | || test_padding(a, 0, 0, 2, 2, 0, 0, 0, 1.f, 0) |
| 199 | || test_padding(b, 0, 0, 2, 2, 0, 0, 0, 2.f, 0) |
| 200 | || test_padding(c, 0, 0, 2, 2, 0, 0, 0, -3.f, 0) |
| 201 | |
| 202 | || test_padding(a, 0, 0, 32, 16, 0, 0, 0, -1.f, 0) |
| 203 | || test_padding(b, 0, 0, 32, 16, 0, 0, 0, -2.f, 0) |
| 204 | || test_padding(c, 0, 0, 32, 16, 0, 0, 0, 3.f, 0) |
| 205 | |
| 206 | || test_padding(a, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 207 | || test_padding(b, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 208 | || test_padding(c, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 209 | |
| 210 | || test_padding(a, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 211 | || test_padding(b, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 212 | || test_padding(c, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 213 | |
| 214 | || test_padding(a, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 215 | || test_padding(b, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 216 | || test_padding(c, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 217 | |
| 218 | || test_padding(a, 0, 0, 10, 6, 0, 0, 2, 0.f, 0) |
| 219 | || test_padding(b, 0, 0, 10, 6, 0, 0, 2, 0.f, 0) |
| 220 | || test_padding(c, 0, 0, 10, 6, 0, 0, 2, 0.f, 0); |
| 221 | } |
| 222 | |
| 223 | static int test_padding_int8(const ncnn::Mat& a, int top, int bottom, int left, int right, int front, int behind, int type, float value, int per_channel_pad_data_size) |
| 224 | { |
| 225 | // TODO enable padding int8 with per_channel_pad_data_size |
| 226 | per_channel_pad_data_size = 0; |
| 227 | |
| 228 | ncnn::ParamDict pd; |
| 229 | pd.set(0, top); |
| 230 | pd.set(1, bottom); |
| 231 | pd.set(2, left); |
| 232 | pd.set(3, right); |
| 233 | pd.set(4, type); |
| 234 | pd.set(5, value); |
| 235 | pd.set(6, per_channel_pad_data_size); |
| 236 | pd.set(7, front); |
| 237 | pd.set(8, behind); |
| 238 | |
| 239 | std::vector<ncnn::Mat> weights(per_channel_pad_data_size ? 1 : 0); |
| 240 | if (per_channel_pad_data_size) |
| 241 | weights[0] = RandomMat(per_channel_pad_data_size); |
| 242 | |
| 243 | int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING | TEST_LAYER_DISABLE_GPU_TESTING; |
| 244 | int ret = test_layer("Padding", pd, weights, a, 0.001, 0, flag); |
| 245 | if (ret != 0) |
| 246 | { |
| 247 | fprintf(stderr, "test_padding_int8 failed a.dims=%d a=(%d %d %d %d) top=%d bottom=%d left=%d right=%d front=%d behind=%d type=%d value=%f per_channel_pad_data_size=%d\n", a.dims, a.w, a.h, a.d, a.c, top, bottom, left, right, front, behind, type, value, per_channel_pad_data_size); |
| 248 | } |
| 249 | |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | static int test_padding_4() |
| 254 | { |
| 255 | ncnn::Mat a = RandomS8Mat(9, 10, 11, 96); |
| 256 | ncnn::Mat b = RandomS8Mat(10, 12, 13, 44); |
| 257 | ncnn::Mat c = RandomS8Mat(8, 7, 9, 13); |
| 258 | |
| 259 | return 0 |
| 260 | || test_padding_int8(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 261 | || test_padding_int8(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 262 | || test_padding_int8(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 263 | |
| 264 | || test_padding_int8(a, 2, 2, 2, 2, 1, 1, 0, 1.f, 0) |
| 265 | || test_padding_int8(b, 2, 2, 2, 2, 1, 1, 0, 2.f, 0) |
| 266 | || test_padding_int8(c, 2, 2, 2, 2, 1, 1, 0, -3.f, 0) |
| 267 | |
| 268 | || test_padding_int8(a, 2, 1, 2, 1, 2, 1, 0, 0.f, a.c) |
| 269 | || test_padding_int8(b, 2, 1, 2, 1, 2, 1, 0, 0.f, b.c) |
| 270 | || test_padding_int8(c, 2, 1, 2, 1, 2, 1, 0, 0.f, c.c) |
| 271 | |
| 272 | || test_padding_int8(a, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 273 | || test_padding_int8(b, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 274 | || test_padding_int8(c, 0, 1, 0, 1, 0, 1, 0, 0.f, 0) |
| 275 | |
| 276 | || test_padding_int8(a, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 277 | || test_padding_int8(b, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 278 | || test_padding_int8(c, 1, 2, 3, 4, 5, 6, 0, 0.f, 0) |
| 279 | |
| 280 | || test_padding_int8(a, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 281 | || test_padding_int8(b, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 282 | || test_padding_int8(c, 2, 3, 2, 3, 2, 3, 0, 0.f, 0) |
| 283 | |
| 284 | || test_padding_int8(a, 1, 1, 1, 1, 1, 1, 0, -1.f, 0) |
| 285 | || test_padding_int8(b, 1, 1, 1, 1, 1, 1, 0, -2.f, 0) |
| 286 | || test_padding_int8(c, 1, 1, 1, 1, 1, 1, 0, 3.f, 0); |
| 287 | } |
| 288 | |
| 289 | static int test_padding_5() |
| 290 | { |
| 291 | ncnn::Mat a = RandomS8Mat(9, 11, 96); |
| 292 | ncnn::Mat b = RandomS8Mat(10, 13, 44); |
| 293 | ncnn::Mat c = RandomS8Mat(8, 9, 13); |
| 294 | |
| 295 | return 0 |
| 296 | || test_padding_int8(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 297 | || test_padding_int8(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 298 | || test_padding_int8(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 299 | |
| 300 | || test_padding_int8(a, 2, 2, 2, 2, 0, 0, 0, 1.f, 0) |
| 301 | || test_padding_int8(b, 2, 2, 2, 2, 0, 0, 0, 2.f, 0) |
| 302 | || test_padding_int8(c, 2, 2, 2, 2, 0, 0, 0, -3.f, 0) |
| 303 | |
| 304 | || test_padding_int8(a, 2, 1, 2, 1, 0, 0, 0, 0.f, a.c) |
| 305 | || test_padding_int8(b, 2, 1, 2, 1, 0, 0, 0, 0.f, b.c) |
| 306 | || test_padding_int8(c, 2, 1, 2, 1, 0, 0, 0, 0.f, c.c) |
| 307 | |
| 308 | || test_padding_int8(a, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 309 | || test_padding_int8(b, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 310 | || test_padding_int8(c, 0, 1, 0, 1, 0, 0, 1, 0.f, 0) |
| 311 | |
| 312 | || test_padding_int8(a, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 313 | || test_padding_int8(b, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 314 | || test_padding_int8(c, 1, 2, 3, 4, 0, 0, 1, 0.f, 0) |
| 315 | |
| 316 | || test_padding_int8(a, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 317 | || test_padding_int8(b, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 318 | || test_padding_int8(c, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 319 | |
| 320 | || test_padding_int8(a, 1, 1, 1, 1, 1, 1, 0, -1.f, 0) |
| 321 | || test_padding_int8(b, 1, 1, 1, 1, 1, 1, 0, -2.f, 0) |
| 322 | || test_padding_int8(c, 1, 1, 1, 1, 1, 1, 0, 3.f, 0) |
| 323 | |
| 324 | || test_padding_int8(a, 2, 1, 0, 0, 2, 3, 0, 0.f, a.c + 5) |
| 325 | || test_padding_int8(b, 2, 1, 0, 0, 2, 3, 0, 0.f, b.c + 5) |
| 326 | || test_padding_int8(c, 2, 1, 0, 0, 2, 3, 0, 0.f, c.c + 5) |
| 327 | |
| 328 | || test_padding_int8(a, 1, 2, 3, 4, 8, 4, 0, 0.f, a.c + 12) |
| 329 | || test_padding_int8(b, 1, 2, 3, 4, 8, 4, 0, 0.f, b.c + 12) |
| 330 | || test_padding_int8(c, 1, 2, 3, 4, 8, 4, 0, 0.f, c.c + 12) |
| 331 | |
| 332 | || test_padding_int8(a, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 333 | || test_padding_int8(b, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 334 | || test_padding_int8(c, 0, 0, 0, 0, 3, 1, 1, 0.f, 0) |
| 335 | |
| 336 | || test_padding_int8(a, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 337 | || test_padding_int8(b, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 338 | || test_padding_int8(c, 2, 0, 1, 0, 4, 4, 1, 0.f, 0) |
| 339 | |
| 340 | || test_padding_int8(a, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 341 | || test_padding_int8(b, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 342 | || test_padding_int8(c, 2, 0, 2, 0, 0, 2, 2, 0.f, 0) |
| 343 | |
| 344 | || test_padding_int8(a, 4, 2, 1, 3, 3, 5, 2, 0.f, 0) |
| 345 | || test_padding_int8(b, 4, 2, 1, 3, 3, 5, 2, 0.f, 0) |
| 346 | || test_padding_int8(c, 4, 2, 1, 3, 3, 5, 2, 0.f, 0); |
| 347 | } |
| 348 | |
| 349 | static int test_padding_6() |
| 350 | { |
| 351 | ncnn::Mat a = RandomS8Mat(15, 96); |
| 352 | ncnn::Mat b = RandomS8Mat(19, 44); |
| 353 | ncnn::Mat c = RandomS8Mat(17, 15); |
| 354 | |
| 355 | return 0 |
| 356 | || test_padding_int8(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 357 | || test_padding_int8(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 358 | || test_padding_int8(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 359 | |
| 360 | || test_padding_int8(a, 0, 0, 1, 1, 0, 0, 0, 1.f, 0) |
| 361 | || test_padding_int8(b, 0, 0, 1, 1, 0, 0, 0, 2.f, 0) |
| 362 | || test_padding_int8(c, 0, 0, 1, 1, 0, 0, 0, -3.f, 0) |
| 363 | |
| 364 | || test_padding_int8(a, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 365 | || test_padding_int8(b, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 366 | || test_padding_int8(c, 0, 0, 3, 4, 0, 0, 1, 0.f, 0) |
| 367 | |
| 368 | || test_padding_int8(a, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 369 | || test_padding_int8(b, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 370 | || test_padding_int8(c, 0, 0, 3, 2, 0, 0, 2, 0.f, 0) |
| 371 | |
| 372 | || test_padding_int8(a, 2, 2, 2, 2, 0, 0, 0, 1.f, 0) |
| 373 | || test_padding_int8(b, 2, 2, 2, 2, 0, 0, 0, 2.f, 0) |
| 374 | || test_padding_int8(c, 2, 2, 2, 2, 0, 0, 0, -3.f, 0) |
| 375 | |
| 376 | || test_padding_int8(a, 8, 8, 2, 5, 0, 0, 0, -1.f, 0) |
| 377 | || test_padding_int8(b, 8, 8, 2, 5, 0, 0, 0, -2.f, 0) |
| 378 | || test_padding_int8(c, 8, 8, 2, 5, 0, 0, 0, 3.f, 0) |
| 379 | |
| 380 | || test_padding_int8(a, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 381 | || test_padding_int8(b, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 382 | || test_padding_int8(c, 3, 1, 3, 1, 0, 0, 1, 0.f, 0) |
| 383 | |
| 384 | || test_padding_int8(a, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 385 | || test_padding_int8(b, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 386 | || test_padding_int8(c, 4, 4, 0, 1, 0, 0, 1, 0.f, 0) |
| 387 | |
| 388 | || test_padding_int8(a, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 389 | || test_padding_int8(b, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 390 | || test_padding_int8(c, 2, 3, 2, 3, 0, 0, 2, 0.f, 0) |
| 391 | |
| 392 | || test_padding_int8(a, 2, 6, 1, 0, 0, 0, 2, 0.f, 0) |
| 393 | || test_padding_int8(b, 2, 6, 1, 0, 0, 0, 2, 0.f, 0) |
| 394 | || test_padding_int8(c, 2, 6, 1, 0, 0, 0, 2, 0.f, 0); |
| 395 | } |
| 396 | |
| 397 | static int test_padding_7() |
| 398 | { |
| 399 | ncnn::Mat a = RandomS8Mat(128); |
| 400 | ncnn::Mat b = RandomS8Mat(124); |
| 401 | ncnn::Mat c = RandomS8Mat(127); |
| 402 | |
| 403 | return 0 |
| 404 | || test_padding_int8(a, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 405 | || test_padding_int8(b, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 406 | || test_padding_int8(c, 0, 0, 0, 0, 0, 0, 0, 0.f, 0) |
| 407 | |
| 408 | || test_padding_int8(a, 0, 0, 2, 2, 0, 0, 0, 1.f, 0) |
| 409 | || test_padding_int8(b, 0, 0, 2, 2, 0, 0, 0, 2.f, 0) |
| 410 | || test_padding_int8(c, 0, 0, 2, 2, 0, 0, 0, -3.f, 0) |
| 411 | |
| 412 | || test_padding_int8(a, 0, 0, 16, 8, 0, 0, 0, -1.f, 0) |
| 413 | || test_padding_int8(b, 0, 0, 16, 8, 0, 0, 0, -2.f, 0) |
| 414 | || test_padding_int8(c, 0, 0, 16, 8, 0, 0, 0, 3.f, 0) |
| 415 | |
| 416 | || test_padding_int8(a, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 417 | || test_padding_int8(b, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 418 | || test_padding_int8(c, 0, 0, 0, 1, 0, 0, 1, 0.f, 0) |
| 419 | |
| 420 | || test_padding_int8(a, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 421 | || test_padding_int8(b, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 422 | || test_padding_int8(c, 0, 0, 4, 12, 0, 0, 1, 0.f, 0) |
| 423 | |
| 424 | || test_padding_int8(a, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 425 | || test_padding_int8(b, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 426 | || test_padding_int8(c, 0, 0, 2, 3, 0, 0, 2, 0.f, 0) |
| 427 | |
| 428 | || test_padding_int8(a, 0, 0, 10, 6, 0, 0, 2, 0.f, 0) |
| 429 | || test_padding_int8(b, 0, 0, 10, 6, 0, 0, 2, 0.f, 0) |
| 430 | || test_padding_int8(c, 0, 0, 10, 6, 0, 0, 2, 0.f, 0); |
| 431 | } |
| 432 | |
| 433 | int main() |
| 434 | { |
| 435 | SRAND(7767517); |
| 436 | |
| 437 | return test_padding_0() |
| 438 | || test_padding_1() |
| 439 | || test_padding_2() |
| 440 | || test_padding_3() |
| 441 | || test_padding_4() |
| 442 | || test_padding_5() |
| 443 | || test_padding_6() |
| 444 | || test_padding_7(); |
| 445 | } |