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_reshape.cpp 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "testutil.h"
  15. #include "layer/reshape.h"
  16. static int test_reshape(const ncnn::Mat& a, int outw, int outh, int outc)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, outw);// w
  20. pd.set(1, outh);// h
  21. pd.set(2, outc);// c
  22. std::vector<ncnn::Mat> weights(0);
  23. ncnn::Option opt;
  24. opt.num_threads = 1;
  25. opt.use_vulkan_compute = true;
  26. opt.use_int8_inference = false;
  27. int ret = test_layer<ncnn::Reshape>("Reshape", pd, weights, opt, a);
  28. if (ret != 0)
  29. {
  30. fprintf(stderr, "test_reshape failed a.dims=%d a=(%d %d %d) outw=%d outh=%d outc=%d\n", a.dims, a.w, a.h, a.c, outw, outh, outc);
  31. }
  32. return ret;
  33. }
  34. static int test_reshape_0()
  35. {
  36. ncnn::Mat a = RandomMat(3, 7, 16);
  37. return 0
  38. || test_reshape(a, 7, 3, 16)
  39. || test_reshape(a, 3, 16, 7)
  40. || test_reshape(a, 16, 7, 3)
  41. || test_reshape(a, 2, 3, -1)
  42. || test_reshape(a, -1, 8, 2)
  43. || test_reshape(a, -1, 4, -233)
  44. || test_reshape(a, 8, -1, -233)
  45. || test_reshape(a, 16, 21, -233)
  46. || test_reshape(a, -1, -233, -233)
  47. ;
  48. }
  49. static int test_reshape_1()
  50. {
  51. ncnn::Mat a = RandomMat(4, 14, 13);
  52. return 0
  53. || test_reshape(a, 14, 4, 13)
  54. || test_reshape(a, 4, 13, 14)
  55. || test_reshape(a, 13, 14, 4)
  56. || test_reshape(a, 2, 7, -1)
  57. || test_reshape(a, -1, 13, 2)
  58. || test_reshape(a, -1, 4, -233)
  59. || test_reshape(a, 8, -1, -233)
  60. || test_reshape(a, 8, 91, -233)
  61. || test_reshape(a, -1, -233, -233)
  62. ;
  63. }
  64. static int test_reshape_2()
  65. {
  66. ncnn::Mat a = RandomMat(14, 16);
  67. return 0
  68. || test_reshape(a, 7, 2, 16)
  69. || test_reshape(a, 2, 16, 7)
  70. || test_reshape(a, 16, 7, 2)
  71. || test_reshape(a, 2, 4, -1)
  72. || test_reshape(a, -1, 8, 2)
  73. || test_reshape(a, 28, 8, -233)
  74. || test_reshape(a, -1, 7, -233)
  75. || test_reshape(a, 16, -1, -233)
  76. || test_reshape(a, -1, -233, -233)
  77. ;
  78. }
  79. static int test_reshape_3()
  80. {
  81. ncnn::Mat a = RandomMat(12, 14);
  82. return 0
  83. || test_reshape(a, 7, 2, 12)
  84. || test_reshape(a, 2, 12, 7)
  85. || test_reshape(a, 12, 7, 2)
  86. || test_reshape(a, 2, 4, -1)
  87. || test_reshape(a, -1, 4, 2)
  88. || test_reshape(a, 21, 8, -233)
  89. || test_reshape(a, -1, 7, -233)
  90. || test_reshape(a, 3, -1, -233)
  91. || test_reshape(a, -1, -233, -233)
  92. ;
  93. }
  94. static int test_reshape_4()
  95. {
  96. ncnn::Mat a = RandomMat(120);
  97. return 0
  98. || test_reshape(a, 3, 5, 8)
  99. || test_reshape(a, 3, 8, 5)
  100. || test_reshape(a, 8, 5, 3)
  101. || test_reshape(a, 2, 5, -1)
  102. || test_reshape(a, -1, 5, 2)
  103. || test_reshape(a, 4, 30, -233)
  104. || test_reshape(a, -1, 2, -233)
  105. || test_reshape(a, 24, -1, -233)
  106. || test_reshape(a, -1, -233, -233)
  107. ;
  108. }
  109. static int test_reshape_5()
  110. {
  111. ncnn::Mat a = RandomMat(210);
  112. return 0
  113. || test_reshape(a, 3, 5, 14)
  114. || test_reshape(a, 3, 14, 5)
  115. || test_reshape(a, 14, 5, 3)
  116. || test_reshape(a, 2, 5, -1)
  117. || test_reshape(a, -1, 5, 2)
  118. || test_reshape(a, 6, 35, -233)
  119. || test_reshape(a, -1, 7, -233)
  120. || test_reshape(a, 21, -1, -233)
  121. || test_reshape(a, -1, -233, -233)
  122. ;
  123. }
  124. int main()
  125. {
  126. SRAND(7767517);
  127. return 0
  128. || test_reshape_0()
  129. || test_reshape_1()
  130. || test_reshape_2()
  131. || test_reshape_3()
  132. || test_reshape_4()
  133. || test_reshape_5()
  134. ;
  135. }