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.

arith.h 856 B

11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <cmath>
  3. #include <vector>
  4. #include <numeric>
  5. namespace arith {
  6. float sqrt(float x);
  7. float mean(const std::vector<int>& x);
  8. template<typename T>
  9. void mm(const std::vector<T>& a, const std::vector<T>& b, std::vector<T>& c, size_t m, size_t k, size_t n) {
  10. // 补全这里,谢谢
  11. c.resize(m * n);
  12. std::fill(c.begin(), c.end(), static_cast<T>(0));
  13. for (size_t i = 0; i < m; ++i) {
  14. for (size_t j = 0; j < n; ++j) {
  15. for (size_t p = 0; p < k; ++p) {
  16. c[i * n + j] += a[i * k + p] * b[p * n + j];
  17. }
  18. }
  19. }
  20. }
  21. template<typename T>
  22. void vector_scalar_max(const std::vector<T>& a, std::vector<T> &b, T scalar) {
  23. // 补全这里,谢谢
  24. b.resize(a.size());
  25. for (size_t i = 0; i < a.size(); ++i) {
  26. b[i] = (a[i] > scalar) ? a[i] : scalar;
  27. }
  28. }
  29. }