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_clip.cpp 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2019 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_clip(const ncnn::Mat& a, float min, float max)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, min);
  8. pd.set(1, max);
  9. std::vector<ncnn::Mat> weights(0);
  10. int ret = test_layer("Clip", pd, weights, a);
  11. if (ret != 0)
  12. {
  13. fprintf(stderr, "test_clip failed a.dims=%d a=(%d %d %d %d) min=%f max=%f\n", a.dims, a.w, a.h, a.d, a.c, min, max);
  14. }
  15. return ret;
  16. }
  17. static int test_clip_0()
  18. {
  19. return 0
  20. || test_clip(RandomMat(5, 6, 7, 24), -1.f, 1.f)
  21. || test_clip(RandomMat(7, 8, 9, 12), -1.f, 1.f)
  22. || test_clip(RandomMat(3, 4, 5, 13), -1.f, 1.f);
  23. }
  24. static int test_clip_1()
  25. {
  26. return 0
  27. || test_clip(RandomMat(5, 7, 24), -1.f, 1.f)
  28. || test_clip(RandomMat(7, 9, 12), -1.f, 1.f)
  29. || test_clip(RandomMat(3, 5, 13), -1.f, 1.f);
  30. }
  31. static int test_clip_2()
  32. {
  33. return 0
  34. || test_clip(RandomMat(15, 24), -1.f, 1.f)
  35. || test_clip(RandomMat(17, 12), -1.f, 1.f)
  36. || test_clip(RandomMat(19, 15), -1.f, 1.f);
  37. }
  38. static int test_clip_3()
  39. {
  40. return 0
  41. || test_clip(RandomMat(128), -1.f, 1.f)
  42. || test_clip(RandomMat(124), -1.f, 1.f)
  43. || test_clip(RandomMat(127), -1.f, 1.f);
  44. }
  45. int main()
  46. {
  47. SRAND(7767517);
  48. return 0
  49. || test_clip_0()
  50. || test_clip_1()
  51. || test_clip_2()
  52. || test_clip_3();
  53. }