| 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_interp(const ncnn::Mat& a, int resize_type, float height_scale, float width_scale, int output_height, int output_width) |
| 18 | { |
| 19 | ncnn::ParamDict pd; |
| 20 | pd.set(0, resize_type); |
| 21 | pd.set(1, height_scale); |
| 22 | pd.set(2, width_scale); |
| 23 | pd.set(3, output_height); |
| 24 | pd.set(4, output_width); |
| 25 | |
| 26 | std::vector<ncnn::Mat> weights(0); |
| 27 | |
| 28 | int ret = test_layer("Interp", pd, weights, a); |
| 29 | if (ret != 0) |
| 30 | { |
| 31 | fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d height_scale=%f width_scale=%f output_height=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, height_scale, width_scale, output_height, output_width); |
| 32 | } |
| 33 | |
| 34 | return ret; |
| 35 | } |
| 36 | |
| 37 | static int test_interp_ref(const ncnn::Mat& a, int resize_type, int output_height, int output_width) |
| 38 | { |
| 39 | ncnn::ParamDict pd; |
| 40 | pd.set(0, resize_type); |
| 41 | pd.set(5, 1); |
| 42 | |
| 43 | std::vector<ncnn::Mat> as(2); |
| 44 | as[0] = a; |
| 45 | as[1] = ncnn::Mat(output_width, output_height, 1); |
| 46 | |
| 47 | std::vector<ncnn::Mat> weights(0); |
| 48 | |
| 49 | int ret = test_layer("Interp", pd, weights, as); |
| 50 | if (ret != 0) |
| 51 | { |
| 52 | fprintf(stderr, "test_interp_ref failed a.dims=%d a=(%d %d %d) resize_type=%d output_height=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, output_height, output_width); |
| 53 | } |
| 54 | |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | static int test_interp_align_corner(const ncnn::Mat& a, int resize_type, float height_scale, float width_scale, int output_height, int output_width, int align_corner) |
| 59 | { |
| 60 | ncnn::ParamDict pd; |
| 61 | pd.set(0, resize_type); |
| 62 | pd.set(1, height_scale); |
| 63 | pd.set(2, width_scale); |
| 64 | pd.set(3, output_height); |
| 65 | pd.set(4, output_width); |
| 66 | pd.set(6, align_corner); |
| 67 | |
| 68 | std::vector<ncnn::Mat> weights(0); |
| 69 | |
| 70 | int ret = test_layer("Interp", pd, weights, a); |
| 71 | if (ret != 0) |
| 72 | { |
| 73 | fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d height_scale=%f width_scale=%f output_height=%d output_width=%d align_corner=%d\n", a.dims, a.w, a.h, a.c, resize_type, height_scale, width_scale, output_height, output_width, align_corner); |
| 74 | } |
| 75 | |
| 76 | return ret; |
| 77 | } |
| 78 | |
| 79 | static int test_interp(const ncnn::Mat& a, int resize_type, float width_scale, int output_width) |
| 80 | { |
| 81 | ncnn::ParamDict pd; |
| 82 | pd.set(0, resize_type); |
| 83 | pd.set(1, 1.f); |
| 84 | pd.set(2, width_scale); |
| 85 | pd.set(3, 0); |
| 86 | pd.set(4, output_width); |
| 87 | |
| 88 | std::vector<ncnn::Mat> weights(0); |
| 89 | |
| 90 | int ret = test_layer("Interp", pd, weights, a); |
| 91 | if (ret != 0) |
| 92 | { |
| 93 | fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d width_scale=%f output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, width_scale, output_width); |
| 94 | } |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | static int test_interp_ref(const ncnn::Mat& a, int resize_type, int output_width) |
| 100 | { |
| 101 | ncnn::ParamDict pd; |
| 102 | pd.set(0, resize_type); |
| 103 | pd.set(5, 1); |
| 104 | |
| 105 | std::vector<ncnn::Mat> as(2); |
| 106 | as[0] = a; |
| 107 | as[1] = ncnn::Mat(output_width, 1); |
| 108 | |
| 109 | std::vector<ncnn::Mat> weights(0); |
| 110 | |
| 111 | int ret = test_layer("Interp", pd, weights, as); |
| 112 | if (ret != 0) |
| 113 | { |
| 114 | fprintf(stderr, "test_interp_ref failed a.dims=%d a=(%d %d %d) resize_type=%d output_width=%d\n", a.dims, a.w, a.h, a.c, resize_type, output_width); |
| 115 | } |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
| 120 | static int test_interp_align_corner(const ncnn::Mat& a, int resize_type, float width_scale, int output_width, int align_corner) |
| 121 | { |
| 122 | ncnn::ParamDict pd; |
| 123 | pd.set(0, resize_type); |
| 124 | pd.set(1, 1.f); |
| 125 | pd.set(2, width_scale); |
| 126 | pd.set(3, 0); |
| 127 | pd.set(4, output_width); |
| 128 | pd.set(6, align_corner); |
| 129 | |
| 130 | std::vector<ncnn::Mat> weights(0); |
| 131 | |
| 132 | int ret = test_layer("Interp", pd, weights, a); |
| 133 | if (ret != 0) |
| 134 | { |
| 135 | fprintf(stderr, "test_interp failed a.dims=%d a=(%d %d %d) resize_type=%d width_scale=%f output_width=%d align_corner=%d\n", a.dims, a.w, a.h, a.c, resize_type, width_scale, output_width, align_corner); |
| 136 | } |
| 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | static int test_interp_0() |
| 142 | { |
| 143 | ncnn::Mat a = RandomMat(15, 16, 7); |
| 144 | ncnn::Mat b = RandomMat(14, 17, 12); |
| 145 | ncnn::Mat c = RandomMat(13, 14, 32); |
| 146 | |
| 147 | return 0 |
| 148 | || test_interp(a, 1, 2.f, 2.f, 0, 0) |
| 149 | || test_interp(a, 1, 4.f, 0.5f, 0, 0) |
| 150 | || test_interp(a, 1, 1.2f, 1.2f, 0, 0) |
| 151 | || test_interp(a, 1, 0.8f, 0.8f, 0, 0) |
| 152 | || test_interp(a, 1, 1.f, 1.f, 10, 12) |
| 153 | || test_interp(a, 1, 1.f, 1.f, 2, 2) |
| 154 | || test_interp(a, 1, 1.f, 1.f, 15, 16) |
| 155 | || test_interp_ref(a, 1, 10, 12) |
| 156 | || test_interp_ref(a, 1, 2, 2) |
| 157 | || test_interp_ref(a, 1, 15, 16) |
| 158 | |
| 159 | || test_interp(b, 1, 2.f, 2.f, 0, 0) |
| 160 | || test_interp(b, 1, 4.f, 0.5f, 0, 0) |
| 161 | || test_interp(b, 1, 1.2f, 1.2f, 0, 0) |
| 162 | || test_interp(b, 1, 0.8f, 0.8f, 0, 0) |
| 163 | || test_interp(b, 1, 1.f, 1.f, 10, 12) |
| 164 | || test_interp(b, 1, 1.f, 1.f, 2, 2) |
| 165 | || test_interp(b, 1, 1.f, 1.f, 14, 17) |
| 166 | || test_interp_ref(b, 1, 10, 12) |
| 167 | || test_interp_ref(b, 1, 2, 2) |
| 168 | || test_interp_ref(b, 1, 14, 17) |
| 169 | |
| 170 | || test_interp(c, 1, 2.f, 2.f, 0, 0) |
| 171 | || test_interp(c, 1, 4.f, 0.5f, 0, 0) |
| 172 | || test_interp(c, 1, 1.2f, 1.2f, 0, 0) |
| 173 | || test_interp(c, 1, 0.8f, 0.8f, 0, 0) |
| 174 | || test_interp(c, 1, 1.f, 1.f, 10, 12) |
| 175 | || test_interp(c, 1, 1.f, 1.f, 2, 2) |
| 176 | || test_interp(c, 1, 1.f, 1.f, 14, 17) |
| 177 | || test_interp_ref(c, 1, 10, 12) |
| 178 | || test_interp_ref(c, 1, 2, 2) |
| 179 | || test_interp_ref(c, 1, 14, 17); |
| 180 | } |
| 181 | |
| 182 | static int test_interp_1() |
| 183 | { |
| 184 | ncnn::Mat a = RandomMat(15, 16, 7); |
| 185 | ncnn::Mat b = RandomMat(14, 17, 12); |
| 186 | ncnn::Mat c = RandomMat(13, 14, 32); |
| 187 | |
| 188 | return 0 |
| 189 | || test_interp(a, 2, 2.f, 2.f, 0, 0) |
| 190 | || test_interp(a, 2, 4.f, 0.5f, 0, 0) |
| 191 | || test_interp(a, 2, 1.2f, 1.2f, 0, 0) |
| 192 | || test_interp(a, 2, 0.8f, 0.8f, 0, 0) |
| 193 | || test_interp(a, 2, 1.f, 1.f, 10, 12) |
| 194 | || test_interp(a, 2, 1.f, 1.f, 2, 2) |
| 195 | || test_interp(a, 2, 1.f, 1.f, 15, 16) |
| 196 | || test_interp_align_corner(a, 2, 2.f, 2.f, 0, 0, 1) |
| 197 | || test_interp_align_corner(a, 2, 4.f, 0.5f, 0, 0, 1) |
| 198 | || test_interp_align_corner(a, 2, 1.2f, 1.2f, 0, 0, 1) |
| 199 | || test_interp_align_corner(a, 2, 0.8f, 0.8f, 0, 0, 1) |
| 200 | || test_interp_align_corner(a, 2, 1.f, 1.f, 10, 12, 1) |
| 201 | || test_interp_align_corner(a, 2, 1.f, 1.f, 2, 2, 1) |
| 202 | || test_interp_align_corner(a, 2, 1.f, 1.f, 15, 16, 1) |
| 203 | || test_interp_ref(a, 2, 10, 12) |
| 204 | || test_interp_ref(a, 2, 2, 2) |
| 205 | || test_interp_ref(a, 2, 15, 16) |
| 206 | |
| 207 | || test_interp(b, 2, 2.f, 2.f, 0, 0) |
| 208 | || test_interp(b, 2, 4.f, 0.5f, 0, 0) |
| 209 | || test_interp(b, 2, 1.2f, 1.2f, 0, 0) |
| 210 | || test_interp(b, 2, 0.8f, 0.8f, 0, 0) |
| 211 | || test_interp(b, 2, 1.f, 1.f, 10, 12) |
| 212 | || test_interp(b, 2, 1.f, 1.f, 2, 2) |
| 213 | || test_interp(b, 2, 1.f, 1.f, 14, 17) |
| 214 | || test_interp_align_corner(b, 2, 2.f, 2.f, 0, 0, 1) |
| 215 | || test_interp_align_corner(b, 2, 4.f, 0.5f, 0, 0, 1) |
| 216 | || test_interp_align_corner(b, 2, 1.2f, 1.2f, 0, 0, 1) |
| 217 | || test_interp_align_corner(b, 2, 0.8f, 0.8f, 0, 0, 1) |
| 218 | || test_interp_align_corner(b, 2, 1.f, 1.f, 10, 12, 1) |
| 219 | || test_interp_align_corner(b, 2, 1.f, 1.f, 2, 2, 1) |
| 220 | || test_interp_align_corner(b, 2, 1.f, 1.f, 14, 17, 1) |
| 221 | || test_interp_ref(b, 2, 10, 12) |
| 222 | || test_interp_ref(b, 2, 2, 2) |
| 223 | || test_interp_ref(b, 2, 14, 17) |
| 224 | |
| 225 | || test_interp(c, 2, 2.f, 2.f, 0, 0) |
| 226 | || test_interp(c, 2, 4.f, 0.5f, 0, 0) |
| 227 | || test_interp(c, 2, 1.2f, 1.2f, 0, 0) |
| 228 | || test_interp(c, 2, 0.8f, 0.8f, 0, 0) |
| 229 | || test_interp(c, 2, 1.f, 1.f, 10, 12) |
| 230 | || test_interp(c, 2, 1.f, 1.f, 2, 2) |
| 231 | || test_interp(c, 2, 1.f, 1.f, 14, 17) |
| 232 | || test_interp_align_corner(c, 2, 2.f, 2.f, 0, 0, 1) |
| 233 | || test_interp_align_corner(c, 2, 4.f, 0.5f, 0, 0, 1) |
| 234 | || test_interp_align_corner(c, 2, 1.2f, 1.2f, 0, 0, 1) |
| 235 | || test_interp_align_corner(c, 2, 0.8f, 0.8f, 0, 0, 1) |
| 236 | || test_interp_align_corner(c, 2, 1.f, 1.f, 10, 12, 1) |
| 237 | || test_interp_align_corner(c, 2, 1.f, 1.f, 2, 2, 1) |
| 238 | || test_interp_align_corner(c, 2, 1.f, 1.f, 14, 17, 1) |
| 239 | || test_interp_ref(c, 2, 10, 12) |
| 240 | || test_interp_ref(c, 2, 2, 2) |
| 241 | || test_interp_ref(c, 2, 14, 17); |
| 242 | } |
| 243 | |
| 244 | static int test_interp_2() |
| 245 | { |
| 246 | ncnn::Mat a = RandomMat(16, 17, 13); |
| 247 | ncnn::Mat b = RandomMat(18, 19, 12); |
| 248 | ncnn::Mat c = RandomMat(13, 14, 32); |
| 249 | |
| 250 | return 0 |
| 251 | || test_interp(a, 3, 2.f, 2.f, 0, 0) |
| 252 | || test_interp(a, 3, 4.f, 0.5f, 0, 0) |
| 253 | || test_interp(a, 3, 1.2f, 1.2f, 0, 0) |
| 254 | || test_interp(a, 3, 0.8f, 0.8f, 0, 0) |
| 255 | || test_interp(a, 3, 1.f, 1.f, 10, 12) |
| 256 | || test_interp(a, 3, 1.f, 1.f, 2, 2) |
| 257 | || test_interp(a, 3, 1.f, 1.f, 6, 7) |
| 258 | || test_interp(a, 3, 1.f, 1.f, 16, 17) |
| 259 | || test_interp_align_corner(a, 3, 2.f, 2.f, 0, 0, 1) |
| 260 | || test_interp_align_corner(a, 3, 4.f, 0.5f, 0, 0, 1) |
| 261 | || test_interp_align_corner(a, 3, 1.2f, 1.2f, 0, 0, 1) |
| 262 | || test_interp_align_corner(a, 3, 0.8f, 0.8f, 0, 0, 1) |
| 263 | || test_interp_align_corner(a, 3, 1.f, 1.f, 10, 12, 1) |
| 264 | || test_interp_align_corner(a, 3, 1.f, 1.f, 2, 2, 1) |
| 265 | || test_interp_align_corner(a, 3, 1.f, 1.f, 6, 7, 1) |
| 266 | || test_interp_align_corner(a, 3, 1.f, 1.f, 16, 17, 1) |
| 267 | || test_interp_ref(a, 3, 2, 2) |
| 268 | || test_interp_ref(a, 3, 6, 7) |
| 269 | || test_interp_ref(a, 3, 16, 17) |
| 270 | |
| 271 | || test_interp(b, 3, 2.f, 2.f, 0, 0) |
| 272 | || test_interp(b, 3, 4.f, 0.5f, 0, 0) |
| 273 | || test_interp(b, 3, 1.2f, 1.2f, 0, 0) |
| 274 | || test_interp(b, 3, 0.8f, 0.8f, 0, 0) |
| 275 | || test_interp(b, 3, 1.f, 1.f, 10, 12) |
| 276 | || test_interp(b, 3, 1.f, 1.f, 2, 2) |
| 277 | || test_interp(b, 3, 1.f, 1.f, 6, 7) |
| 278 | || test_interp(b, 3, 1.f, 1.f, 18, 19) |
| 279 | || test_interp_align_corner(b, 3, 2.f, 2.f, 0, 0, 1) |
| 280 | || test_interp_align_corner(b, 3, 4.f, 0.5f, 0, 0, 1) |
| 281 | || test_interp_align_corner(b, 3, 1.2f, 1.2f, 0, 0, 1) |
| 282 | || test_interp_align_corner(b, 3, 0.8f, 0.8f, 0, 0, 1) |
| 283 | || test_interp_align_corner(b, 3, 1.f, 1.f, 10, 12, 1) |
| 284 | || test_interp_align_corner(b, 3, 1.f, 1.f, 2, 2, 1) |
| 285 | || test_interp_align_corner(b, 3, 1.f, 1.f, 6, 7, 1) |
| 286 | || test_interp_align_corner(b, 3, 1.f, 1.f, 18, 19, 1) |
| 287 | || test_interp_ref(b, 3, 2, 2) |
| 288 | || test_interp_ref(b, 3, 6, 7) |
| 289 | || test_interp_ref(b, 3, 18, 19) |
| 290 | |
| 291 | || test_interp(c, 3, 2.f, 2.f, 0, 0) |
| 292 | || test_interp(c, 3, 4.f, 0.5f, 0, 0) |
| 293 | || test_interp(c, 3, 1.2f, 1.2f, 0, 0) |
| 294 | || test_interp(c, 3, 0.8f, 0.8f, 0, 0) |
| 295 | || test_interp(c, 3, 1.f, 1.f, 10, 12) |
| 296 | || test_interp(c, 3, 1.f, 1.f, 2, 2) |
| 297 | || test_interp(c, 3, 1.f, 1.f, 6, 7) |
| 298 | || test_interp(c, 3, 1.f, 1.f, 18, 19) |
| 299 | || test_interp_align_corner(c, 3, 2.f, 2.f, 0, 0, 1) |
| 300 | || test_interp_align_corner(c, 3, 4.f, 0.5f, 0, 0, 1) |
| 301 | || test_interp_align_corner(c, 3, 1.2f, 1.2f, 0, 0, 1) |
| 302 | || test_interp_align_corner(c, 3, 0.8f, 0.8f, 0, 0, 1) |
| 303 | || test_interp_align_corner(c, 3, 1.f, 1.f, 10, 12, 1) |
| 304 | || test_interp_align_corner(c, 3, 1.f, 1.f, 2, 2, 1) |
| 305 | || test_interp_align_corner(c, 3, 1.f, 1.f, 6, 7, 1) |
| 306 | || test_interp_align_corner(c, 3, 1.f, 1.f, 18, 19, 1) |
| 307 | || test_interp_ref(c, 3, 2, 2) |
| 308 | || test_interp_ref(c, 3, 6, 7) |
| 309 | || test_interp_ref(c, 3, 18, 19); |
| 310 | } |
| 311 | |
| 312 | static int test_interp_3() |
| 313 | { |
| 314 | ncnn::Mat a = RandomMat(15, 7); |
| 315 | ncnn::Mat b = RandomMat(14, 12); |
| 316 | ncnn::Mat c = RandomMat(13, 32); |
| 317 | |
| 318 | return 0 |
| 319 | || test_interp(a, 1, 2.f, 0) |
| 320 | || test_interp(a, 1, 0.5f, 0) |
| 321 | || test_interp(a, 1, 1.2f, 0) |
| 322 | || test_interp(a, 1, 0.8f, 0) |
| 323 | || test_interp(a, 1, 1.f, 12) |
| 324 | || test_interp(a, 1, 1.f, 2) |
| 325 | || test_interp(a, 1, 1.f, 16) |
| 326 | || test_interp_ref(a, 1, 12) |
| 327 | || test_interp_ref(a, 1, 2) |
| 328 | || test_interp_ref(a, 1, 16) |
| 329 | |
| 330 | || test_interp(b, 1, 2.f, 0) |
| 331 | || test_interp(b, 1, 0.5f, 0) |
| 332 | || test_interp(b, 1, 1.2f, 0) |
| 333 | || test_interp(b, 1, 0.8f, 0) |
| 334 | || test_interp(b, 1, 1.f, 12) |
| 335 | || test_interp(b, 1, 1.f, 2) |
| 336 | || test_interp(b, 1, 1.f, 17) |
| 337 | || test_interp_ref(b, 1, 12) |
| 338 | || test_interp_ref(b, 1, 2) |
| 339 | || test_interp_ref(b, 1, 17) |
| 340 | |
| 341 | || test_interp(c, 1, 2.f, 0) |
| 342 | || test_interp(c, 1, 0.5f, 0) |
| 343 | || test_interp(c, 1, 1.2f, 0) |
| 344 | || test_interp(c, 1, 0.8f, 0) |
| 345 | || test_interp(c, 1, 1.f, 12) |
| 346 | || test_interp(c, 1, 1.f, 2) |
| 347 | || test_interp(c, 1, 1.f, 17) |
| 348 | || test_interp_ref(c, 1, 12) |
| 349 | || test_interp_ref(c, 1, 2) |
| 350 | || test_interp_ref(c, 1, 17); |
| 351 | } |
| 352 | |
| 353 | static int test_interp_4() |
| 354 | { |
| 355 | ncnn::Mat a = RandomMat(15, 7); |
| 356 | ncnn::Mat b = RandomMat(14, 12); |
| 357 | ncnn::Mat c = RandomMat(13, 32); |
| 358 | |
| 359 | return 0 |
| 360 | || test_interp(a, 2, 2.f, 0) |
| 361 | || test_interp(a, 2, 0.5f, 0) |
| 362 | || test_interp(a, 2, 1.2f, 0) |
| 363 | || test_interp(a, 2, 0.8f, 0) |
| 364 | || test_interp(a, 2, 1.f, 12) |
| 365 | || test_interp(a, 2, 1.f, 2) |
| 366 | || test_interp(a, 2, 1.f, 16) |
| 367 | || test_interp_align_corner(a, 2, 2.f, 0, 1) |
| 368 | || test_interp_align_corner(a, 2, 0.5f, 0, 1) |
| 369 | || test_interp_align_corner(a, 2, 1.2f, 0, 1) |
| 370 | || test_interp_align_corner(a, 2, 0.8f, 0, 1) |
| 371 | || test_interp_align_corner(a, 2, 1.f, 12, 1) |
| 372 | || test_interp_align_corner(a, 2, 1.f, 2, 1) |
| 373 | || test_interp_align_corner(a, 2, 1.f, 16, 1) |
| 374 | || test_interp_ref(a, 2, 12) |
| 375 | || test_interp_ref(a, 2, 2) |
| 376 | || test_interp_ref(a, 2, 16) |
| 377 | |
| 378 | || test_interp(b, 2, 2.f, 0) |
| 379 | || test_interp(b, 2, 0.5f, 0) |
| 380 | || test_interp(b, 2, 1.2f, 0) |
| 381 | || test_interp(b, 2, 0.8f, 0) |
| 382 | || test_interp(b, 2, 1.f, 12) |
| 383 | || test_interp(b, 2, 1.f, 2) |
| 384 | || test_interp(b, 2, 1.f, 17) |
| 385 | || test_interp_align_corner(b, 2, 2.f, 0, 1) |
| 386 | || test_interp_align_corner(b, 2, 0.5f, 0, 1) |
| 387 | || test_interp_align_corner(b, 2, 1.2f, 0, 1) |
| 388 | || test_interp_align_corner(b, 2, 0.8f, 0, 1) |
| 389 | || test_interp_align_corner(b, 2, 1.f, 12, 1) |
| 390 | || test_interp_align_corner(b, 2, 1.f, 2, 1) |
| 391 | || test_interp_align_corner(b, 2, 1.f, 17, 1) |
| 392 | || test_interp_ref(b, 2, 12) |
| 393 | || test_interp_ref(b, 2, 2) |
| 394 | || test_interp_ref(b, 2, 17) |
| 395 | |
| 396 | || test_interp(c, 2, 2.f, 0) |
| 397 | || test_interp(c, 2, 0.5f, 0) |
| 398 | || test_interp(c, 2, 1.2f, 0) |
| 399 | || test_interp(c, 2, 0.8f, 0) |
| 400 | || test_interp(c, 2, 1.f, 12) |
| 401 | || test_interp(c, 2, 1.f, 2) |
| 402 | || test_interp(c, 2, 1.f, 17) |
| 403 | || test_interp_align_corner(c, 2, 2.f, 0, 1) |
| 404 | || test_interp_align_corner(c, 2, 0.5f, 0, 1) |
| 405 | || test_interp_align_corner(c, 2, 1.2f, 0, 1) |
| 406 | || test_interp_align_corner(c, 2, 0.8f, 0, 1) |
| 407 | || test_interp_align_corner(c, 2, 1.f, 12, 1) |
| 408 | || test_interp_align_corner(c, 2, 1.f, 2, 1) |
| 409 | || test_interp_align_corner(c, 2, 1.f, 17, 1) |
| 410 | || test_interp_ref(c, 2, 12) |
| 411 | || test_interp_ref(c, 2, 2) |
| 412 | || test_interp_ref(c, 2, 17); |
| 413 | } |
| 414 | |
| 415 | static int test_interp_5() |
| 416 | { |
| 417 | ncnn::Mat a = RandomMat(16, 13); |
| 418 | ncnn::Mat b = RandomMat(18, 12); |
| 419 | ncnn::Mat c = RandomMat(13, 32); |
| 420 | |
| 421 | return 0 |
| 422 | || test_interp(a, 3, 2.f, 0) |
| 423 | || test_interp(a, 3, 0.5f, 0) |
| 424 | || test_interp(a, 3, 1.2f, 0) |
| 425 | || test_interp(a, 3, 0.8f, 0) |
| 426 | || test_interp(a, 3, 1.f, 12) |
| 427 | || test_interp(a, 3, 1.f, 2) |
| 428 | || test_interp(a, 3, 1.f, 7) |
| 429 | || test_interp(a, 3, 1.f, 17) |
| 430 | || test_interp_align_corner(a, 3, 2.f, 0, 1) |
| 431 | || test_interp_align_corner(a, 3, 0.5f, 0, 1) |
| 432 | || test_interp_align_corner(a, 3, 1.2f, 0, 1) |
| 433 | || test_interp_align_corner(a, 3, 0.8f, 0, 1) |
| 434 | || test_interp_align_corner(a, 3, 1.f, 12, 1) |
| 435 | || test_interp_align_corner(a, 3, 1.f, 2, 1) |
| 436 | || test_interp_align_corner(a, 3, 1.f, 7, 1) |
| 437 | || test_interp_align_corner(a, 3, 1.f, 17, 1) |
| 438 | || test_interp_ref(a, 3, 2) |
| 439 | || test_interp_ref(a, 3, 7) |
| 440 | || test_interp_ref(a, 3, 17) |
| 441 | |
| 442 | || test_interp(b, 3, 2.f, 0) |
| 443 | || test_interp(b, 3, 0.5f, 0) |
| 444 | || test_interp(b, 3, 1.2f, 0) |
| 445 | || test_interp(b, 3, 0.8f, 0) |
| 446 | || test_interp(b, 3, 1.f, 12) |
| 447 | || test_interp(b, 3, 1.f, 2) |
| 448 | || test_interp(b, 3, 1.f, 7) |
| 449 | || test_interp(b, 3, 1.f, 19) |
| 450 | || test_interp_align_corner(b, 3, 2.f, 0, 1) |
| 451 | || test_interp_align_corner(b, 3, 0.5f, 0, 1) |
| 452 | || test_interp_align_corner(b, 3, 1.2f, 0, 1) |
| 453 | || test_interp_align_corner(b, 3, 0.8f, 0, 1) |
| 454 | || test_interp_align_corner(b, 3, 1.f, 12, 1) |
| 455 | || test_interp_align_corner(b, 3, 1.f, 2, 1) |
| 456 | || test_interp_align_corner(b, 3, 1.f, 7, 1) |
| 457 | || test_interp_align_corner(b, 3, 1.f, 19, 1) |
| 458 | || test_interp_ref(b, 3, 2) |
| 459 | || test_interp_ref(b, 3, 7) |
| 460 | || test_interp_ref(b, 3, 19) |
| 461 | |
| 462 | || test_interp(c, 3, 2.f, 0) |
| 463 | || test_interp(c, 3, 0.5f, 0) |
| 464 | || test_interp(c, 3, 1.2f, 0) |
| 465 | || test_interp(c, 3, 0.8f, 0) |
| 466 | || test_interp(c, 3, 1.f, 12) |
| 467 | || test_interp(c, 3, 1.f, 2) |
| 468 | || test_interp(c, 3, 1.f, 7) |
| 469 | || test_interp(c, 3, 1.f, 19) |
| 470 | || test_interp_align_corner(c, 3, 2.f, 0, 1) |
| 471 | || test_interp_align_corner(c, 3, 0.5f, 0, 1) |
| 472 | || test_interp_align_corner(c, 3, 1.2f, 0, 1) |
| 473 | || test_interp_align_corner(c, 3, 0.8f, 0, 1) |
| 474 | || test_interp_align_corner(c, 3, 1.f, 12, 1) |
| 475 | || test_interp_align_corner(c, 3, 1.f, 2, 1) |
| 476 | || test_interp_align_corner(c, 3, 1.f, 7, 1) |
| 477 | || test_interp_align_corner(c, 3, 1.f, 19, 1) |
| 478 | || test_interp_ref(c, 3, 2) |
| 479 | || test_interp_ref(c, 3, 7) |
| 480 | || test_interp_ref(c, 3, 19); |
| 481 | } |
| 482 | |
| 483 | static int test_interp_6() |
| 484 | { |
| 485 | ncnn::Mat a = RandomMat(17); |
| 486 | ncnn::Mat b = RandomMat(20); |
| 487 | ncnn::Mat c = RandomMat(48); |
| 488 | |
| 489 | return 0 |
| 490 | || test_interp(a, 1, 2.f, 3.f, 0, 0) |
| 491 | || test_interp(a, 1, 1.f, 1.f, 10, 12) |
| 492 | || test_interp(a, 1, 1.f, 1.f, 15, 16) |
| 493 | || test_interp_ref(a, 1, 10, 12) |
| 494 | || test_interp_ref(a, 1, 4, 4) |
| 495 | || test_interp_ref(a, 1, 15, 16) |
| 496 | |
| 497 | || test_interp(b, 1, 4.f, 5.f, 0, 0) |
| 498 | || test_interp(b, 1, 1.f, 1.f, 10, 12) |
| 499 | || test_interp(b, 1, 1.f, 1.f, 14, 17) |
| 500 | || test_interp_ref(b, 1, 5, 5) |
| 501 | || test_interp_ref(b, 1, 14, 17) |
| 502 | |
| 503 | || test_interp(c, 1, 6.f, 7.f, 0, 0) |
| 504 | || test_interp(c, 1, 1.f, 1.f, 10, 12) |
| 505 | || test_interp(c, 1, 1.f, 1.f, 14, 17) |
| 506 | || test_interp_ref(c, 1, 6, 6) |
| 507 | || test_interp_ref(c, 1, 14, 17); |
| 508 | } |
| 509 | |
| 510 | int main() |
| 511 | { |
| 512 | SRAND(7767517); |
| 513 | |
| 514 | return 0 |
| 515 | || test_interp_0() |
| 516 | || test_interp_1() |
| 517 | || test_interp_2() |
| 518 | || test_interp_3() |
| 519 | || test_interp_4() |
| 520 | || test_interp_5() |
| 521 | || test_interp_6(); |
| 522 | } |