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.9 kB

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