Sync public subset from Flux

This commit is contained in:
Gitea CI
2025-10-07 11:09:55 +00:00
parent 8892d58e66
commit 35023cb7e1
30 changed files with 707 additions and 229 deletions

52
include/numerics/matmax.h Normal file
View File

@@ -0,0 +1,52 @@
#pragma once
#include "./utils/matrix.h"
namespace numerics{
template <typename T>
T matmax(const utils::Matrix<T>& A){
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
T max_value(T{0});
for (uint64_t i = 0; i < rows; ++i){
for (uint64_t j = 0; j < cols; ++j){
max_value = numerics::max(max_value, A(i,j));
}
}
return max_value;
}
template <typename T>
utils::Vector<T> matmax(const utils::Matrix<T>& A, std::string method){
utils::Vector<T> b;
if (method == "cols"){
b.resize(A.cols(), T{0});
for (uint64_t i = 0; i < A.cols(); ++i){
for (uint64_t j = 0; j < A.rows(); ++j){
b[i] = numerics::max(A(j, i), b[i]);
}
}
}else if (method == "rows"){
b.resize(A.rows(), T{0});
for (uint64_t i = 0; i < A.rows(); ++i){
for (uint64_t j = 0; j < A.cols(); ++j){
b[i] = numerics::max(A(i, j), b[i]);
}
}
}else{
throw std::runtime_error("max: choose 'rows or 'cols'");
}
return b;
}
} // namespace numerics