Files
Flux-openbuild/include/numerics/matdiv.h
2025-10-06 20:14:13 +00:00

38 lines
934 B
C++

#ifndef _matdiv_n_
#define _matdiv_n_
#include "./utils/matrix.h"
#include "./core/omp_config.h"
namespace numerics{
// ---------------- Serial baseline ----------------
template <typename T>
utils::Matrix<T> matdiv(const utils::Matrix<T>& A, const utils::Vector<T>& b, std::string method){
utils::Matrix<T> C = A;
if (method == "row"){
for (uint64_t i = 0; i < A.rows(); ++i){
for (uint64_t j = 0; j < A.cols(); ++j){
C(i,j) /= b[j];
}
}
}else if (method == "col"){
for (uint64_t i = 0; i < A.rows(); ++i){
for (uint64_t j = 0; j < A.cols(); ++j){
C(i,j) /= b[i];
}
}
}else{
throw std::runtime_error("matdiv: choose div by: 'row' or 'col'");
}
return C;
}
} // namespace numerics
#endif // _matdiv_n_