almost complete. Need to doublecheck names for functions in *_serial.h
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user