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_flatten.cpp 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_flatten(const ncnn::Mat& a)
  16. {
  17. ncnn::ParamDict pd;
  18. std::vector<ncnn::Mat> weights(0);
  19. int ret = test_layer("Flatten", pd, weights, a);
  20. if (ret != 0)
  21. {
  22. fprintf(stderr, "test_flatten failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
  23. }
  24. return ret;
  25. }
  26. static int test_flatten_0()
  27. {
  28. return 0
  29. || test_flatten(RandomMat(2, 3, 4, 4))
  30. || test_flatten(RandomMat(3, 5, 7, 8))
  31. || test_flatten(RandomMat(1, 1, 1, 16))
  32. || test_flatten(RandomMat(9, 10, 2, 16))
  33. || test_flatten(RandomMat(1, 7, 1, 1))
  34. || test_flatten(RandomMat(6, 6, 6, 15))
  35. || test_flatten(RandomMat(2, 4, 4))
  36. || test_flatten(RandomMat(3, 5, 8))
  37. || test_flatten(RandomMat(1, 1, 16))
  38. || test_flatten(RandomMat(9, 10, 16))
  39. || test_flatten(RandomMat(1, 7, 1))
  40. || test_flatten(RandomMat(6, 6, 15))
  41. || test_flatten(RandomMat(13, 13))
  42. || test_flatten(RandomMat(16, 16))
  43. || test_flatten(RandomMat(8, 12))
  44. || test_flatten(RandomMat(8, 2))
  45. || test_flatten(RandomMat(32))
  46. || test_flatten(RandomMat(17));
  47. }
  48. static int test_flatten_int8(const ncnn::Mat& a)
  49. {
  50. ncnn::ParamDict pd;
  51. std::vector<ncnn::Mat> weights(0);
  52. int flag = TEST_LAYER_DISABLE_AUTO_INPUT_CASTING | TEST_LAYER_DISABLE_GPU_TESTING;
  53. int ret = test_layer("Flatten", pd, weights, a, 0.001, 0, flag);
  54. if (ret != 0)
  55. {
  56. fprintf(stderr, "test_flatten_int8 failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
  57. }
  58. return ret;
  59. }
  60. static int test_flatten_1()
  61. {
  62. return 0
  63. || test_flatten_int8(RandomS8Mat(2, 3, 4, 4))
  64. || test_flatten_int8(RandomS8Mat(3, 5, 7, 8))
  65. || test_flatten_int8(RandomS8Mat(1, 1, 1, 16))
  66. || test_flatten_int8(RandomS8Mat(9, 10, 2, 16))
  67. || test_flatten_int8(RandomS8Mat(1, 7, 1, 1))
  68. || test_flatten_int8(RandomS8Mat(6, 6, 6, 15))
  69. || test_flatten_int8(RandomS8Mat(2, 4, 16))
  70. || test_flatten_int8(RandomS8Mat(3, 5, 32))
  71. || test_flatten_int8(RandomS8Mat(1, 1, 64))
  72. || test_flatten_int8(RandomS8Mat(9, 10, 64))
  73. || test_flatten_int8(RandomS8Mat(1, 7, 4))
  74. || test_flatten_int8(RandomS8Mat(6, 6, 70))
  75. || test_flatten_int8(RandomS8Mat(13, 52))
  76. || test_flatten_int8(RandomS8Mat(16, 64))
  77. || test_flatten_int8(RandomS8Mat(8, 48))
  78. || test_flatten_int8(RandomS8Mat(16, 11))
  79. || test_flatten_int8(RandomS8Mat(8, 8))
  80. || test_flatten_int8(RandomS8Mat(128))
  81. || test_flatten_int8(RandomS8Mat(127));
  82. }
  83. int main()
  84. {
  85. SRAND(7767517);
  86. return test_flatten_0() || test_flatten_1();
  87. }