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.

rng.h 865 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <cstddef>
  3. #include <utility>
  4. #include "megdnn/dtype/half.hpp"
  5. namespace half_float {
  6. static inline std::ostream& operator<<(std::ostream& stream, half v) {
  7. return stream << static_cast<float>(v);
  8. }
  9. } // namespace half_float
  10. namespace megdnn {
  11. namespace test {
  12. //! get mean and variance
  13. template <typename ctype>
  14. std::pair<double, double> get_mean_var(
  15. const ctype* src, size_t size, ctype expected_mean) {
  16. double sum = 0, sum2 = 0;
  17. for (size_t i = 0; i < size; ++i) {
  18. auto cur = src[i] - expected_mean;
  19. sum += cur;
  20. sum2 += cur * cur;
  21. }
  22. double mean = sum / size;
  23. return {mean + expected_mean, sum2 / size - mean * mean};
  24. }
  25. template <typename ctype>
  26. void assert_uniform_correct(const ctype* src, size_t size);
  27. } // namespace test
  28. } // namespace megdnn
  29. // vim: syntax=cpp.doxygen