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_selu.cpp 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2021 Xavier Hsinyuan <me@lstlx.com>
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_selu(const ncnn::Mat& a, float alpha, float lambda)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, alpha);
  8. pd.set(1, lambda);
  9. std::vector<ncnn::Mat> weights(0);
  10. int ret = test_layer("SELU", pd, weights, a);
  11. if (ret != 0)
  12. {
  13. fprintf(stderr, "test_selu failed a.dims=%d a=(%d %d %d %d) alpha=%f lambda=%f\n", a.dims, a.w, a.h, a.d, a.c, alpha, lambda);
  14. }
  15. return ret;
  16. }
  17. static int test_selu_0()
  18. {
  19. return 0
  20. || test_selu(RandomMat(7, 6, 5, 32), 1.673264f, 1.050700f)
  21. || test_selu(RandomMat(5, 6, 7, 24), 1.673264f, 1.050700f)
  22. || test_selu(RandomMat(7, 8, 9, 12), 1.673264f, 1.050700f)
  23. || test_selu(RandomMat(3, 4, 5, 13), 1.673264f, 1.050700f);
  24. }
  25. static int test_selu_1()
  26. {
  27. return 0
  28. || test_selu(RandomMat(4, 7, 32), 1.673264f, 1.050700f)
  29. || test_selu(RandomMat(5, 7, 24), 1.673264f, 1.050700f)
  30. || test_selu(RandomMat(7, 9, 12), 1.673264f, 1.050700f)
  31. || test_selu(RandomMat(3, 5, 13), 1.673264f, 1.050700f);
  32. }
  33. static int test_selu_2()
  34. {
  35. return 0
  36. || test_selu(RandomMat(13, 32), 1.673264f, 1.050700f)
  37. || test_selu(RandomMat(15, 24), 1.673264f, 1.050700f)
  38. || test_selu(RandomMat(17, 12), 1.673264f, 1.050700f)
  39. || test_selu(RandomMat(19, 15), 1.673264f, 1.050700f);
  40. }
  41. static int test_selu_3()
  42. {
  43. return 0
  44. || test_selu(RandomMat(128), 1.673264f, 1.050700f)
  45. || test_selu(RandomMat(124), 1.673264f, 1.050700f)
  46. || test_selu(RandomMat(127), 1.673264f, 1.050700f)
  47. || test_selu(RandomMat(120), 1.673264f, 1.050700f);
  48. }
  49. int main()
  50. {
  51. SRAND(7767517);
  52. return 0
  53. || test_selu_0()
  54. || test_selu_1()
  55. || test_selu_2()
  56. || test_selu_3();
  57. }