Files
Bausager 6b8a7ab582
Sync public mirror / sync (push) Failing after 29s
refactor
almost complete. Need to doublecheck names for functions in *_serial.h
2026-01-18 17:51:05 +01:00

97 lines
2.7 KiB
C++

#pragma once
#include "./core/omp_config.h"
#include "detail/random_serial.h"
#include "add.h"
#include "mul.h"
namespace numerics{
// ---------------- inplace_random ----------------
template <typename T>
inline void inplace_random(utils::Vector<T>& v, const T low, const T high) {
detail::inplace_random_serial(v, low, high);
}
template <typename T>
inline void inplace_random(utils::Matrix<T>& A, const T low, const T high) {
detail::inplace_random_serial(A, low, high);
}
// ---------------- random ----------------
template <typename T>
inline utils::Vector<T> random_vector(const uint64_t n, const T low, const T high) {
utils::Vector<T> v(n);
inplace_random(v, low, high);
return v;
}
template <typename T>
inline utils::Matrix<T> random_matrix(const uint64_t n, const uint64_t m, const T low, const T high) {
utils::Matrix<T> A(n, m);
inplace_random(A, low, high);
return A;
}
// ---------------- inplace random add----------------
template <typename T>
inline void inplace_random_add(utils::Vector<T>& v, const T low, const T high){
utils::Vector<T> noise = random_vector(v.size(), low, high);
inplace_add(v, noise);
}
template <typename T>
inline void inplace_random_add(utils::Matrix<T>& A, const T low, const T high){
utils::Matrix<T> noise = random_matrix(A.rows(), A.cols(), low, high);
inplace_add(A, noise);
}
// ---------------- random add----------------
template <typename T>
inline utils::Vector<T> random_add(const utils::Vector<T>& v, const T low, const T high){
utils::Vector<T> out = v;
inplace_random_add(out, low, high);
return out;
}
template <typename T>
inline utils::Matrix<T> random_add(const utils::Matrix<T>& A, const T low, const T high){
utils::Matrix<T> out = A;
inplace_random_add(out, low, high);
return out;
}
// ---------------- inplace random mul----------------
template <typename T>
inline void inplace_random_mul(utils::Vector<T>& v, const T low, const T high){
utils::Vector<T> noise = random_vector(v.size(), low, high);
inplace_mul(v, noise);
}
template <typename T>
inline void inplace_random_mul(utils::Matrix<T>& A, const T low, const T high){
utils::Matrix<T> noise = random_matrix(A.rows(), A.cols(), low, high);
inplace_mul(A, noise);
}
// ---------------- random mul----------------
template <typename T>
inline utils::Vector<T> random_mul(const utils::Vector<T>& v, const T low, const T high){
utils::Vector<T> out = v;
inplace_random_mul(out, low, high);
return out;
}
template <typename T>
inline utils::Matrix<T> random_mul(const utils::Matrix<T>& A, const T low, const T high){
utils::Matrix<T> out = A;
inplace_random_mul(out, low, high);
return out;
}
}