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_diag.cpp 937 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2023 Tencent
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "testutil.h"
  4. static int test_diag(const ncnn::Mat& a, int diagonal)
  5. {
  6. ncnn::ParamDict pd;
  7. pd.set(0, diagonal);
  8. std::vector<ncnn::Mat> weights(0);
  9. int ret = test_layer("Diag", pd, weights, a);
  10. if (ret != 0)
  11. {
  12. fprintf(stderr, "test_diag failed a.dims=%d a=(%d %d %d %d)\n", a.dims, a.w, a.h, a.d, a.c);
  13. }
  14. return ret;
  15. }
  16. static int test_diag_0()
  17. {
  18. return 0
  19. || test_diag(RandomMat(5, 24), 3)
  20. || test_diag(RandomMat(7, 12), 0)
  21. || test_diag(RandomMat(6, 6), -4)
  22. || test_diag(RandomMat(3, 4), -6);
  23. }
  24. static int test_diag_1()
  25. {
  26. return 0
  27. || test_diag(RandomMat(5), -1)
  28. || test_diag(RandomMat(7), 0)
  29. || test_diag(RandomMat(3), 2);
  30. }
  31. int main()
  32. {
  33. SRAND(7767517);
  34. return 0
  35. || test_diag_0()
  36. || test_diag_1();
  37. }