-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
44 lines (33 loc) · 785 Bytes
/
utils.hpp
File metadata and controls
44 lines (33 loc) · 785 Bytes
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
#include <vector>
#include <cmath>
#include <complex>
// adapted from: 17-cholesky/matrix.hpp by Thorsten Koch
template <typename T>
T max_norm(std::vector<std::complex<T>> const& vec)
{
T max_x = 0.0;
T abs_x;
for(auto x : vec) {
abs_x = std::abs(x);
if (abs_x > max_x)
max_x = abs_x;
}
return max_x;
}
template <typename T>
T two_norm(std::vector<std::complex<T>> const& vec)
{
T sum = 0.0;
for(auto x : vec)
sum += std::norm(x);
return std::sqrt(sum);
}
template <typename T>
std::vector<T> operator-(std::vector<T> const& a, std::vector<T> const& b)
{
assert(a.size() == b.size());
std::vector<T> r(a.size(), 0.0);
for(size_t i = 0; i < a.size(); ++i)
r[i] = a[i] - b[i];
return r;
}