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 18 kB

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