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_permute.cpp 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/permute.h"
  16. static int test_permute(const ncnn::Mat& a, int order_type)
  17. {
  18. ncnn::ParamDict pd;
  19. pd.set(0, order_type);
  20. std::vector<ncnn::Mat> weights(0);
  21. ncnn::Option opt;
  22. opt.num_threads = 1;
  23. opt.use_vulkan_compute = true;
  24. opt.use_int8_inference = false;
  25. int ret = test_layer<ncnn::Permute>("Permute", pd, weights, opt, a);
  26. if (ret != 0)
  27. {
  28. fprintf(stderr, "test_permute failed a.dims=%d a=(%d %d %d) order_type=%d\n", a.dims, a.w, a.h, a.c, order_type);
  29. }
  30. return ret;
  31. }
  32. static int test_permute_0()
  33. {
  34. ncnn::Mat a = RandomMat(128);
  35. ncnn::Mat b = RandomMat(127);
  36. return 0
  37. || test_permute(a, 0)
  38. || test_permute(b, 0)
  39. ;
  40. }
  41. static int test_permute_1()
  42. {
  43. ncnn::Mat a = RandomMat(12, 32);
  44. ncnn::Mat b = RandomMat(8, 15);
  45. ncnn::Mat c = RandomMat(11, 16);
  46. ncnn::Mat d = RandomMat(7, 9);
  47. for (int order_type=0; order_type<2; order_type++)
  48. {
  49. int ret = 0
  50. || test_permute(a, order_type)
  51. || test_permute(b, order_type)
  52. || test_permute(c, order_type)
  53. || test_permute(d, order_type)
  54. ;
  55. if (ret != 0)
  56. return -1;
  57. }
  58. return 0;
  59. }
  60. static int test_permute_2()
  61. {
  62. ncnn::Mat a = RandomMat(8, 16, 32);
  63. ncnn::Mat b = RandomMat(12, 8, 16);
  64. ncnn::Mat c = RandomMat(7, 14, 12);
  65. ncnn::Mat d = RandomMat(4, 4, 13);
  66. ncnn::Mat e = RandomMat(1, 2, 7);
  67. ncnn::Mat f = RandomMat(8, 5, 6);
  68. for (int order_type=0; order_type<6; order_type++)
  69. {
  70. int ret = 0
  71. || test_permute(a, order_type)
  72. || test_permute(b, order_type)
  73. || test_permute(c, order_type)
  74. || test_permute(d, order_type)
  75. || test_permute(e, order_type)
  76. || test_permute(f, order_type)
  77. ;
  78. if (ret != 0)
  79. return -1;
  80. }
  81. return 0;
  82. }
  83. int main()
  84. {
  85. SRAND(7767517);
  86. return 0
  87. || test_permute_0()
  88. || test_permute_1()
  89. || test_permute_2()
  90. ;
  91. }