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.

roi_pooling.h 1.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * \file dnn/test/common/roi_pooling.h
  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 "megdnn/oprs.h"
  12. #include "test/common/random_state.h"
  13. #include "test/common/rng.h"
  14. namespace megdnn {
  15. namespace test {
  16. class ROIPoolingRNG final : public IIDRNG {
  17. public:
  18. ROIPoolingRNG(size_t n) : n(n), idx(0) {}
  19. dt_float32 gen_single_val() override {
  20. std::uniform_real_distribution<dt_float32> distf(0.0f, 1.0f);
  21. std::uniform_int_distribution<int> disti(0, n - 1);
  22. dt_float32 res;
  23. if (idx == 0) {
  24. res = static_cast<dt_float32>(disti(RandomState::generator()));
  25. }
  26. if (idx == 1 || idx == 2) {
  27. res = distf(RandomState::generator()) * 0.5;
  28. } else {
  29. res = distf(RandomState::generator()) * 0.5 + 0.5;
  30. }
  31. idx = (idx + 1) % 5;
  32. return res;
  33. }
  34. private:
  35. size_t n;
  36. size_t idx;
  37. };
  38. } // namespace test
  39. } // namespace megdnn
  40. // vim: syntax=cpp.doxygen