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_flip.cpp 3.8 kB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "layer.h"
  15. #include "testutil.h"
  16. // 为兼容低于c++11
  17. // ncnn::Mat axis_mat(axis.size());
  18. // for (size_t i = 0; i < axis.size(); i++)
  19. // {
  20. // axis_mat[i] = axis[i];
  21. // }
  22. static ncnn::Mat IntArrayMat(int a0)
  23. {
  24. ncnn::Mat m(1);
  25. int* p = m;
  26. p[0] = a0;
  27. return m;
  28. }
  29. static ncnn::Mat IntArrayMat(int a0, int a1)
  30. {
  31. ncnn::Mat m(2);
  32. int* p = m;
  33. p[0] = a0;
  34. p[1] = a1;
  35. return m;
  36. }
  37. static ncnn::Mat IntArrayMat(int a0, int a1, int a2)
  38. {
  39. ncnn::Mat m(3);
  40. int* p = m;
  41. p[0] = a0;
  42. p[1] = a1;
  43. p[2] = a2;
  44. return m;
  45. }
  46. static ncnn::Mat IntArrayMat(int a0, int a1, int a2, int a3)
  47. {
  48. ncnn::Mat m(4);
  49. int* p = m;
  50. p[0] = a0;
  51. p[1] = a1;
  52. p[2] = a2;
  53. p[3] = a3;
  54. return m;
  55. }
  56. static int test_flip(const ncnn::Mat& a, const ncnn::Mat& axis)
  57. {
  58. ncnn::ParamDict pd;
  59. pd.set(0, axis);
  60. std::vector<ncnn::Mat> weights(0);
  61. int ret = test_layer("Flip", pd, weights, a);
  62. if (ret != 0)
  63. {
  64. fprintf(stderr, "test_flip failed a.dims=%d a=(%d %d %d %d) axis_w=%d\n", a.dims, a.w, a.h, a.d, a.c, axis.w);
  65. }
  66. return ret;
  67. }
  68. static int test_flip_0()
  69. {
  70. return 0
  71. || test_flip(RandomMat(2, 3, 4, 5), IntArrayMat(0))
  72. || test_flip(RandomMat(3, 2, 4, 5), IntArrayMat(1))
  73. || test_flip(RandomMat(4, 3, 2, 5), IntArrayMat(2))
  74. || test_flip(RandomMat(2, 3, 1, 5), IntArrayMat(3))
  75. || test_flip(RandomMat(6, 3, 4, 5), IntArrayMat(0, 1))
  76. || test_flip(RandomMat(2, 3, 1, 6), IntArrayMat(0, 2))
  77. || test_flip(RandomMat(5, 1, 2, 5), IntArrayMat(0, 3))
  78. || test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(1, 2))
  79. || test_flip(RandomMat(4, 5, 2, 3), IntArrayMat(1, 3))
  80. || test_flip(RandomMat(2, 6, 4, 5), IntArrayMat(2, 3))
  81. || test_flip(RandomMat(6, 1, 4, 5), IntArrayMat(0, 1, 2))
  82. || test_flip(RandomMat(5, 2, 1, 5), IntArrayMat(0, 1, 3))
  83. || test_flip(RandomMat(4, 3, 3, 5), IntArrayMat(0, 2, 3))
  84. || test_flip(RandomMat(4, 3, 4, 5), IntArrayMat(1, 2, 3))
  85. || test_flip(RandomMat(6, 3, 3, 2), IntArrayMat(0, 1, 2, 3));
  86. }
  87. static int test_flip_1()
  88. {
  89. return 0
  90. || test_flip(RandomMat(2, 3, 5), IntArrayMat(0))
  91. || test_flip(RandomMat(3, 3, 5), IntArrayMat(1))
  92. || test_flip(RandomMat(4, 3, 5), IntArrayMat(2))
  93. || test_flip(RandomMat(3, 1, 5), IntArrayMat(0, 1))
  94. || test_flip(RandomMat(3, 2, 5), IntArrayMat(0, 2))
  95. || test_flip(RandomMat(3, 3, 4), IntArrayMat(1, 2))
  96. || test_flip(RandomMat(4, 3, 2), IntArrayMat(0, 1, 2));
  97. }
  98. static int test_flip_2()
  99. {
  100. return 0
  101. || test_flip(RandomMat(8, 2), IntArrayMat(-2))
  102. || test_flip(RandomMat(16, 3), IntArrayMat(-1))
  103. || test_flip(RandomMat(7, 2), IntArrayMat(-2, -1));
  104. }
  105. static int test_flip_3()
  106. {
  107. return 0
  108. || test_flip(RandomMat(18), IntArrayMat(-1));
  109. }
  110. int main()
  111. {
  112. SRAND(7767517);
  113. return 0
  114. || test_flip_0()
  115. || test_flip_1()
  116. || test_flip_2()
  117. || test_flip_3();
  118. }