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
+73
View File
@@ -0,0 +1,73 @@
#pragma once
#include <cstdint> //uint64_t
//#include <stdexcept> // std::runtime_error
#include "../utils/vector.h"
#include "../utils/matrix.h"
namespace numerics::detail{
// ---------------- Matrix -> Scalar ----------------
template <typename T>
T min_serial(const utils::Matrix<T>& A) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
T min = A(0,0);
for (uint64_t i = 0; i < rows; ++i){
for (uint64_t j = 0; j < cols; ++j){
if (min > A(i,j)){
min = A(i,j);
}
}
}
return min;
}
// ---------------- Vector -> Scalar ----------------
template <typename T>
T min_serial(const utils::Vector<T>& v) {
const uint64_t N = v.size();
T min = v[0];
for (uint64_t i = 0; i < N; ++i){
if (min > v[i]){
min = v[i];
}
}
return min;
}
// ---------------- Matrix -> Vector ----------------
template <typename T>
utils::Vector<T> min_rowwise_serial(const utils::Matrix<T>& A) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
utils::Vector<T> min(rows, T{0});
for (uint64_t i = 0; i < rows; ++i){
min[i] = A(i,0);
for (uint64_t j = 1; j < cols; ++j){
if (min[i] > A(i,j)){
min[i] = A(i,j);
}
}
}
return min;
}
template <typename T>
utils::Vector<T> min_colwise_serial(const utils::Matrix<T>& A) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
utils::Vector<T> min(cols, T{0});
for (uint64_t j = 0; j < cols; ++j){
min[j] = A(0, j);
for (uint64_t i = 1; i < rows; ++i){
if (min[j] > A(i,j)){
min[j] = A(i,j);
}
}
}
return min;
}
} // namespace numerics