-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathutil.hpp
45 lines (36 loc) · 917 Bytes
/
util.hpp
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
#ifndef _CPP_UTIL_
#define _CPP_UTIL_
#include<iostream>
#include<string>
#include<sstream>
//#include<boost/numeric/ublas/vector.hpp>
using namespace std;
//////////////////// utils/////////////////////////////////
template < class T>
void convert_from_string(T& value, const string& s)
{
stringstream ss(s);
ss >> value;
}
double norm(const std::vector<double>& v1, const std::vector<double>& v2) {
assert (v1.size() == v2.size());
double sum = 0;
for (size_t i=0; i<v1.size(); ++i)
{
double minus = v1[i] - v2[i];
double r = minus * minus;
sum += r;
}
return sqrt(sum);
}
double norm_1(const std::vector<double>& v1, const std::vector<double>& v2) {
assert (v1.size() == v2.size());
double sum = 0;
for (size_t i=0; i<v1.size(); ++i)
{
double minus = abs(v1[i] - v2[i]);
sum += minus;
}
return sum;
}
#endif