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_1.cpp 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2025 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_reshape(const ncnn::Mat& a, const char* shape_expr)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(6, std::string(shape_expr));
  8. std::vector<ncnn::Mat> weights(0);
  9. int ret = test_layer("Reshape", pd, weights, a);
  10. if (ret != 0)
  11. {
  12. fprintf(stderr, "test_reshape failed a.dims=%d a=(%d %d %d %d) shape_expr=%s\n", a.dims, a.w, a.h, a.d, a.c, shape_expr);
  13. }
  14. return ret;
  15. }
  16. static int test_reshape(const std::vector<ncnn::Mat>& as, const char* shape_expr)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(6, std::string(shape_expr));
  20. std::vector<ncnn::Mat> weights(0);
  21. int ret = test_layer("Reshape", pd, weights, as, 1);
  22. if (ret != 0)
  23. {
  24. fprintf(stderr, "test_reshape failed a.dims=%d a=(%d %d %d %d) shape_expr=%s\n", as[0].dims, as[0].w, as[0].h, as[0].d, as[0].c, shape_expr);
  25. }
  26. return ret;
  27. }
  28. static int test_reshape_0()
  29. {
  30. ncnn::Mat a = RandomMat(3, 2, 25, 32);
  31. return 0
  32. || test_reshape(a, "0w,0h,*(0d,2),-1")
  33. || test_reshape(a, "-1,0w,5,4")
  34. || test_reshape(a, "-1,square(neg(abs(max(min(//(*(-(+(0w,1),-1),4),4),100),-4))))")
  35. || test_reshape(a, "-1,square(neg(abs(max(min(//(*(-(+(0w,1.0),-1.0),2.0),2.0),100.3),-2.2))))")
  36. || test_reshape(a, "-1,trunc(*(round(-(floor(+(ceil(*(0w,1.2)),0.7)),-0.4)),1.0001))")
  37. || test_reshape(a, "-1,ceil(sqrt(square(*(asinh(sinh(atanh(tanh(atan(tan(acos(cos(asin(sin(/(0w,2))))))))))),16))))");
  38. }
  39. static int test_reshape_1()
  40. {
  41. std::vector<ncnn::Mat> as(2);
  42. as[0] = RandomMat(14, 15, 16);
  43. as[1] = RandomMat(28, 45, 48);
  44. return 0
  45. || test_reshape(as, "*(1w,0.5),/(1h,3),-(1c,32)")
  46. || test_reshape(as, "*(0w,0h),-(-(1c,0c),16)");
  47. }
  48. static int test_reshape_2()
  49. {
  50. ncnn::Mat a = RandomMat(14, 15, 16);
  51. return 0
  52. || test_reshape(a, "*(0w,0.5),/(0h,3),-1")
  53. || test_reshape(a, "-1")
  54. || test_reshape(a, "*(0w,0h),0c");
  55. }
  56. int main()
  57. {
  58. SRAND(7767517);
  59. return 0
  60. || test_reshape_0()
  61. || test_reshape_1()
  62. || test_reshape_2();
  63. }