Refactor progress
Sync public mirror / sync (push) Failing after 27s

Next step is ramdom and equal. I also need to have a look at add and the serial naming of the functions.
This commit is contained in:
2026-01-13 20:07:27 +01:00
parent 48f329feef
commit 9709949a5b
52 changed files with 2038 additions and 1058 deletions
+55
View File
@@ -0,0 +1,55 @@
#pragma once
#include <cstdint> //uint64_t
//#include <stdexcept> // std::runtime_error
#include "../utils/vector.h"
#include "../utils/matrix.h"
#include "sum_serial.h"
namespace numerics::detail{
// ---------------- Matrix -> Scalar ----------------
template <typename T>
T mean_serial(const utils::Matrix<T>& A) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
T sum = detail::sum_serial(A);
sum /= static_cast<T>(rows*cols);
return sum;
}
// ---------------- Vector -> Scalar ----------------
template <typename T>
T mean_serial(const utils::Vector<T>& v) {
const uint64_t N = v.size();
T sum = detail::sum_serial(v);
sum /= static_cast<T>(N);
return sum;
}
// ---------------- Matrix -> Vector ----------------
template <typename T>
utils::Vector<T> mean_rowwise_serial(const utils::Matrix<T>& A) {
const T cols = static_cast<T>(A.cols());
utils::Vector<T> sum = detail::sum_rowwise_serial(A);
const uint64_t N = sum.size();
for (uint64_t i = 0; i < N; ++i){
sum[i] /= cols;
}
return sum;
}
template <typename T>
utils::Vector<T> mean_colwise_serial(const utils::Matrix<T>& A) {
const T rows = static_cast<T>(A.rows());
utils::Vector<T> sum = detail::sum_colwise_serial(A);
const uint64_t N = sum.size();
for (uint64_t i = 0; i < N; ++i){
sum[i] /= rows;
}
return sum;
}
} // namespace numerics