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 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2025 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_layer_oom(const ncnn::Mat& a, int outw, int outh, int outd, int outc)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, outw); // w
  8. pd.set(1, outh); // h
  9. pd.set(11, outd); // d
  10. pd.set(2, outc); // c
  11. std::vector<ncnn::Mat> weights(0);
  12. int ret = test_layer_oom("Reshape", pd, weights, a);
  13. if (ret != 0)
  14. {
  15. 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);
  16. }
  17. return ret;
  18. }
  19. static int test_reshape_0()
  20. {
  21. ncnn::Mat a = RandomMat(3, 8, 5, 32);
  22. return 0
  23. || test_layer_oom(a, 5, 8, 3, 32)
  24. || test_layer_oom(a, 3, 8, 32, 5)
  25. || test_layer_oom(a, 32, 5, 8, 3)
  26. || test_layer_oom(a, 4, 3, 16, -1)
  27. || test_layer_oom(a, 6, 16, -1, 2)
  28. || test_layer_oom(a, 4, -1, 8, 8)
  29. || test_layer_oom(a, -1, 16, 6, 2)
  30. || test_layer_oom(a, 16, 6, -233, -1)
  31. || test_layer_oom(a, 8, -1, -233, 8)
  32. || test_layer_oom(a, -1, 6, -233, 16)
  33. || test_layer_oom(a, 8, -1, -233, -233)
  34. || test_layer_oom(a, -1, 6, -233, -233)
  35. || test_layer_oom(a, -1, -233, -233, -233);
  36. }
  37. static int test_reshape_1()
  38. {
  39. ncnn::Mat a = RandomMat(6, 7, 32);
  40. return 0
  41. || test_layer_oom(a, 6, 8, 4, 7)
  42. || test_layer_oom(a, 2, 6, 7, 16)
  43. || test_layer_oom(a, 7, 6, -233, 32)
  44. || test_layer_oom(a, 6, 32, -233, 7)
  45. || test_layer_oom(a, 32, 7, -233, 6)
  46. || test_layer_oom(a, 2, 6, -233, -1)
  47. || test_layer_oom(a, -1, 8, -233, 2)
  48. || test_layer_oom(a, -1, 4, -233, -233)
  49. || test_layer_oom(a, 8, -1, -233, -233)
  50. || test_layer_oom(a, 32, 42, -233, -233)
  51. || test_layer_oom(a, -1, -233, -233, -233);
  52. }
  53. static int test_reshape_2()
  54. {
  55. ncnn::Mat a = RandomMat(14, 32);
  56. return 0
  57. || test_layer_oom(a, 2, 7, 2, 16)
  58. || test_layer_oom(a, 16, 1, 7, 4)
  59. || test_layer_oom(a, 7, 2, -233, 32)
  60. || test_layer_oom(a, 4, 16, -233, 7)
  61. || test_layer_oom(a, 16, 14, -233, 2)
  62. || test_layer_oom(a, 2, 4, -233, -1)
  63. || test_layer_oom(a, -1, 8, -233, 2)
  64. || test_layer_oom(a, 28, 16, -233, -233)
  65. || test_layer_oom(a, -1, 14, -233, -233)
  66. || test_layer_oom(a, 16, -1, -233, -233)
  67. || test_layer_oom(a, -1, -233, -233, -233);
  68. }
  69. static int test_reshape_3()
  70. {
  71. ncnn::Mat a = RandomMat(240);
  72. return 0
  73. || test_layer_oom(a, 1, 1, 1, 240)
  74. || test_layer_oom(a, 10, 1, 1, 24)
  75. || test_layer_oom(a, 3, 5, -233, 16)
  76. || test_layer_oom(a, 3, 8, -233, 10)
  77. || test_layer_oom(a, 8, 5, -233, 6)
  78. || test_layer_oom(a, 2, 5, -233, -1)
  79. || test_layer_oom(a, -1, 5, -233, 4)
  80. || test_layer_oom(a, 8, 30, -233, -233)
  81. || test_layer_oom(a, -1, 2, -233, -233)
  82. || test_layer_oom(a, 24, -1, -233, -233)
  83. || test_layer_oom(a, -1, -233, -233, -233);
  84. }
  85. int main()
  86. {
  87. SRAND(7767517);
  88. return 0
  89. || test_reshape_0()
  90. || test_reshape_1()
  91. || test_reshape_2()
  92. || test_reshape_3();
  93. }