-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.h
55 lines (44 loc) · 1.19 KB
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _util_h_
#define _util_h_
#include <vector>
#include <ostream>
#include <sstream>
#include <random>
template <class T>
std::string vstr(const std::vector<T>& v) {
std::stringstream ss;
ss << "(";
for (size_t i = 0; i < v.size(); ++i) {
ss << v[i];
if (i != v.size() - 1) {
ss << ",";
}
}
ss << ")";
return ss.str();
}
template <class T>
std::vector<T> random_vec(size_t size, T min_val, T max_val) {
std::random_device rd;
std::default_random_engine generator(rd());
std::uniform_real_distribution<T> distribution(min_val, max_val);
std::vector<T> vec(size);
std::generate(vec.begin(), vec.end(), [&](){
return distribution(generator);
});
return vec;
}
template <class T>
std::vector<T> random_normal_vec(size_t size, T mean, T stddev) {
std::random_device rd;
std::default_random_engine generator(rd());
std::normal_distribution<T> distribution(mean, stddev);
std::vector<T> vec(size);
std::generate(vec.begin(), vec.end(), [&](){
return distribution(generator);
});
return vec;
}
std::vector<float> random_vec(size_t, float, float);
std::vector<float> random_normal_vec(size_t, float, float);
#endif // _util_h_