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.9 kB

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