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_oom.cpp 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Tencent is pleased to support the open source community by making ncnn available.
  2. //
  3. // Copyright (C) 2025 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. static int test_layer_oom(const ncnn::Mat& a, int outw, int outh, int outd, int outc)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(0, outw); // w
  19. pd.set(1, outh); // h
  20. pd.set(11, outd); // d
  21. pd.set(2, outc); // c
  22. std::vector<ncnn::Mat> weights(0);
  23. int ret = test_layer_oom("Reshape", pd, weights, a);
  24. if (ret != 0)
  25. {
  26. fprintf(stderr, "test_layer_oom failed a.dims=%d a=(%d %d %d %d) outw=%d outh=%d outd=%d outc=%d\n", a.dims, a.w, a.h, a.d, a.c, outw, outh, outd, outc);
  27. }
  28. return ret;
  29. }
  30. static int test_reshape_0()
  31. {
  32. ncnn::Mat a = RandomMat(3, 8, 5, 32);
  33. return 0
  34. || test_layer_oom(a, 5, 8, 3, 32)
  35. || test_layer_oom(a, 3, 8, 32, 5)
  36. || test_layer_oom(a, 32, 5, 8, 3)
  37. || test_layer_oom(a, 4, 3, 16, -1)
  38. || test_layer_oom(a, 6, 16, -1, 2)
  39. || test_layer_oom(a, 4, -1, 8, 8)
  40. || test_layer_oom(a, -1, 16, 6, 2)
  41. || test_layer_oom(a, 16, 6, -233, -1)
  42. || test_layer_oom(a, 8, -1, -233, 8)
  43. || test_layer_oom(a, -1, 6, -233, 16)
  44. || test_layer_oom(a, 8, -1, -233, -233)
  45. || test_layer_oom(a, -1, 6, -233, -233)
  46. || test_layer_oom(a, -1, -233, -233, -233);
  47. }
  48. static int test_reshape_1()
  49. {
  50. ncnn::Mat a = RandomMat(6, 7, 32);
  51. return 0
  52. || test_layer_oom(a, 6, 8, 4, 7)
  53. || test_layer_oom(a, 2, 6, 7, 16)
  54. || test_layer_oom(a, 7, 6, -233, 32)
  55. || test_layer_oom(a, 6, 32, -233, 7)
  56. || test_layer_oom(a, 32, 7, -233, 6)
  57. || test_layer_oom(a, 2, 6, -233, -1)
  58. || test_layer_oom(a, -1, 8, -233, 2)
  59. || test_layer_oom(a, -1, 4, -233, -233)
  60. || test_layer_oom(a, 8, -1, -233, -233)
  61. || test_layer_oom(a, 32, 42, -233, -233)
  62. || test_layer_oom(a, -1, -233, -233, -233);
  63. }
  64. static int test_reshape_2()
  65. {
  66. ncnn::Mat a = RandomMat(14, 32);
  67. return 0
  68. || test_layer_oom(a, 2, 7, 2, 16)
  69. || test_layer_oom(a, 16, 1, 7, 4)
  70. || test_layer_oom(a, 7, 2, -233, 32)
  71. || test_layer_oom(a, 4, 16, -233, 7)
  72. || test_layer_oom(a, 16, 14, -233, 2)
  73. || test_layer_oom(a, 2, 4, -233, -1)
  74. || test_layer_oom(a, -1, 8, -233, 2)
  75. || test_layer_oom(a, 28, 16, -233, -233)
  76. || test_layer_oom(a, -1, 14, -233, -233)
  77. || test_layer_oom(a, 16, -1, -233, -233)
  78. || test_layer_oom(a, -1, -233, -233, -233);
  79. }
  80. static int test_reshape_3()
  81. {
  82. ncnn::Mat a = RandomMat(240);
  83. return 0
  84. || test_layer_oom(a, 1, 1, 1, 240)
  85. || test_layer_oom(a, 10, 1, 1, 24)
  86. || test_layer_oom(a, 3, 5, -233, 16)
  87. || test_layer_oom(a, 3, 8, -233, 10)
  88. || test_layer_oom(a, 8, 5, -233, 6)
  89. || test_layer_oom(a, 2, 5, -233, -1)
  90. || test_layer_oom(a, -1, 5, -233, 4)
  91. || test_layer_oom(a, 8, 30, -233, -233)
  92. || test_layer_oom(a, -1, 2, -233, -233)
  93. || test_layer_oom(a, 24, -1, -233, -233)
  94. || test_layer_oom(a, -1, -233, -233, -233);
  95. }
  96. int main()
  97. {
  98. SRAND(7767517);
  99. return 0
  100. || test_reshape_0()
  101. || test_reshape_1()
  102. || test_reshape_2()
  103. || test_reshape_3();
  104. }