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

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