-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectorview.cpp
55 lines (45 loc) · 926 Bytes
/
vectorview.cpp
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
55
#include "vectorview.hpp"
namespace linalgcpp
{
void Randomize(VectorView<double> vect, double lo, double hi, int seed)
{
std::random_device r;
std::default_random_engine dev(r());
std::uniform_real_distribution<double> gen(lo, hi);
if (seed >= 0)
{
dev.seed(seed);
}
for (double& val : vect)
{
val = gen(dev);
}
}
void Randomize(VectorView<int> vect, int lo, int hi, int seed)
{
std::random_device r;
std::default_random_engine dev(r());
std::uniform_int_distribution<int> gen(lo, hi);
if (seed >= 0)
{
dev.seed(seed);
}
for (int& val : vect)
{
val = gen(dev);
}
}
void Normalize(VectorView<double> vect)
{
vect /= L2Norm(vect);
}
void SubAvg(VectorView<double> vect)
{
vect -= Mean(vect);
}
template <>
void VectorView<double>::Normalize()
{
linalgcpp::Normalize(*this);
}
} // namespace linalgcpp