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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user