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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_reshape(const ncnn::Mat& a, const char* shape_expr)
  16. {
  17. ncnn::ParamDict pd;
  18. pd.set(6, std::string(shape_expr));
  19. std::vector<ncnn::Mat> weights(0);
  20. int ret = test_layer("Reshape", pd, weights, a);
  21. if (ret != 0)
  22. {
  23. 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);
  24. }
  25. return ret;
  26. }
  27. static int test_reshape(const std::vector<ncnn::Mat>& as, const char* shape_expr)
  28. {
  29. ncnn::ParamDict pd;
  30. pd.set(6, std::string(shape_expr));
  31. std::vector<ncnn::Mat> weights(0);
  32. int ret = test_layer("Reshape", pd, weights, as, 1);
  33. if (ret != 0)
  34. {
  35. 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);
  36. }
  37. return ret;
  38. }
  39. static int test_reshape_0()
  40. {
  41. ncnn::Mat a = RandomMat(3, 2, 25, 32);
  42. return 0
  43. || test_reshape(a, "0w,0h,*(0d,2),-1")
  44. || test_reshape(a, "-1,0w,5,4")
  45. || test_reshape(a, "-1,square(neg(abs(max(min(//(*(-(+(0w,1),-1),4),4),100),-4))))")
  46. || test_reshape(a, "-1,square(neg(abs(max(min(//(*(-(+(0w,1.0),-1.0),2.0),2.0),100.3),-2.2)))")
  47. || test_reshape(a, "-1,trunc(*(round(-(floor(+(ceil(*(0w,1.2)),0.7)),-0.4)),1.0001))")
  48. || test_reshape(a, "-1,ceil(sqrt(square(*(asinh(sinh(atanh(tanh(atan(tan(acos(cos(asin(sin(/(0w,2))))))))))),16))))");
  49. }
  50. static int test_reshape_1()
  51. {
  52. std::vector<ncnn::Mat> as(2);
  53. as[0] = RandomMat(14, 15, 16);
  54. as[1] = RandomMat(28, 45, 48);
  55. return 0
  56. || test_reshape(as, "*(1w,0.5),/(1h,3),-(1c,32)")
  57. || test_reshape(as, "*(0w,0h),-(-(1c,0c),16)");
  58. }
  59. static int test_reshape_2()
  60. {
  61. ncnn::Mat a = RandomMat(14, 15, 16);
  62. return 0
  63. || test_reshape(a, "*(0w,0.5),/(0h,3),-1")
  64. || test_reshape(a, "-1")
  65. || test_reshape(a, "*(0w,0h),0c");
  66. }
  67. int main()
  68. {
  69. SRAND(7767517);
  70. return 0
  71. || test_reshape_0()
  72. || test_reshape_1()
  73. || test_reshape_2();
  74. }