Files
Flux-openbuild/include/numerics/matrandom.h
2025-10-09 08:44:15 +00:00

55 lines
1.2 KiB
C++

#ifndef _matrandom_n_
#define _matrandom_n_
#include "./utils/vector.h"
#include "./utils/matrix.h"
#include "./core/omp_config.h"
namespace numerics{
template <typename T>
void inplace_matrandom_add(utils::Matrix<T>& A, const T lower, const T higher) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
utils::Matrix<T> B;
B.random(rows,cols, lower, higher);
numerics::inplace_matadd_mat(A, B);
}
template <typename T>
void inplace_matrandom_mul(utils::Matrix<T>& A, const T lower, const T higher) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
utils::Matrix<T> B;
B.random(rows,cols, lower, higher);
for (uint64_t i = 0; i < rows; ++i){
for (uint64_t j = 0; j < cols; ++j){
A(i,j) *= B(i,j);
}
}
}
template <typename T>
utils::Matrix<T> matrandom_add(const utils::Matrix<T>& A, const T lower, const T higher) {
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
utils::Matrix<T> B = A;
numerics::inplace_matadd_mat(B, lower, higher);
return B;
}
} // namespace numerics
#endif // _matrandom_n_