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.

diag.cpp 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * \file dnn/test/cuda/diag.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "test/cuda/fixture.h"
  12. #include "megdnn/oprs.h"
  13. #include "test/common/checker.h"
  14. namespace megdnn {
  15. namespace test {
  16. TEST_F(CUDA, DIAG) {
  17. Checker<Diag> checker(handle_cuda());
  18. for (DType dtype :
  19. std::vector<DType>{dtype::Float16(), dtype::Int32(), dtype::Float32()})
  20. for (int k = -5; k < 5; ++k) {
  21. checker.set_param({k});
  22. checker.set_dtype(0, dtype);
  23. checker.set_dtype(1, dtype);
  24. size_t absk = static_cast<size_t>(std::abs(k));
  25. checker.exec(TensorShapeArray{{8}, {8 + absk, 8 + absk}});
  26. auto oshape = [&](int n, int m) -> TensorShape {
  27. size_t o = (k >= 0 ? std::min(n - k, m) : std::min(m + k, n));
  28. return {o, o};
  29. };
  30. checker.exec(TensorShapeArray{{8, 6}, oshape(8, 6)});
  31. checker.exec(TensorShapeArray{{6, 8}, oshape(6, 8)});
  32. checker.exec(TensorShapeArray{{8, 8}, oshape(8, 8)});
  33. }
  34. }
  35. } // namespace test
  36. } // namespace megdnn
  37. // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}