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_hardsigmoid.cpp 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2020 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_hardsigmoid(const ncnn::Mat& a, float alpha, float beta)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, alpha);
  8. pd.set(0, beta);
  9. std::vector<ncnn::Mat> weights(0);
  10. int ret = test_layer("HardSigmoid", pd, weights, a);
  11. if (ret != 0)
  12. {
  13. fprintf(stderr, "test_hardsigmoid failed a.dims=%d a=(%d %d %d) alpha=%f beta=%f\n", a.dims, a.w, a.h, a.c, alpha, beta);
  14. }
  15. return ret;
  16. }
  17. static int test_hardsigmoid_0()
  18. {
  19. return 0
  20. || test_hardsigmoid(RandomMat(5, 7, 24), 0.5f, 0.5f)
  21. || test_hardsigmoid(RandomMat(7, 9, 12), 0.5f, 0.5f)
  22. || test_hardsigmoid(RandomMat(3, 5, 13), 0.5f, 0.5f);
  23. }
  24. static int test_hardsigmoid_1()
  25. {
  26. return 0
  27. || test_hardsigmoid(RandomMat(15, 24), 0.5f, 0.5f)
  28. || test_hardsigmoid(RandomMat(17, 12), 0.5f, 0.5f)
  29. || test_hardsigmoid(RandomMat(19, 15), 0.5f, 0.5f);
  30. }
  31. static int test_hardsigmoid_2()
  32. {
  33. return 0
  34. || test_hardsigmoid(RandomMat(128), 0.5f, 0.5f)
  35. || test_hardsigmoid(RandomMat(124), 0.5f, 0.5f)
  36. || test_hardsigmoid(RandomMat(127), 0.5f, 0.5f);
  37. }
  38. int main()
  39. {
  40. SRAND(7767517);
  41. return 0
  42. || test_hardsigmoid_0()
  43. || test_hardsigmoid_1()
  44. || test_hardsigmoid_2();
  45. }