You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_crop.cpp 38 kB

6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
6 years ago
4 years ago
6 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
4 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. #include "layer/crop.h"
  15. #include "testutil.h"
  16. static int test_crop(const ncnn::Mat& a, int woffset, int hoffset, int doffset, int coffset, int outw, int outh, int outd, int outc, int woffset2, int hoffset2, int doffset2, int coffset2)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, woffset); // woffset
  20. pd.set(1, hoffset); // hoffset
  21. pd.set(13, doffset); // doffset
  22. pd.set(2, coffset); // coffset
  23. pd.set(3, outw); // outw
  24. pd.set(4, outh); // outh
  25. pd.set(14, outd); // outd
  26. pd.set(5, outc); // outc
  27. pd.set(6, woffset2); // woffset2
  28. pd.set(7, hoffset2); // hoffset2
  29. pd.set(15, doffset2); // doffset2
  30. pd.set(8, coffset2); // coffset2
  31. std::vector<ncnn::Mat> weights(0);
  32. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, a);
  33. if (ret != 0)
  34. {
  35. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d) woffset=%d hoffset=%d doffset=%d coffset=%d outw=%d outh=%d outd=%d outc=%d woffset2=%d hoffset2=%d doffset2=%d coffset2=%d\n", a.dims, a.w, a.h, a.d, a.c, woffset, hoffset, doffset, coffset, outw, outh, outd, outc, woffset2, hoffset2, doffset2, coffset2);
  36. }
  37. return ret;
  38. }
  39. static ncnn::Mat IntArrayMat(int a0)
  40. {
  41. ncnn::Mat m(1);
  42. int* p = m;
  43. p[0] = a0;
  44. return m;
  45. }
  46. static ncnn::Mat IntArrayMat(int a0, int a1)
  47. {
  48. ncnn::Mat m(2);
  49. int* p = m;
  50. p[0] = a0;
  51. p[1] = a1;
  52. return m;
  53. }
  54. static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
  55. {
  56. ncnn::Mat m(3);
  57. int* p = m;
  58. p[0] = a0;
  59. p[1] = a1;
  60. p[2] = a2;
  61. return m;
  62. }
  63. static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3)
  64. {
  65. ncnn::Mat m(4);
  66. int* p = m;
  67. p[0] = a0;
  68. p[1] = a1;
  69. p[2] = a2;
  70. p[3] = a3;
  71. return m;
  72. }
  73. static void print_int_array(const ncnn::Mat& a)
  74. {
  75. const int* pa = a;
  76. fprintf(stderr, "[");
  77. for (int i = 0; i < a.w; i++)
  78. {
  79. fprintf(stderr, " %d", pa[i]);
  80. }
  81. fprintf(stderr, " ]");
  82. }
  83. static int test_crop(const ncnn::Mat& a, const ncnn::Mat& starts, const ncnn::Mat& ends, const ncnn::Mat& axes)
  84. {
  85. ncnn::ParamDict pd;
  86. pd.set(9, starts); // starts
  87. pd.set(10, ends); // ends
  88. pd.set(11, axes); // axes
  89. std::vector<ncnn::Mat> weights(0);
  90. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, a);
  91. if (ret != 0)
  92. {
  93. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d)", a.dims, a.w, a.h, a.d, a.c);
  94. fprintf(stderr, " starts=");
  95. print_int_array(starts);
  96. fprintf(stderr, " ends=");
  97. print_int_array(ends);
  98. fprintf(stderr, " axes=");
  99. print_int_array(axes);
  100. fprintf(stderr, "\n");
  101. }
  102. return ret;
  103. }
  104. static int test_crop(const ncnn::Mat& a, int woffset, int hoffset, int doffset, int coffset, const ncnn::Mat& ref)
  105. {
  106. ncnn::ParamDict pd;
  107. pd.set(0, woffset);
  108. pd.set(1, hoffset);
  109. pd.set(13, doffset);
  110. pd.set(2, coffset);
  111. pd.set(3, 0); // outw
  112. pd.set(4, 0); // outh
  113. pd.set(14, 0); // outd
  114. pd.set(5, 0); // outc
  115. pd.set(6, 0); // woffset2
  116. pd.set(7, 0); // hoffset2
  117. pd.set(15, 0); // doffset2
  118. pd.set(8, 0); // coffset2
  119. std::vector<ncnn::Mat> weights(0);
  120. std::vector<ncnn::Mat> ab(2);
  121. ab[0] = a;
  122. ab[1] = ref;
  123. int ret = test_layer<ncnn::Crop>("Crop", pd, weights, ab);
  124. if (ret != 0)
  125. {
  126. fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d) woffset=%d hoffset=%d coffset=%d ref.dims=%d ref=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c, woffset, hoffset, doffset, coffset, ref.dims, ref.w, ref.h, ref.d, ref.c);
  127. }
  128. return ret;
  129. }
  130. static int test_crop_0(const ncnn::Mat& a)
  131. {
  132. return 0
  133. || test_crop(a, 0, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
  134. || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
  135. || test_crop(a, 11, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0)
  136. || test_crop(a, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0)
  137. || test_crop(a, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0)
  138. || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 12, 0, 0, 0)
  139. || test_crop(a, 12, 0, 0, 0, -233, 0, 0, 0, 16, 0, 0, 0)
  140. || test_crop(a, 16, 0, 0, 0, -233, 0, 0, 0, 7, 0, 0, 0);
  141. }
  142. static int test_crop_1(const ncnn::Mat& a)
  143. {
  144. return 0
  145. || test_crop(a, IntArrayMat(12), IntArrayMat(-233), IntArrayMat(0))
  146. || test_crop(a, IntArrayMat(16), IntArrayMat(-233), IntArrayMat(0))
  147. || test_crop(a, IntArrayMat(11), IntArrayMat(11 + 16), IntArrayMat(0))
  148. || test_crop(a, IntArrayMat(12), IntArrayMat(12 + 7), IntArrayMat(-1))
  149. || test_crop(a, IntArrayMat(16), IntArrayMat(16 + 12), ncnn::Mat())
  150. || test_crop(a, IntArrayMat(11), IntArrayMat(-7 + 1), IntArrayMat(0))
  151. || test_crop(a, IntArrayMat(12), IntArrayMat(-12 + 1), IntArrayMat(-1))
  152. || test_crop(a, IntArrayMat(16), IntArrayMat(-16 + 1), ncnn::Mat());
  153. }
  154. static int test_crop_2(const ncnn::Mat& a)
  155. {
  156. return 0
  157. || test_crop(a, 0, 0, 0, 0, a)
  158. || test_crop(a, 0, 0, 0, 0, ncnn::Mat(27))
  159. || test_crop(a, 11, 0, 0, 0, ncnn::Mat(7))
  160. || test_crop(a, 12, 0, 0, 0, ncnn::Mat(12))
  161. || test_crop(a, 16, 0, 0, 0, ncnn::Mat(16));
  162. }
  163. static int test_crop_3(const ncnn::Mat& a)
  164. {
  165. return 0
  166. || test_crop(a, 0, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  167. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  168. || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  169. || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  170. || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  171. || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
  172. || test_crop(a, 5, 0, 0, 0, 5, -233, 0, 0, 0, 0, 0, 0)
  173. || test_crop(a, 6, 0, 0, 0, 6, -233, 0, 0, 0, 0, 0, 0)
  174. || test_crop(a, 4, 0, 0, 0, 4, -233, 0, 0, 0, 0, 0, 0)
  175. || test_crop(a, 0, 11, 0, 0, -233, 12, 0, 0, 0, 0, 0, 0)
  176. || test_crop(a, 0, 12, 0, 0, -233, 16, 0, 0, 0, 0, 0, 0)
  177. || test_crop(a, 0, 8, 0, 0, -233, 7, 0, 0, 0, 0, 0, 0)
  178. || test_crop(a, 5, 11, 0, 0, 4, 16, 0, 0, 0, 0, 0, 0)
  179. || test_crop(a, 6, 12, 0, 0, 5, 7, 0, 0, 0, 0, 0, 0)
  180. || test_crop(a, 4, 8, 0, 0, 6, 12, 0, 0, 0, 0, 0, 0)
  181. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 5, 0, 0, 0)
  182. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, 0, 6, 0, 0, 0)
  183. || test_crop(a, 4, 0, 0, 0, -233, -233, 0, 0, 4, 0, 0, 0)
  184. || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 12, 0, 0)
  185. || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 16, 0, 0)
  186. || test_crop(a, 0, 8, 0, 0, -233, -233, 0, 0, 0, 7, 0, 0)
  187. || test_crop(a, 5, 11, 0, 0, -233, -233, 0, 0, 4, 16, 0, 0)
  188. || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 5, 7, 0, 0)
  189. || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 6, 12, 0, 0);
  190. }
  191. static int test_crop_4(const ncnn::Mat& a)
  192. {
  193. return 0
  194. || test_crop(a, IntArrayMat(12), IntArrayMat(-233), IntArrayMat(0))
  195. || test_crop(a, IntArrayMat(8), IntArrayMat(-233), IntArrayMat(0))
  196. || test_crop(a, IntArrayMat(4), IntArrayMat(-233), IntArrayMat(1))
  197. || test_crop(a, IntArrayMat(5, 11), IntArrayMat(-233, -233), IntArrayMat(0, 1))
  198. || test_crop(a, IntArrayMat(11), IntArrayMat(11 + 16), IntArrayMat(0))
  199. || test_crop(a, IntArrayMat(12), IntArrayMat(12 + 7), IntArrayMat(0))
  200. || test_crop(a, IntArrayMat(8), IntArrayMat(8 + 12), IntArrayMat(-2))
  201. || test_crop(a, IntArrayMat(5), IntArrayMat(8), IntArrayMat(1))
  202. || test_crop(a, IntArrayMat(6), IntArrayMat(9), IntArrayMat(1))
  203. || test_crop(a, IntArrayMat(4), IntArrayMat(12), IntArrayMat(-1))
  204. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(11 + 7, 11), IntArrayMat(0, 1))
  205. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(12 + 12, 12), IntArrayMat(0, 1))
  206. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(8 + 16, 10), IntArrayMat(0, -1))
  207. || test_crop(a, IntArrayMat(11), IntArrayMat(-16 + 1), IntArrayMat(0))
  208. || test_crop(a, IntArrayMat(12), IntArrayMat(-7 + 1), IntArrayMat(0))
  209. || test_crop(a, IntArrayMat(8), IntArrayMat(-12 + 1), IntArrayMat(-2))
  210. || test_crop(a, IntArrayMat(5), IntArrayMat(-5 + 1), IntArrayMat(1))
  211. || test_crop(a, IntArrayMat(6), IntArrayMat(-6 + 1), IntArrayMat(1))
  212. || test_crop(a, IntArrayMat(4), IntArrayMat(-4 + 1), IntArrayMat(-1))
  213. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(-12 + 1, -6 + 1), IntArrayMat(0, 1))
  214. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-16 + 1, -5 + 1), IntArrayMat(0, 1))
  215. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(-7 + 1, -4 + 1), IntArrayMat(-2, -1));
  216. }
  217. static int test_crop_5(const ncnn::Mat& a)
  218. {
  219. return 0
  220. || test_crop(a, 0, 0, 0, 0, a)
  221. || test_crop(a, 0, 12, 0, 0, ncnn::Mat(8, 7))
  222. || test_crop(a, 5, 0, 0, 0, ncnn::Mat(7, 27))
  223. || test_crop(a, 5, 11, 0, 0, ncnn::Mat(5, 12))
  224. || test_crop(a, 6, 12, 0, 0, ncnn::Mat(4, 16))
  225. || test_crop(a, 4, 8, 0, 0, ncnn::Mat(6, 7));
  226. }
  227. static int test_crop_6(const ncnn::Mat& a)
  228. {
  229. return 0
  230. || test_crop(a, 0, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  231. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  232. || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  233. || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  234. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  235. || test_crop(a, 5, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  236. || test_crop(a, 4, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
  237. || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  238. || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 0)
  239. || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 0)
  240. || test_crop(a, 6, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
  241. || test_crop(a, 5, 0, 0, 0, 6, -233, 0, -233, 0, 0, 0, 0)
  242. || test_crop(a, 6, 0, 0, 0, 4, -233, 0, -233, 0, 0, 0, 0)
  243. || test_crop(a, 4, 0, 0, 0, 5, -233, 0, -233, 0, 0, 0, 0)
  244. || test_crop(a, 0, 5, 0, 0, -233, 4, 0, -233, 0, 0, 0, 0)
  245. || test_crop(a, 0, 6, 0, 0, -233, 5, 0, -233, 0, 0, 0, 0)
  246. || test_crop(a, 0, 4, 0, 0, -233, 6, 0, -233, 0, 0, 0, 0)
  247. || test_crop(a, 0, 0, 0, 11, -233, -233, 0, 7, 0, 0, 0, 0)
  248. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, 12, 0, 0, 0, 0)
  249. || test_crop(a, 0, 0, 0, 8, -233, -233, 0, 16, 0, 0, 0, 0)
  250. || test_crop(a, 5, 5, 0, 0, 4, 4, 0, -233, 0, 0, 0, 0)
  251. || test_crop(a, 6, 6, 0, 0, 6, 6, 0, -233, 0, 0, 0, 0)
  252. || test_crop(a, 4, 4, 0, 0, 5, 5, 0, -233, 0, 0, 0, 0)
  253. || test_crop(a, 0, 5, 0, 11, -233, 6, 0, 12, 0, 0, 0, 0)
  254. || test_crop(a, 0, 6, 0, 12, -233, 4, 0, 16, 0, 0, 0, 0)
  255. || test_crop(a, 0, 4, 0, 8, -233, 5, 0, 7, 0, 0, 0, 0)
  256. || test_crop(a, 5, 0, 0, 11, 4, -233, 0, 16, 0, 0, 0, 0)
  257. || test_crop(a, 6, 0, 0, 12, 5, -233, 0, 7, 0, 0, 0, 0)
  258. || test_crop(a, 4, 0, 0, 8, 4, -233, 0, 12, 0, 0, 0, 0)
  259. || test_crop(a, 5, 3, 0, 11, 6, 5, 0, 12, 0, 0, 0, 0)
  260. || test_crop(a, 6, 4, 0, 12, 4, 4, 0, 16, 0, 0, 0, 0)
  261. || test_crop(a, 4, 5, 0, 8, 5, 3, 0, 7, 0, 0, 0, 0)
  262. || test_crop(a, 5, 0, 0, 0, -233, -233, 0, -233, 4, 0, 0, 0)
  263. || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 5, 0, 0, 0)
  264. || test_crop(a, 4, 0, 0, 0, -233, -233, 0, -233, 6, 0, 0, 0)
  265. || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 5, 0, 0)
  266. || test_crop(a, 0, 6, 0, 0, -233, -233, 0, -233, 0, 6, 0, 0)
  267. || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 4, 0, 0)
  268. || test_crop(a, 0, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 12)
  269. || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 16)
  270. || test_crop(a, 0, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 7)
  271. || test_crop(a, 5, 4, 0, 0, -233, -233, 0, -233, 4, 2, 0, 0)
  272. || test_crop(a, 6, 3, 0, 0, -233, -233, 0, -233, 5, 3, 0, 0)
  273. || test_crop(a, 4, 2, 0, 0, -233, -233, 0, -233, 6, 4, 0, 0)
  274. || test_crop(a, 0, 5, 0, 11, -233, -233, 0, -233, 0, 5, 0, 7)
  275. || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 6, 0, 12)
  276. || test_crop(a, 0, 4, 0, 8, -233, -233, 0, -233, 0, 4, 0, 16)
  277. || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 6, 0, 0, 12)
  278. || test_crop(a, 6, 0, 0, 12, -233, -233, 0, -233, 4, 0, 0, 16)
  279. || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 5, 0, 0, 7)
  280. || test_crop(a, 5, 2, 0, 11, -233, -233, 0, -233, 4, 3, 0, 16)
  281. || test_crop(a, 6, 3, 0, 12, -233, -233, 0, -233, 5, 4, 0, 7)
  282. || test_crop(a, 4, 4, 0, 8, -233, -233, 0, -233, 6, 2, 0, 12);
  283. }
  284. static int test_crop_7(const ncnn::Mat& a)
  285. {
  286. return 0
  287. || test_crop(a, IntArrayMat(11), IntArrayMat(-233), IntArrayMat(0))
  288. || test_crop(a, IntArrayMat(8), IntArrayMat(-233), IntArrayMat(0))
  289. || test_crop(a, IntArrayMat(5), IntArrayMat(-233), IntArrayMat(1))
  290. || test_crop(a, IntArrayMat(6), IntArrayMat(-233), IntArrayMat(2))
  291. || test_crop(a, IntArrayMat(4), IntArrayMat(-233), IntArrayMat(-1))
  292. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-233, -233), IntArrayMat(0, 1))
  293. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(-233, -233), IntArrayMat(0, -1))
  294. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(-233, -233), IntArrayMat(0, 2))
  295. || test_crop(a, IntArrayMat(6, 6), IntArrayMat(-233, -233), IntArrayMat(1, -1))
  296. || test_crop(a, IntArrayMat(11, 5, 5), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 2))
  297. || test_crop(a, IntArrayMat(8, 4, 4), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, -1))
  298. || test_crop(a, IntArrayMat(11), IntArrayMat(11 + 7), IntArrayMat(0))
  299. || test_crop(a, IntArrayMat(12), IntArrayMat(12 + 12), IntArrayMat(0))
  300. || test_crop(a, IntArrayMat(8), IntArrayMat(8 + 16), IntArrayMat(0))
  301. || test_crop(a, IntArrayMat(5), IntArrayMat(13), IntArrayMat(1))
  302. || test_crop(a, IntArrayMat(6), IntArrayMat(12), IntArrayMat(1))
  303. || test_crop(a, IntArrayMat(4), IntArrayMat(11), IntArrayMat(-2))
  304. || test_crop(a, IntArrayMat(5), IntArrayMat(12), IntArrayMat(2))
  305. || test_crop(a, IntArrayMat(6), IntArrayMat(11), IntArrayMat(2))
  306. || test_crop(a, IntArrayMat(4), IntArrayMat(13), IntArrayMat(-1))
  307. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(11 + 7, 11), IntArrayMat(0, 1))
  308. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(12 + 16, 12), IntArrayMat(0, 1))
  309. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(8 + 12, 13), IntArrayMat(0, -2))
  310. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(11 + 16, 13), IntArrayMat(0, 2))
  311. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(12 + 12, 11), IntArrayMat(0, 2))
  312. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(8 + 7, 12), IntArrayMat(0, -1))
  313. || test_crop(a, IntArrayMat(5, 4), IntArrayMat(12, 12), IntArrayMat(1, 2))
  314. || test_crop(a, IntArrayMat(6, 3), IntArrayMat(13, 13), IntArrayMat(1, 2))
  315. || test_crop(a, IntArrayMat(4, 2), IntArrayMat(11, 11), IntArrayMat(-2, -1))
  316. || test_crop(a, IntArrayMat(11, 5, 2), IntArrayMat(11 + 7, 11, 11), IntArrayMat(0, 1, 2))
  317. || test_crop(a, IntArrayMat(12, 6, 4), IntArrayMat(12 + 16, 12, 12), IntArrayMat(0, 1, 2))
  318. || test_crop(a, IntArrayMat(8, 4, 3), IntArrayMat(8 + 12, 13, 13), IntArrayMat(-3, -2, -1))
  319. || test_crop(a, IntArrayMat(11), IntArrayMat(-7 + 1), IntArrayMat(0))
  320. || test_crop(a, IntArrayMat(12), IntArrayMat(-12 + 1), IntArrayMat(0))
  321. || test_crop(a, IntArrayMat(8), IntArrayMat(-16 + 1), IntArrayMat(-3))
  322. || test_crop(a, IntArrayMat(5), IntArrayMat(-6 + 1), IntArrayMat(1))
  323. || test_crop(a, IntArrayMat(6), IntArrayMat(-5 + 1), IntArrayMat(1))
  324. || test_crop(a, IntArrayMat(4), IntArrayMat(-4 + 1), IntArrayMat(-2))
  325. || test_crop(a, IntArrayMat(5), IntArrayMat(-5 + 1), IntArrayMat(2))
  326. || test_crop(a, IntArrayMat(6), IntArrayMat(-4 + 1), IntArrayMat(2))
  327. || test_crop(a, IntArrayMat(4), IntArrayMat(-6 + 1), IntArrayMat(-1))
  328. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(-7 + 1, -4 + 1), IntArrayMat(0, 1))
  329. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-12 + 1, -6 + 1), IntArrayMat(0, 1))
  330. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(-16 + 1, -5 + 1), IntArrayMat(-3, -2))
  331. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(-12 + 1, -6 + 1), IntArrayMat(0, 2))
  332. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-16 + 1, -5 + 1), IntArrayMat(0, 2))
  333. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(-7 + 1, -4 + 1), IntArrayMat(-3, -1))
  334. || test_crop(a, IntArrayMat(5, 2), IntArrayMat(-5 + 1, -5 + 1), IntArrayMat(1, 2))
  335. || test_crop(a, IntArrayMat(6, 4), IntArrayMat(-4 + 1, -4 + 1), IntArrayMat(1, 2))
  336. || test_crop(a, IntArrayMat(4, 3), IntArrayMat(-6 + 1, -6 + 1), IntArrayMat(-2, -1))
  337. || test_crop(a, IntArrayMat(11, 5, 4), IntArrayMat(-7 + 1, -5 + 1, -5 + 1), IntArrayMat(0, 1, 2))
  338. || test_crop(a, IntArrayMat(12, 6, 3), IntArrayMat(-12 + 1, -6 + 1, -6 + 1), IntArrayMat(0, 1, 2))
  339. || test_crop(a, IntArrayMat(8, 4, 2), IntArrayMat(-16 + 1, -4 + 1, -4 + 1), IntArrayMat(-3, -2, -1));
  340. }
  341. static int test_crop_8(const ncnn::Mat& a)
  342. {
  343. return 0
  344. || test_crop(a, 0, 0, 0, 0, a)
  345. || test_crop(a, 0, 5, 0, 0, ncnn::Mat(6, 6))
  346. || test_crop(a, 6, 0, 0, 0, ncnn::Mat(8, 8))
  347. || test_crop(a, 5, 2, 0, 0, ncnn::Mat(6, 3))
  348. || test_crop(a, 6, 3, 0, 0, ncnn::Mat(8, 4))
  349. || test_crop(a, 4, 4, 0, 0, ncnn::Mat(7, 5))
  350. || test_crop(a, 5, 3, 0, 11, ncnn::Mat(7, 3, 7))
  351. || test_crop(a, 6, 4, 0, 12, ncnn::Mat(6, 4, 12))
  352. || test_crop(a, 4, 2, 0, 8, ncnn::Mat(5, 5, 16));
  353. }
  354. static int test_crop_9(const ncnn::Mat& a)
  355. {
  356. return 0
  357. || test_crop(a, 0, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  358. || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  359. || test_crop(a, 0, 5, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  360. || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  361. || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  362. || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  363. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  364. || test_crop(a, 5, 5, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  365. || test_crop(a, 4, 4, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
  366. || test_crop(a, 0, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  367. || test_crop(a, 5, 0, 5, 11, -233, -233, -233, -233, 0, 0, 0, 0)
  368. || test_crop(a, 4, 0, 4, 8, -233, -233, -233, -233, 0, 0, 0, 0)
  369. || test_crop(a, 6, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
  370. || test_crop(a, 5, 0, 0, 0, 6, -233, -233, -233, 0, 0, 0, 0)
  371. || test_crop(a, 6, 0, 0, 0, 5, -233, -233, -233, 0, 0, 0, 0)
  372. || test_crop(a, 4, 0, 0, 0, 4, -233, -233, -233, 0, 0, 0, 0)
  373. || test_crop(a, 0, 5, 0, 0, -233, 4, -233, -233, 0, 0, 0, 0)
  374. || test_crop(a, 0, 6, 0, 0, -233, 5, -233, -233, 0, 0, 0, 0)
  375. || test_crop(a, 0, 4, 0, 0, -233, 6, -233, -233, 0, 0, 0, 0)
  376. || test_crop(a, 0, 0, 5, 0, -233, -233, 6, -233, 0, 0, 0, 0)
  377. || test_crop(a, 0, 0, 6, 0, -233, -233, 4, -233, 0, 0, 0, 0)
  378. || test_crop(a, 0, 0, 4, 0, -233, -233, 5, -233, 0, 0, 0, 0)
  379. || test_crop(a, 0, 0, 0, 11, -233, -233, -233, 7, 0, 0, 0, 0)
  380. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, 12, 0, 0, 0, 0)
  381. || test_crop(a, 0, 0, 0, 8, -233, -233, -233, 16, 0, 0, 0, 0)
  382. || test_crop(a, 5, 2, 0, 0, 6, 5, -233, -233, 0, 0, 0, 0)
  383. || test_crop(a, 6, 3, 0, 0, 5, 6, -233, -233, 0, 0, 0, 0)
  384. || test_crop(a, 4, 4, 0, 0, 4, 4, -233, -233, 0, 0, 0, 0)
  385. || test_crop(a, 5, 0, 3, 0, 2, -233, 5, -233, 0, 0, 0, 0)
  386. || test_crop(a, 6, 0, 2, 0, 3, -233, 3, -233, 0, 0, 0, 0)
  387. || test_crop(a, 4, 0, 4, 0, 4, -233, 4, -233, 0, 0, 0, 0)
  388. || test_crop(a, 0, 5, 0, 11, -233, 1, -233, 12, 0, 0, 0, 0)
  389. || test_crop(a, 0, 6, 0, 12, -233, 2, -233, 16, 0, 0, 0, 0)
  390. || test_crop(a, 0, 4, 0, 8, -233, 3, -233, 7, 0, 0, 0, 0)
  391. || test_crop(a, 0, 0, 4, 11, -233, -233, 3, 16, 0, 0, 0, 0)
  392. || test_crop(a, 0, 0, 5, 12, -233, -233, 2, 7, 0, 0, 0, 0)
  393. || test_crop(a, 0, 0, 6, 8, -233, -233, 1, 16, 0, 0, 0, 0)
  394. || test_crop(a, 5, 0, 5, 11, 1, -233, 2, 16, 0, 0, 0, 0)
  395. || test_crop(a, 6, 0, 6, 12, 2, -233, 3, 7, 0, 0, 0, 0)
  396. || test_crop(a, 4, 0, 4, 8, 3, -233, 1, 16, 0, 0, 0, 0)
  397. || test_crop(a, 4, 6, 3, 11, 2, 3, 4, 12, 0, 0, 0, 0)
  398. || test_crop(a, 5, 5, 4, 12, 3, 4, 5, 16, 0, 0, 0, 0)
  399. || test_crop(a, 6, 4, 2, 8, 4, 5, 6, 7, 0, 0, 0, 0)
  400. || test_crop(a, 5, 0, 0, 0, -233, -233, -233, -233, 2, 0, 0, 0)
  401. || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 3, 0, 0, 0)
  402. || test_crop(a, 4, 0, 0, 0, -233, -233, -233, -233, 4, 0, 0, 0)
  403. || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 4, 0, 0)
  404. || test_crop(a, 0, 3, 0, 0, -233, -233, -233, -233, 0, 3, 0, 0)
  405. || test_crop(a, 0, 2, 0, 0, -233, -233, -233, -233, 0, 2, 0, 0)
  406. || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 4, 0)
  407. || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 2, 0)
  408. || test_crop(a, 0, 0, 6, 0, -233, -233, -233, -233, 0, 0, 3, 0)
  409. || test_crop(a, 0, 0, 0, 11, -233, -233, -233, -233, 0, 0, 0, 12)
  410. || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 16)
  411. || test_crop(a, 0, 0, 0, 8, -233, -233, -233, -233, 0, 0, 0, 7)
  412. || test_crop(a, 5, 3, 0, 0, -233, -233, -233, -233, 5, 2, 0, 0)
  413. || test_crop(a, 6, 4, 0, 0, -233, -233, -233, -233, 3, 3, 0, 0)
  414. || test_crop(a, 4, 4, 0, 0, -233, -233, -233, -233, 2, 5, 0, 0)
  415. || test_crop(a, 0, 4, 0, 11, -233, -233, -233, -233, 0, 3, 0, 7)
  416. || test_crop(a, 0, 3, 0, 12, -233, -233, -233, -233, 0, 4, 0, 12)
  417. || test_crop(a, 0, 2, 0, 8, -233, -233, -233, -233, 0, 5, 0, 16)
  418. || test_crop(a, 0, 4, 4, 0, -233, -233, -233, -233, 0, 4, 1, 0)
  419. || test_crop(a, 0, 5, 5, 0, -233, -233, -233, -233, 0, 2, 2, 0)
  420. || test_crop(a, 0, 2, 6, 0, -233, -233, -233, -233, 0, 1, 3, 0)
  421. || test_crop(a, 3, 0, 0, 11, -233, -233, -233, -233, 3, 0, 0, 12)
  422. || test_crop(a, 4, 0, 0, 12, -233, -233, -233, -233, 4, 0, 0, 16)
  423. || test_crop(a, 5, 0, 0, 8, -233, -233, -233, -233, 2, 0, 0, 7)
  424. || test_crop(a, 0, 4, 4, 11, -233, -233, -233, -233, 0, 4, 4, 12)
  425. || test_crop(a, 0, 5, 5, 12, -233, -233, -233, -233, 0, 4, 4, 16)
  426. || test_crop(a, 0, 6, 6, 8, -233, -233, -233, -233, 0, 3, 3, 7)
  427. || test_crop(a, 1, 1, 1, 11, -233, -233, -233, -233, 1, 1, 1, 16)
  428. || test_crop(a, 2, 2, 2, 12, -233, -233, -233, -233, 2, 2, 2, 7)
  429. || test_crop(a, 3, 3, 3, 8, -233, -233, -233, -233, 3, 3, 3, 12);
  430. }
  431. static int test_crop_10(const ncnn::Mat& a)
  432. {
  433. return 0
  434. || test_crop(a, IntArrayMat(11), IntArrayMat(-233), IntArrayMat(0))
  435. || test_crop(a, IntArrayMat(8), IntArrayMat(-233), IntArrayMat(0))
  436. || test_crop(a, IntArrayMat(6), IntArrayMat(-233), IntArrayMat(1))
  437. || test_crop(a, IntArrayMat(5), IntArrayMat(-233), IntArrayMat(2))
  438. || test_crop(a, IntArrayMat(4), IntArrayMat(-233), IntArrayMat(-2))
  439. || test_crop(a, IntArrayMat(6), IntArrayMat(-233), IntArrayMat(3))
  440. || test_crop(a, IntArrayMat(5), IntArrayMat(-233), IntArrayMat(-1))
  441. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(-233, -233), IntArrayMat(0, 1))
  442. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-233, -233), IntArrayMat(0, 2))
  443. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(-233, -233), IntArrayMat(-4, -2))
  444. || test_crop(a, IntArrayMat(4, 4), IntArrayMat(-233, -233), IntArrayMat(1, 2))
  445. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(-233, -233), IntArrayMat(0, 3))
  446. || test_crop(a, IntArrayMat(5, 5), IntArrayMat(-233, -233), IntArrayMat(1, 3))
  447. || test_crop(a, IntArrayMat(4, 4), IntArrayMat(-233, -233), IntArrayMat(2, 3))
  448. || test_crop(a, IntArrayMat(12, 6, 6), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 2))
  449. || test_crop(a, IntArrayMat(11, 5, 5), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 2))
  450. || test_crop(a, IntArrayMat(8, 4, 4), IntArrayMat(-233, -233, -233), IntArrayMat(0, 1, 3))
  451. || test_crop(a, IntArrayMat(12, 6, 6), IntArrayMat(-233, -233, -233), IntArrayMat(0, 2, 3))
  452. || test_crop(a, IntArrayMat(11, 5, 5), IntArrayMat(-233, -233, -233), IntArrayMat(0, 2, 3))
  453. || test_crop(a, IntArrayMat(4, 4, 4), IntArrayMat(-233, -233, -233), IntArrayMat(1, 2, 3))
  454. || test_crop(a, IntArrayMat(6, 6, 6), IntArrayMat(-233, -233, -233), IntArrayMat(1, 2, 3))
  455. || test_crop(a, IntArrayMat(11, 5, 5, 5), IntArrayMat(-233, -233, -233, -233), IntArrayMat(0, 1, 2, 3))
  456. || test_crop(a, IntArrayMat(8, 4, 4, 4), IntArrayMat(-233, -233, -233, -233), IntArrayMat(0, 1, 2, 3))
  457. || test_crop(a, IntArrayMat(12, 6, 6, 6), IntArrayMat(-233, -233, -233, -233), IntArrayMat(-4, -3, -2, -1))
  458. || test_crop(a, IntArrayMat(11), IntArrayMat(11 + 16), IntArrayMat(0))
  459. || test_crop(a, IntArrayMat(12), IntArrayMat(12 + 7), IntArrayMat(0))
  460. || test_crop(a, IntArrayMat(8), IntArrayMat(8 + 12), IntArrayMat(-4))
  461. || test_crop(a, IntArrayMat(5), IntArrayMat(11), IntArrayMat(1))
  462. || test_crop(a, IntArrayMat(6), IntArrayMat(13), IntArrayMat(1))
  463. || test_crop(a, IntArrayMat(4), IntArrayMat(12), IntArrayMat(-3))
  464. || test_crop(a, IntArrayMat(3), IntArrayMat(12), IntArrayMat(2))
  465. || test_crop(a, IntArrayMat(4), IntArrayMat(13), IntArrayMat(2))
  466. || test_crop(a, IntArrayMat(5), IntArrayMat(11), IntArrayMat(-2))
  467. || test_crop(a, IntArrayMat(1), IntArrayMat(8), IntArrayMat(3))
  468. || test_crop(a, IntArrayMat(2), IntArrayMat(7), IntArrayMat(3))
  469. || test_crop(a, IntArrayMat(3), IntArrayMat(6), IntArrayMat(-1))
  470. || test_crop(a, IntArrayMat(11, 5), IntArrayMat(11 + 7, 11), IntArrayMat(0, 1))
  471. || test_crop(a, IntArrayMat(12, 6), IntArrayMat(12 + 12, 12), IntArrayMat(0, 1))
  472. || test_crop(a, IntArrayMat(8, 4), IntArrayMat(8 + 16, 13), IntArrayMat(-4, -3))
  473. || test_crop(a, IntArrayMat(11, 4), IntArrayMat(11 + 12, 13), IntArrayMat(0, 2))
  474. || test_crop(a, IntArrayMat(12, 3), IntArrayMat(12 + 16, 11), IntArrayMat(0, 2))
  475. || test_crop(a, IntArrayMat(8, 2), IntArrayMat(8 + 7, 12), IntArrayMat(-4, -2))
  476. || test_crop(a, IntArrayMat(11, 1), IntArrayMat(11 + 16, 5), IntArrayMat(0, 3))
  477. || test_crop(a, IntArrayMat(12, 2), IntArrayMat(12 + 7, 6), IntArrayMat(0, 3))
  478. || test_crop(a, IntArrayMat(8, 3), IntArrayMat(8 + 12, 7), IntArrayMat(-4, -1))
  479. || test_crop(a, IntArrayMat(3, 3), IntArrayMat(13, 4), IntArrayMat(1, 2))
  480. || test_crop(a, IntArrayMat(4, 2), IntArrayMat(12, 3), IntArrayMat(1, 2))
  481. || test_crop(a, IntArrayMat(5, 1), IntArrayMat(11, 2), IntArrayMat(-3, -2))
  482. || test_crop(a, IntArrayMat(5, 5), IntArrayMat(11, 8), IntArrayMat(1, 3))
  483. || test_crop(a, IntArrayMat(4, 6), IntArrayMat(12, 9), IntArrayMat(1, 3))
  484. || test_crop(a, IntArrayMat(3, 4), IntArrayMat(13, 7), IntArrayMat(-3, -1))
  485. || test_crop(a, IntArrayMat(2, 3), IntArrayMat(12, 9), IntArrayMat(2, 3))
  486. || test_crop(a, IntArrayMat(3, 2), IntArrayMat(11, 7), IntArrayMat(2, 3))
  487. || test_crop(a, IntArrayMat(4, 1), IntArrayMat(10, 8), IntArrayMat(-2, -1))
  488. || test_crop(a, IntArrayMat(11, 2, 2), IntArrayMat(11 + 6, 9, 9), IntArrayMat(0, 1, 2))
  489. || test_crop(a, IntArrayMat(12, 3, 3), IntArrayMat(12 + 1, 10, 10), IntArrayMat(0, 1, 2))
  490. || test_crop(a, IntArrayMat(8, 4, 4), IntArrayMat(8 + 3, 11, 11), IntArrayMat(-4, -3, -2))
  491. || test_crop(a, IntArrayMat(11, 4, 4), IntArrayMat(11 + 12, 12, 12), IntArrayMat(0, 1, 3))
  492. || test_crop(a, IntArrayMat(12, 5, 5), IntArrayMat(12 + 8, 11, 11), IntArrayMat(0, 1, 3))
  493. || test_crop(a, IntArrayMat(8, 6, 6), IntArrayMat(8 + 4, 13, 13), IntArrayMat(-4, -3, -1))
  494. || test_crop(a, IntArrayMat(11, 1, 4), IntArrayMat(11 + 5, 12, 12), IntArrayMat(0, 2, 3))
  495. || test_crop(a, IntArrayMat(12, 3, 3), IntArrayMat(12 + 3, 11, 11), IntArrayMat(0, 2, 3))
  496. || test_crop(a, IntArrayMat(8, 2, 5), IntArrayMat(8 + 2, 10, 10), IntArrayMat(-4, -2, -1))
  497. || test_crop(a, IntArrayMat(1, 1, 1), IntArrayMat(7, 7, 7), IntArrayMat(1, 2, 3))
  498. || test_crop(a, IntArrayMat(2, 2, 2), IntArrayMat(8, 9, 10), IntArrayMat(1, 2, 3))
  499. || test_crop(a, IntArrayMat(3, 3, 3), IntArrayMat(11, 12, 13), IntArrayMat(-3, -2, -1))
  500. || test_crop(a, IntArrayMat(11, 2, 3, 6), IntArrayMat(11 + 11, 10, 12, 11), IntArrayMat(0, 1, 2, 3))
  501. || test_crop(a, IntArrayMat(12, 3, 4, 5), IntArrayMat(12 + 12, 9, 11, 13), IntArrayMat(0, 1, 2, 3))
  502. || test_crop(a, IntArrayMat(8, 4, 5, 4), IntArrayMat(8 + 8, 8, 10, 12), IntArrayMat(-4, -3, -2, -1))
  503. || test_crop(a, IntArrayMat(11), IntArrayMat(-7 + 1), IntArrayMat(0))
  504. || test_crop(a, IntArrayMat(12), IntArrayMat(-12 + 1), IntArrayMat(0))
  505. || test_crop(a, IntArrayMat(8), IntArrayMat(-16 + 1), IntArrayMat(-4))
  506. || test_crop(a, IntArrayMat(5), IntArrayMat(-6 + 1), IntArrayMat(1))
  507. || test_crop(a, IntArrayMat(6), IntArrayMat(-5 + 1), IntArrayMat(1))
  508. || test_crop(a, IntArrayMat(4), IntArrayMat(-4 + 1), IntArrayMat(-3))
  509. || test_crop(a, IntArrayMat(4), IntArrayMat(-4 + 1), IntArrayMat(2))
  510. || test_crop(a, IntArrayMat(5), IntArrayMat(-5 + 1), IntArrayMat(2))
  511. || test_crop(a, IntArrayMat(6), IntArrayMat(-6 + 1), IntArrayMat(-2))
  512. || test_crop(a, IntArrayMat(1), IntArrayMat(-5 + 1), IntArrayMat(3))
  513. || test_crop(a, IntArrayMat(2), IntArrayMat(-4 + 1), IntArrayMat(3))
  514. || test_crop(a, IntArrayMat(3), IntArrayMat(-3 + 1), IntArrayMat(-1))
  515. || test_crop(a, IntArrayMat(11, 3), IntArrayMat(-7 + 1, -3 + 1), IntArrayMat(0, 1))
  516. || test_crop(a, IntArrayMat(12, 4), IntArrayMat(-12 + 1, -4 + 1), IntArrayMat(0, 1))
  517. || test_crop(a, IntArrayMat(8, 5), IntArrayMat(-16 + 1, -5 + 1), IntArrayMat(-4, -3))
  518. || test_crop(a, IntArrayMat(11, 1), IntArrayMat(-12 + 1, -5 + 1), IntArrayMat(0, 2))
  519. || test_crop(a, IntArrayMat(12, 2), IntArrayMat(-16 + 1, -4 + 1), IntArrayMat(0, 2))
  520. || test_crop(a, IntArrayMat(8, 3), IntArrayMat(-7 + 1, -6 + 1), IntArrayMat(-4, -2))
  521. || test_crop(a, IntArrayMat(11, 3), IntArrayMat(-12 + 1, -2 + 1), IntArrayMat(0, 3))
  522. || test_crop(a, IntArrayMat(12, 4), IntArrayMat(-16 + 1, -3 + 1), IntArrayMat(0, 3))
  523. || test_crop(a, IntArrayMat(8, 5), IntArrayMat(-7 + 1, -4 + 1), IntArrayMat(-4, -1))
  524. || test_crop(a, IntArrayMat(2, 3), IntArrayMat(-4 + 1, -2 + 1), IntArrayMat(1, 2))
  525. || test_crop(a, IntArrayMat(3, 4), IntArrayMat(-2 + 1, -3 + 1), IntArrayMat(1, 2))
  526. || test_crop(a, IntArrayMat(4, 5), IntArrayMat(-3 + 1, -4 + 1), IntArrayMat(-3, -2))
  527. || test_crop(a, IntArrayMat(3, 2), IntArrayMat(-2 + 1, -4 + 1), IntArrayMat(1, 3))
  528. || test_crop(a, IntArrayMat(4, 3), IntArrayMat(-3 + 1, -2 + 1), IntArrayMat(1, 3))
  529. || test_crop(a, IntArrayMat(5, 4), IntArrayMat(-4 + 1, -3 + 1), IntArrayMat(-3, -1))
  530. || test_crop(a, IntArrayMat(2, 3), IntArrayMat(-4 + 1, -6 + 1), IntArrayMat(2, 3))
  531. || test_crop(a, IntArrayMat(1, 2), IntArrayMat(-5 + 1, -5 + 1), IntArrayMat(2, 3))
  532. || test_crop(a, IntArrayMat(3, 1), IntArrayMat(-6 + 1, -4 + 1), IntArrayMat(-2, -1))
  533. || test_crop(a, IntArrayMat(11, 3, 3), IntArrayMat(-7 + 1, -3 + 1, -4 + 1), IntArrayMat(0, 1, 2))
  534. || test_crop(a, IntArrayMat(12, 4, 4), IntArrayMat(-12 + 1, -4 + 1, -3 + 1), IntArrayMat(0, 1, 2))
  535. || test_crop(a, IntArrayMat(8, 5, 5), IntArrayMat(-16 + 1, -5 + 1, -5 + 1), IntArrayMat(-4, -3, -2))
  536. || test_crop(a, IntArrayMat(11, 2, 2), IntArrayMat(-7 + 1, -5 + 1, -4 + 1), IntArrayMat(0, 1, 3))
  537. || test_crop(a, IntArrayMat(12, 1, 1), IntArrayMat(-12 + 1, -6 + 1, -5 + 1), IntArrayMat(0, 1, 3))
  538. || test_crop(a, IntArrayMat(8, 3, 3), IntArrayMat(-16 + 1, -4 + 1, -6 + 1), IntArrayMat(-4, -3, -1))
  539. || test_crop(a, IntArrayMat(11, 2, 5), IntArrayMat(-7 + 1, -2 + 1, -5 + 1), IntArrayMat(0, 2, 3))
  540. || test_crop(a, IntArrayMat(12, 3, 3), IntArrayMat(-12 + 1, -3 + 1, -4 + 1), IntArrayMat(0, 2, 3))
  541. || test_crop(a, IntArrayMat(8, 4, 4), IntArrayMat(-16 + 1, -4 + 1, -3 + 1), IntArrayMat(-4, -2, -1))
  542. || test_crop(a, IntArrayMat(1, 3, 3), IntArrayMat(-3 + 1, -6 + 1, -4 + 1), IntArrayMat(1, 2, 3))
  543. || test_crop(a, IntArrayMat(2, 2, 2), IntArrayMat(-4 + 1, -4 + 1, -5 + 1), IntArrayMat(1, 2, 3))
  544. || test_crop(a, IntArrayMat(3, 1, 1), IntArrayMat(-5 + 1, -5 + 1, -6 + 1), IntArrayMat(-3, -2, -1))
  545. || test_crop(a, IntArrayMat(11, 3, 4, 4), IntArrayMat(-7 + 1, -3 + 1, -2 + 1, -4 + 1), IntArrayMat(0, 1, 2, 3))
  546. || test_crop(a, IntArrayMat(12, 4, 5, 3), IntArrayMat(-12 + 1, -4 + 1, -3 + 1, -5 + 1), IntArrayMat(0, 1, 2, 3))
  547. || test_crop(a, IntArrayMat(8, 5, 6, 2), IntArrayMat(-16 + 1, -5 + 1, -4 + 1, -3 + 1), IntArrayMat(-4, -3, -2, -1));
  548. }
  549. static int test_crop_11(const ncnn::Mat& a)
  550. {
  551. return 0
  552. || test_crop(a, 0, 0, 0, 0, a)
  553. || test_crop(a, 0, 5, 0, 0, ncnn::Mat(6, 6, 6))
  554. || test_crop(a, 6, 0, 0, 0, ncnn::Mat(8, 8, 8))
  555. || test_crop(a, 5, 5, 5, 0, ncnn::Mat(6, 6, 6))
  556. || test_crop(a, 6, 6, 6, 0, ncnn::Mat(8, 8, 8))
  557. || test_crop(a, 4, 4, 4, 0, ncnn::Mat(5, 5, 5))
  558. || test_crop(a, 3, 3, 3, 11, ncnn::Mat(3, 3, 3, 7))
  559. || test_crop(a, 4, 4, 4, 12, ncnn::Mat(6, 6, 6, 12))
  560. || test_crop(a, 5, 5, 5, 8, ncnn::Mat(8, 8, 8, 16));
  561. }
  562. int main()
  563. {
  564. SRAND(776757);
  565. return 0
  566. || test_crop_0(RandomMat(112))
  567. || test_crop_0(RandomMat(126))
  568. || test_crop_0(RandomMat(127))
  569. || test_crop_1(RandomMat(112))
  570. || test_crop_1(RandomMat(126))
  571. || test_crop_1(RandomMat(127))
  572. || test_crop_2(RandomMat(112))
  573. || test_crop_2(RandomMat(126))
  574. || test_crop_2(RandomMat(127))
  575. || test_crop_3(RandomMat(20, 40))
  576. || test_crop_3(RandomMat(15, 36))
  577. || test_crop_3(RandomMat(16, 33))
  578. || test_crop_4(RandomMat(20, 40))
  579. || test_crop_4(RandomMat(15, 36))
  580. || test_crop_4(RandomMat(16, 33))
  581. || test_crop_5(RandomMat(20, 40))
  582. || test_crop_5(RandomMat(15, 36))
  583. || test_crop_5(RandomMat(16, 33))
  584. || test_crop_6(RandomMat(20, 20, 40))
  585. || test_crop_6(RandomMat(15, 15, 36))
  586. || test_crop_6(RandomMat(16, 16, 33))
  587. || test_crop_7(RandomMat(20, 20, 40))
  588. || test_crop_7(RandomMat(15, 15, 36))
  589. || test_crop_7(RandomMat(16, 16, 33))
  590. || test_crop_8(RandomMat(20, 20, 40))
  591. || test_crop_8(RandomMat(15, 15, 36))
  592. || test_crop_8(RandomMat(16, 16, 33))
  593. || test_crop_9(RandomMat(20, 20, 20, 40))
  594. || test_crop_9(RandomMat(15, 15, 15, 36))
  595. || test_crop_9(RandomMat(16, 16, 16, 33))
  596. || test_crop_10(RandomMat(20, 20, 20, 40))
  597. || test_crop_10(RandomMat(15, 15, 15, 36))
  598. || test_crop_10(RandomMat(16, 16, 16, 33))
  599. || test_crop_11(RandomMat(20, 20, 20, 40))
  600. || test_crop_11(RandomMat(15, 15, 15, 36))
  601. || test_crop_11(RandomMat(16, 16, 16, 33));
  602. }