-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_operations.cpp
More file actions
47 lines (42 loc) · 1.46 KB
/
vector_operations.cpp
File metadata and controls
47 lines (42 loc) · 1.46 KB
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
//This file contains some basic vector operations used by both cca and cda
double euclidean_distance(std::vector<double> const *p1, std::vector<double> const *p2){
double sum = 0;
for(int i=0;i<p1->size();i++){
#pragma omp critical
sum+= pow((*p1)[i]-(*p2)[i], 2);
}
#pragma omp critical
sum = sqrt(sum);
return sum;
}
std::vector<double> vector_subtraction(std::vector<double> const *p1, std::vector<double> const *p2){
std::vector<double> p3 = {};
for(int i=0;i<p1->size();i++){
#pragma omp critical
p3.push_back((*p1)[i]-(*p2)[i]);
}
return p3;
}
std::vector<double> vector_addition(std::vector<double> const *p1, std::vector<double> const *p2){
std::vector<double> p3 = {};
for(int i=0;i<p1->size();i++){
#pragma omp critical
p3.push_back((*p1)[i]+(*p2)[i]);
}
return p3;
}
std::vector<double> scalar_division(std::vector<double> const *p1, double scalar){
std::vector<double> p2 = {};
for(int i=0;i<p1->size();i++){
#pragma omp critical
p2.push_back((*p1)[i]/scalar);
}
return p2;
}
std::vector<double> scalar_multiplication(double scalar, std::vector<double> const *p1){ //switched the order here to jive nicely with the notation of the update rule in lee verlyeson
std::vector<double> p2 = {};
for(int i=0;i<p1->size();i++){
p2.push_back((*p1)[i]*scalar);
}
return p2;
}