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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #define OP_TYPE_MAX 20
  16. static int op_type = 0;
  17. static int test_unaryop(const ncnn::Mat& _a)
  18. {
  19. ncnn::Mat a = _a;
  20. if (op_type == 2 || op_type == 3)
  21. {
  22. // large dynamic range for floor ceil
  23. for (int i = 0; i < a.total(); i++)
  24. {
  25. a[i] *= 1000;
  26. }
  27. }
  28. if (op_type == 5 || op_type == 6 || op_type == 8 || op_type == 17)
  29. {
  30. // value must be positive for sqrt rsqrt log
  31. Randomize(a, 0.001f, 2.f);
  32. }
  33. if (op_type == 11 || op_type == 12 || op_type == 13)
  34. {
  35. // smaller range for tan asin acos
  36. Randomize(a, -1.f, 1.f);
  37. }
  38. ncnn::ParamDict pd;
  39. pd.set(0, op_type);
  40. std::vector<ncnn::Mat> weights(0);
  41. int ret = test_layer("UnaryOp", pd, weights, a);
  42. if (ret != 0)
  43. {
  44. fprintf(stderr, "test_unaryop failed a.dims=%d a=(%d %d %d %d) op_type=%d\n", a.dims, a.w, a.h, a.d, a.c, op_type);
  45. }
  46. return ret;
  47. }
  48. static int test_unaryop_0()
  49. {
  50. return 0
  51. || test_unaryop(RandomMat(11, 3, 2, 16))
  52. || test_unaryop(RandomMat(10, 2, 2, 12))
  53. || test_unaryop(RandomMat(6, 1, 5, 13));
  54. }
  55. static int test_unaryop_1()
  56. {
  57. return 0
  58. || test_unaryop(RandomMat(11, 7, 16))
  59. || test_unaryop(RandomMat(10, 4, 12))
  60. || test_unaryop(RandomMat(6, 5, 13));
  61. }
  62. static int test_unaryop_2()
  63. {
  64. return 0
  65. || test_unaryop(RandomMat(12, 16))
  66. || test_unaryop(RandomMat(10, 12))
  67. || test_unaryop(RandomMat(14, 15));
  68. }
  69. static int test_unaryop_3()
  70. {
  71. return 0
  72. || test_unaryop(RandomMat(128))
  73. || test_unaryop(RandomMat(12))
  74. || test_unaryop(RandomMat(15));
  75. }
  76. int main()
  77. {
  78. SRAND(7767517);
  79. for (op_type = 0; op_type < OP_TYPE_MAX; op_type++)
  80. {
  81. int ret = 0
  82. || test_unaryop_0()
  83. || test_unaryop_1()
  84. || test_unaryop_2()
  85. || test_unaryop_3();
  86. if (ret != 0)
  87. return ret;
  88. }
  89. return 0;
  90. }