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_copyto.cpp 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Copyright 2023 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_copyto(const ncnn::Mat& self, const ncnn::Mat& src, int woffset, int hoffset, int doffset, int coffset)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, woffset); // woffset
  8. pd.set(1, hoffset); // hoffset
  9. pd.set(13, doffset); // doffset
  10. pd.set(2, coffset); // coffset
  11. std::vector<ncnn::Mat> weights(0);
  12. std::vector<ncnn::Mat> as(2);
  13. as[0] = self;
  14. as[1] = src;
  15. int ret = test_layer("CopyTo", pd, weights, as, 1);
  16. if (ret != 0)
  17. {
  18. fprintf(stderr, "test_copyto failed self.dims=%d self=(%d %d %d %d) src.dims=%d src=(%d %d %d %d) woffset=%d hoffset=%d doffset=%d coffset=%d\n", self.dims, self.w, self.h, self.d, self.c, src.dims, src.w, src.h, src.d, src.c, woffset, hoffset, doffset, coffset);
  19. }
  20. return ret;
  21. }
  22. static int test_copyto_0()
  23. {
  24. ncnn::Mat a[] = {
  25. RandomMat(112),
  26. RandomMat(126),
  27. RandomMat(127)
  28. };
  29. ncnn::Mat b[] = {
  30. RandomMat(33),
  31. RandomMat(36),
  32. RandomMat(64)
  33. };
  34. for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
  35. {
  36. for (int j = 0; j < sizeof(b) / sizeof(b[0]); j++)
  37. {
  38. const ncnn::Mat& self = a[i];
  39. const ncnn::Mat& src = b[j];
  40. int ret = 0
  41. || test_copyto(self, src, 0, 0, 0, 0)
  42. || test_copyto(self, src, 13, 0, 0, 0)
  43. || test_copyto(self, src, 28, 0, 0, 0)
  44. || test_copyto(self, src, 32, 0, 0, 0);
  45. if (ret != 0)
  46. return ret;
  47. }
  48. }
  49. return 0;
  50. }
  51. static int test_copyto_1()
  52. {
  53. ncnn::Mat a[] = {
  54. RandomMat(72, 112),
  55. RandomMat(87, 126),
  56. RandomMat(64, 127)
  57. };
  58. ncnn::Mat b[] = {
  59. RandomMat(14, 33),
  60. RandomMat(24, 36),
  61. RandomMat(16, 64),
  62. RandomMat(14),
  63. RandomMat(24),
  64. RandomMat(16)
  65. };
  66. for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
  67. {
  68. for (int j = 0; j < sizeof(b) / sizeof(b[0]); j++)
  69. {
  70. const ncnn::Mat& self = a[i];
  71. const ncnn::Mat& src = b[j];
  72. int ret = 0
  73. || test_copyto(self, src, 0, 0, 0, 0)
  74. || test_copyto(self, src, 1, 13, 0, 0)
  75. || test_copyto(self, src, 3, 28, 0, 0)
  76. || test_copyto(self, src, 10, 32, 0, 0);
  77. if (ret != 0)
  78. return ret;
  79. }
  80. }
  81. return 0;
  82. }
  83. static int test_copyto_2()
  84. {
  85. ncnn::Mat a[] = {
  86. RandomMat(32, 42, 81),
  87. RandomMat(33, 57, 80),
  88. RandomMat(36, 34, 88)
  89. };
  90. ncnn::Mat b[] = {
  91. RandomMat(1, 14, 23),
  92. RandomMat(12, 1, 28),
  93. RandomMat(11, 8, 32),
  94. RandomMat(1, 14),
  95. RandomMat(12, 1),
  96. RandomMat(11, 8),
  97. RandomMat(1),
  98. RandomMat(12),
  99. RandomMat(11)
  100. };
  101. for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
  102. {
  103. for (int j = 0; j < sizeof(b) / sizeof(b[0]); j++)
  104. {
  105. const ncnn::Mat& self = a[i];
  106. const ncnn::Mat& src = b[j];
  107. int ret = 0
  108. || test_copyto(self, src, 0, 0, 0, 0)
  109. || test_copyto(self, src, 0, 1, 0, 13)
  110. || test_copyto(self, src, 4, 3, 0, 28)
  111. || test_copyto(self, src, 5, 0, 0, 32);
  112. if (ret != 0)
  113. return ret;
  114. }
  115. }
  116. return 0;
  117. }
  118. static int test_copyto_3()
  119. {
  120. ncnn::Mat a[] = {
  121. RandomMat(12, 42, 7, 81),
  122. RandomMat(13, 57, 5, 80),
  123. RandomMat(16, 34, 6, 88)
  124. };
  125. ncnn::Mat b[] = {
  126. RandomMat(1, 14, 2, 23),
  127. RandomMat(12, 1, 3, 28),
  128. RandomMat(11, 8, 1, 32),
  129. RandomMat(1, 14, 2),
  130. RandomMat(12, 1, 3),
  131. RandomMat(11, 8, 1),
  132. RandomMat(1, 14),
  133. RandomMat(12, 1),
  134. RandomMat(11, 8),
  135. RandomMat(1),
  136. RandomMat(12),
  137. RandomMat(11)
  138. };
  139. for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
  140. {
  141. for (int j = 0; j < sizeof(b) / sizeof(b[0]); j++)
  142. {
  143. const ncnn::Mat& self = a[i];
  144. const ncnn::Mat& src = b[j];
  145. int ret = 0
  146. || test_copyto(self, src, 0, 0, 0, 0)
  147. || test_copyto(self, src, 0, 1, 1, 13)
  148. || test_copyto(self, src, 4, 3, 0, 28)
  149. || test_copyto(self, src, 5, 0, 2, 32);
  150. if (ret != 0)
  151. return ret;
  152. }
  153. }
  154. return 0;
  155. }
  156. static int test_copyto_4()
  157. {
  158. return 0
  159. || test_copyto(RandomMat(15), RandomMat(15), 0, 0, 0, 0)
  160. || test_copyto(RandomMat(11, 15), RandomMat(11, 15), 0, 0, 0, 0)
  161. || test_copyto(RandomMat(4, 5, 16), RandomMat(4, 5, 16), 0, 0, 0, 0)
  162. || test_copyto(RandomMat(3, 4, 5, 16), RandomMat(3, 4, 5, 16), 0, 0, 0, 0);
  163. }
  164. int main()
  165. {
  166. SRAND(776757);
  167. return 0
  168. || test_copyto_0()
  169. || test_copyto_1()
  170. || test_copyto_2()
  171. || test_copyto_3()
  172. || test_copyto_4();
  173. }