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

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