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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. opt.use_fp16_packed = false;
  28. opt.use_fp16_storage = false;
  29. opt.use_fp16_arithmetic = false;
  30. opt.use_int8_storage = false;
  31. opt.use_int8_arithmetic = false;
  32. int ret = test_layer<ncnn::Reshape>("Reshape", pd, weights, opt, a);
  33. if (ret != 0)
  34. {
  35. 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);
  36. }
  37. return ret;
  38. }
  39. static int test_reshape_0()
  40. {
  41. ncnn::Mat a = RandomMat(3, 7, 16);
  42. return 0
  43. || test_reshape(a, 7, 3, 16)
  44. || test_reshape(a, 3, 16, 7)
  45. || test_reshape(a, 16, 7, 3)
  46. || test_reshape(a, 2, 3, -1)
  47. || test_reshape(a, -1, 8, 2)
  48. || test_reshape(a, -1, 4, -233)
  49. || test_reshape(a, 8, -1, -233)
  50. || test_reshape(a, 16, 21, -233)
  51. || test_reshape(a, -1, -233, -233)
  52. ;
  53. }
  54. static int test_reshape_1()
  55. {
  56. ncnn::Mat a = RandomMat(4, 14, 13);
  57. return 0
  58. || test_reshape(a, 14, 4, 13)
  59. || test_reshape(a, 4, 13, 14)
  60. || test_reshape(a, 13, 14, 4)
  61. || test_reshape(a, 2, 7, -1)
  62. || test_reshape(a, -1, 13, 2)
  63. || test_reshape(a, -1, 4, -233)
  64. || test_reshape(a, 8, -1, -233)
  65. || test_reshape(a, 8, 91, -233)
  66. || test_reshape(a, -1, -233, -233)
  67. ;
  68. }
  69. static int test_reshape_2()
  70. {
  71. ncnn::Mat a = RandomMat(14, 16);
  72. return 0
  73. || test_reshape(a, 7, 2, 16)
  74. || test_reshape(a, 2, 16, 7)
  75. || test_reshape(a, 16, 7, 2)
  76. || test_reshape(a, 2, 4, -1)
  77. || test_reshape(a, -1, 8, 2)
  78. || test_reshape(a, 28, 8, -233)
  79. || test_reshape(a, -1, 7, -233)
  80. || test_reshape(a, 16, -1, -233)
  81. || test_reshape(a, -1, -233, -233)
  82. ;
  83. }
  84. static int test_reshape_3()
  85. {
  86. ncnn::Mat a = RandomMat(12, 14);
  87. return 0
  88. || test_reshape(a, 7, 2, 12)
  89. || test_reshape(a, 2, 12, 7)
  90. || test_reshape(a, 12, 7, 2)
  91. || test_reshape(a, 2, 4, -1)
  92. || test_reshape(a, -1, 4, 2)
  93. || test_reshape(a, 21, 8, -233)
  94. || test_reshape(a, -1, 7, -233)
  95. || test_reshape(a, 3, -1, -233)
  96. || test_reshape(a, -1, -233, -233)
  97. ;
  98. }
  99. static int test_reshape_4()
  100. {
  101. ncnn::Mat a = RandomMat(120);
  102. return 0
  103. || test_reshape(a, 3, 5, 8)
  104. || test_reshape(a, 3, 8, 5)
  105. || test_reshape(a, 8, 5, 3)
  106. || test_reshape(a, 2, 5, -1)
  107. || test_reshape(a, -1, 5, 2)
  108. || test_reshape(a, 4, 30, -233)
  109. || test_reshape(a, -1, 2, -233)
  110. || test_reshape(a, 24, -1, -233)
  111. || test_reshape(a, -1, -233, -233)
  112. ;
  113. }
  114. static int test_reshape_5()
  115. {
  116. ncnn::Mat a = RandomMat(210);
  117. return 0
  118. || test_reshape(a, 3, 5, 14)
  119. || test_reshape(a, 3, 14, 5)
  120. || test_reshape(a, 14, 5, 3)
  121. || test_reshape(a, 2, 5, -1)
  122. || test_reshape(a, -1, 5, 2)
  123. || test_reshape(a, 6, 35, -233)
  124. || test_reshape(a, -1, 7, -233)
  125. || test_reshape(a, 21, -1, -233)
  126. || test_reshape(a, -1, -233, -233)
  127. ;
  128. }
  129. int main()
  130. {
  131. SRAND(7767517);
  132. return 0
  133. || test_reshape_0()
  134. || test_reshape_1()
  135. || test_reshape_2()
  136. || test_reshape_3()
  137. || test_reshape_4()
  138. || test_reshape_5()
  139. ;
  140. }