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_reduction.cpp 19 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2021 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/reduction.h"
  15. #include "testutil.h"
  16. #define OP_TYPE_MAX 11
  17. static int op_type = 0;
  18. static ncnn::Mat IntArrayMat(int a0)
  19. {
  20. ncnn::Mat m(1);
  21. int* p = m;
  22. p[0] = a0;
  23. return m;
  24. }
  25. static ncnn::Mat IntArrayMat(int a0, int a1)
  26. {
  27. ncnn::Mat m(2);
  28. int* p = m;
  29. p[0] = a0;
  30. p[1] = a1;
  31. return m;
  32. }
  33. static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
  34. {
  35. ncnn::Mat m(3);
  36. int* p = m;
  37. p[0] = a0;
  38. p[1] = a1;
  39. p[2] = a2;
  40. return m;
  41. }
  42. static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3)
  43. {
  44. ncnn::Mat m(4);
  45. int* p = m;
  46. p[0] = a0;
  47. p[1] = a1;
  48. p[2] = a2;
  49. p[3] = a3;
  50. return m;
  51. }
  52. static void print_int_array(const ncnn::Mat& a)
  53. {
  54. const int* pa = a;
  55. fprintf(stderr, "[");
  56. for (int i = 0; i < a.w; i++)
  57. {
  58. fprintf(stderr, " %d", pa[i]);
  59. }
  60. fprintf(stderr, " ]");
  61. }
  62. static int test_reduction(const ncnn::Mat& _a, float coeff, int keepdims)
  63. {
  64. ncnn::Mat a = _a;
  65. if (op_type == 9 || op_type == 10)
  66. {
  67. // value must be positive for logsum and logsumexp
  68. Randomize(a, 0.001f, 2.f);
  69. }
  70. ncnn::ParamDict pd;
  71. pd.set(0, op_type);
  72. pd.set(1, 1); // reduce_all
  73. pd.set(2, coeff);
  74. pd.set(4, keepdims);
  75. std::vector<ncnn::Mat> weights(0);
  76. int ret = test_layer<ncnn::Reduction>("Reduction", pd, weights, a);
  77. if (ret != 0)
  78. {
  79. fprintf(stderr, "test_reduction failed a.dims=%d a=(%d %d %d %d) op_type=%d coeff=%f keepdims=%d reduce_all=1\n", a.dims, a.w, a.h, a.d, a.c, op_type, coeff, keepdims);
  80. }
  81. return ret;
  82. }
  83. static int test_reduction(const ncnn::Mat& _a, float coeff, int keepdims, const ncnn::Mat& axes)
  84. {
  85. ncnn::Mat a = _a;
  86. if (op_type == 9 || op_type == 10)
  87. {
  88. // value must be positive for logsum and logsumexp
  89. Randomize(a, 0.001f, 2.f);
  90. }
  91. ncnn::ParamDict pd;
  92. pd.set(0, op_type);
  93. pd.set(1, 0); // reduce_all
  94. pd.set(2, coeff);
  95. pd.set(3, axes);
  96. pd.set(4, keepdims);
  97. std::vector<ncnn::Mat> weights(0);
  98. int ret = test_layer<ncnn::Reduction>("Reduction", pd, weights, a);
  99. if (ret != 0)
  100. {
  101. fprintf(stderr, "test_reduction failed a.dims=%d a=(%d %d %d %d) op_type=%d coeff=%f keepdims=%d", a.dims, a.w, a.h, a.d, a.c, op_type, coeff, keepdims);
  102. fprintf(stderr, " axes=");
  103. print_int_array(axes);
  104. fprintf(stderr, "\n");
  105. }
  106. return ret;
  107. }
  108. static int test_reduction_0()
  109. {
  110. return 0
  111. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0)
  112. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0)
  113. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0)
  114. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0)
  115. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0)
  116. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0)
  117. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1)
  118. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1)
  119. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1)
  120. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1)
  121. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1)
  122. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1)
  123. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0))
  124. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(1))
  125. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(2))
  126. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(3))
  127. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0, 1))
  128. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(0, 2))
  129. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0, 3))
  130. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(1, 2))
  131. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(1, 3))
  132. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(2, 3))
  133. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0, 1, 2))
  134. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(0, 1, 3))
  135. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0, 2, 3))
  136. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 0, IntArrayMat(1, 2, 3))
  137. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 0, IntArrayMat(0, 1, 2, 3))
  138. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0))
  139. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(1))
  140. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(2))
  141. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(3))
  142. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0, 1))
  143. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(0, 2))
  144. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0, 3))
  145. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(1, 2))
  146. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(1, 3))
  147. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(2, 3))
  148. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0, 1, 2))
  149. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(0, 1, 3))
  150. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0, 2, 3))
  151. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 0, IntArrayMat(1, 2, 3))
  152. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 0, IntArrayMat(0, 1, 2, 3))
  153. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0))
  154. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(1))
  155. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(2))
  156. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(3))
  157. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0, 1))
  158. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(0, 2))
  159. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0, 3))
  160. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(1, 2))
  161. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(1, 3))
  162. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(2, 3))
  163. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0, 1, 2))
  164. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(0, 1, 3))
  165. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0, 2, 3))
  166. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 0, IntArrayMat(1, 2, 3))
  167. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 0, IntArrayMat(0, 1, 2, 3))
  168. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0))
  169. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(1))
  170. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(2))
  171. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(3))
  172. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0, 1))
  173. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(0, 2))
  174. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0, 3))
  175. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(1, 2))
  176. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(1, 3))
  177. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(2, 3))
  178. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0, 1, 2))
  179. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(0, 1, 3))
  180. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0, 2, 3))
  181. || test_reduction(RandomMat(5, 6, 7, 24), 2.f, 1, IntArrayMat(1, 2, 3))
  182. || test_reduction(RandomMat(5, 6, 7, 24), 1.f, 1, IntArrayMat(0, 1, 2, 3))
  183. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0))
  184. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(1))
  185. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(2))
  186. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(3))
  187. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0, 1))
  188. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(0, 2))
  189. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0, 3))
  190. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(1, 2))
  191. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(1, 3))
  192. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(2, 3))
  193. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0, 1, 2))
  194. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(0, 1, 3))
  195. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0, 2, 3))
  196. || test_reduction(RandomMat(7, 8, 9, 12), 2.f, 1, IntArrayMat(1, 2, 3))
  197. || test_reduction(RandomMat(7, 8, 9, 12), 1.f, 1, IntArrayMat(0, 1, 2, 3))
  198. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0))
  199. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(1))
  200. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(2))
  201. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(3))
  202. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0, 1))
  203. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(0, 2))
  204. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0, 3))
  205. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(1, 2))
  206. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(1, 3))
  207. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(2, 3))
  208. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0, 1, 2))
  209. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(0, 1, 3))
  210. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0, 2, 3))
  211. || test_reduction(RandomMat(3, 4, 5, 13), 2.f, 1, IntArrayMat(1, 2, 3))
  212. || test_reduction(RandomMat(3, 4, 5, 13), 1.f, 1, IntArrayMat(0, 1, 2, 3));
  213. }
  214. static int test_reduction_1()
  215. {
  216. return 0
  217. || test_reduction(RandomMat(5, 7, 24), 1.f, 0)
  218. || test_reduction(RandomMat(5, 7, 24), 2.f, 0)
  219. || test_reduction(RandomMat(7, 9, 12), 1.f, 0)
  220. || test_reduction(RandomMat(7, 9, 12), 2.f, 0)
  221. || test_reduction(RandomMat(3, 5, 13), 1.f, 0)
  222. || test_reduction(RandomMat(3, 5, 13), 2.f, 0)
  223. || test_reduction(RandomMat(5, 7, 24), 1.f, 1)
  224. || test_reduction(RandomMat(5, 7, 24), 2.f, 1)
  225. || test_reduction(RandomMat(7, 9, 12), 1.f, 1)
  226. || test_reduction(RandomMat(7, 9, 12), 2.f, 1)
  227. || test_reduction(RandomMat(3, 5, 13), 1.f, 1)
  228. || test_reduction(RandomMat(3, 5, 13), 2.f, 1)
  229. || test_reduction(RandomMat(5, 7, 24), 1.f, 0, IntArrayMat(0))
  230. || test_reduction(RandomMat(5, 7, 24), 2.f, 0, IntArrayMat(1))
  231. || test_reduction(RandomMat(5, 7, 24), 1.f, 0, IntArrayMat(0, 1))
  232. || test_reduction(RandomMat(5, 7, 24), 2.f, 0, IntArrayMat(0, 2))
  233. || test_reduction(RandomMat(5, 7, 24), 1.f, 0, IntArrayMat(1, 2))
  234. || test_reduction(RandomMat(5, 7, 24), 2.f, 0, IntArrayMat(0, 1, 2))
  235. || test_reduction(RandomMat(7, 9, 12), 1.f, 0, IntArrayMat(0))
  236. || test_reduction(RandomMat(7, 9, 12), 2.f, 0, IntArrayMat(1))
  237. || test_reduction(RandomMat(7, 9, 12), 1.f, 0, IntArrayMat(0, 1))
  238. || test_reduction(RandomMat(7, 9, 12), 2.f, 0, IntArrayMat(0, 2))
  239. || test_reduction(RandomMat(7, 9, 12), 1.f, 0, IntArrayMat(1, 2))
  240. || test_reduction(RandomMat(7, 9, 12), 2.f, 0, IntArrayMat(0, 1, 2))
  241. || test_reduction(RandomMat(3, 5, 13), 1.f, 0, IntArrayMat(0))
  242. || test_reduction(RandomMat(3, 5, 13), 2.f, 0, IntArrayMat(1))
  243. || test_reduction(RandomMat(3, 5, 13), 1.f, 0, IntArrayMat(0, 1))
  244. || test_reduction(RandomMat(3, 5, 13), 2.f, 0, IntArrayMat(0, 2))
  245. || test_reduction(RandomMat(3, 5, 13), 1.f, 0, IntArrayMat(1, 2))
  246. || test_reduction(RandomMat(3, 5, 13), 2.f, 0, IntArrayMat(0, 1, 2))
  247. || test_reduction(RandomMat(5, 7, 24), 1.f, 1, IntArrayMat(0))
  248. || test_reduction(RandomMat(5, 7, 24), 2.f, 1, IntArrayMat(1))
  249. || test_reduction(RandomMat(5, 7, 24), 1.f, 1, IntArrayMat(0, 1))
  250. || test_reduction(RandomMat(5, 7, 24), 2.f, 1, IntArrayMat(0, 2))
  251. || test_reduction(RandomMat(5, 7, 24), 1.f, 1, IntArrayMat(1, 2))
  252. || test_reduction(RandomMat(5, 7, 24), 2.f, 1, IntArrayMat(0, 1, 2))
  253. || test_reduction(RandomMat(7, 9, 12), 1.f, 1, IntArrayMat(0))
  254. || test_reduction(RandomMat(7, 9, 12), 2.f, 1, IntArrayMat(1))
  255. || test_reduction(RandomMat(7, 9, 12), 1.f, 1, IntArrayMat(0, 1))
  256. || test_reduction(RandomMat(7, 9, 12), 2.f, 1, IntArrayMat(0, 2))
  257. || test_reduction(RandomMat(7, 9, 12), 1.f, 1, IntArrayMat(1, 2))
  258. || test_reduction(RandomMat(7, 9, 12), 2.f, 1, IntArrayMat(0, 1, 2))
  259. || test_reduction(RandomMat(3, 5, 13), 1.f, 1, IntArrayMat(0))
  260. || test_reduction(RandomMat(3, 5, 13), 2.f, 1, IntArrayMat(1))
  261. || test_reduction(RandomMat(3, 5, 13), 1.f, 1, IntArrayMat(0, 1))
  262. || test_reduction(RandomMat(3, 5, 13), 2.f, 1, IntArrayMat(0, 2))
  263. || test_reduction(RandomMat(3, 5, 13), 1.f, 1, IntArrayMat(1, 2))
  264. || test_reduction(RandomMat(3, 5, 13), 2.f, 1, IntArrayMat(0, 1, 2));
  265. }
  266. static int test_reduction_2()
  267. {
  268. return 0
  269. || test_reduction(RandomMat(15, 24), 1.f, 0)
  270. || test_reduction(RandomMat(15, 24), 2.f, 0)
  271. || test_reduction(RandomMat(17, 12), 1.f, 0)
  272. || test_reduction(RandomMat(17, 12), 2.f, 0)
  273. || test_reduction(RandomMat(19, 15), 1.f, 0)
  274. || test_reduction(RandomMat(19, 15), 2.f, 0)
  275. || test_reduction(RandomMat(15, 24), 1.f, 1)
  276. || test_reduction(RandomMat(15, 24), 2.f, 1)
  277. || test_reduction(RandomMat(17, 12), 1.f, 1)
  278. || test_reduction(RandomMat(17, 12), 2.f, 1)
  279. || test_reduction(RandomMat(19, 15), 1.f, 1)
  280. || test_reduction(RandomMat(19, 15), 2.f, 1)
  281. || test_reduction(RandomMat(15, 24), 1.f, 0, IntArrayMat(0))
  282. || test_reduction(RandomMat(15, 24), 2.f, 0, IntArrayMat(1))
  283. || test_reduction(RandomMat(15, 24), 1.f, 0, IntArrayMat(0, 1))
  284. || test_reduction(RandomMat(17, 12), 2.f, 0, IntArrayMat(0))
  285. || test_reduction(RandomMat(17, 12), 1.f, 0, IntArrayMat(1))
  286. || test_reduction(RandomMat(17, 12), 2.f, 0, IntArrayMat(0, 1))
  287. || test_reduction(RandomMat(19, 15), 1.f, 0, IntArrayMat(0))
  288. || test_reduction(RandomMat(19, 15), 2.f, 0, IntArrayMat(1))
  289. || test_reduction(RandomMat(19, 15), 1.f, 0, IntArrayMat(0, 1))
  290. || test_reduction(RandomMat(15, 24), 2.f, 1, IntArrayMat(0))
  291. || test_reduction(RandomMat(15, 24), 1.f, 1, IntArrayMat(1))
  292. || test_reduction(RandomMat(15, 24), 2.f, 1, IntArrayMat(0, 1))
  293. || test_reduction(RandomMat(17, 12), 1.f, 1, IntArrayMat(0))
  294. || test_reduction(RandomMat(17, 12), 2.f, 1, IntArrayMat(1))
  295. || test_reduction(RandomMat(17, 12), 1.f, 1, IntArrayMat(0, 1))
  296. || test_reduction(RandomMat(19, 15), 2.f, 1, IntArrayMat(0))
  297. || test_reduction(RandomMat(19, 15), 1.f, 1, IntArrayMat(1))
  298. || test_reduction(RandomMat(19, 15), 2.f, 1, IntArrayMat(0, 1));
  299. }
  300. static int test_reduction_3()
  301. {
  302. return 0
  303. || test_reduction(RandomMat(128), 1.f, 0)
  304. || test_reduction(RandomMat(128), 2.f, 0)
  305. || test_reduction(RandomMat(124), 1.f, 0)
  306. || test_reduction(RandomMat(124), 2.f, 0)
  307. || test_reduction(RandomMat(127), 1.f, 0)
  308. || test_reduction(RandomMat(127), 2.f, 0)
  309. || test_reduction(RandomMat(128), 1.f, 1)
  310. || test_reduction(RandomMat(128), 2.f, 1)
  311. || test_reduction(RandomMat(124), 1.f, 1)
  312. || test_reduction(RandomMat(124), 2.f, 1)
  313. || test_reduction(RandomMat(127), 1.f, 1)
  314. || test_reduction(RandomMat(127), 2.f, 1)
  315. || test_reduction(RandomMat(128), 1.f, 0, IntArrayMat(0))
  316. || test_reduction(RandomMat(128), 2.f, 0, IntArrayMat(0))
  317. || test_reduction(RandomMat(124), 1.f, 0, IntArrayMat(0))
  318. || test_reduction(RandomMat(124), 2.f, 0, IntArrayMat(0))
  319. || test_reduction(RandomMat(127), 1.f, 0, IntArrayMat(0))
  320. || test_reduction(RandomMat(127), 2.f, 0, IntArrayMat(0))
  321. || test_reduction(RandomMat(128), 1.f, 1, IntArrayMat(0))
  322. || test_reduction(RandomMat(128), 2.f, 1, IntArrayMat(0))
  323. || test_reduction(RandomMat(124), 1.f, 1, IntArrayMat(0))
  324. || test_reduction(RandomMat(124), 2.f, 1, IntArrayMat(0))
  325. || test_reduction(RandomMat(127), 1.f, 1, IntArrayMat(0))
  326. || test_reduction(RandomMat(127), 1.f, 1, IntArrayMat(0));
  327. }
  328. int main()
  329. {
  330. SRAND(7767517);
  331. for (op_type = 0; op_type < OP_TYPE_MAX; op_type++)
  332. {
  333. int ret = 0
  334. || test_reduction_0()
  335. || test_reduction_1()
  336. || test_reduction_2()
  337. || test_reduction_3();
  338. if (ret != 0)
  339. return ret;
  340. }
  341. return 0;
  342. }