-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvector_math.h
36 lines (29 loc) · 839 Bytes
/
vector_math.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
#ifndef VECTOR_MATH_H
#define VECTOR_MATH_H
#include <vector>
#include <algorithm>
#include "pcgsolver/blas_wrapper.h"
template<class T>
T sum(std::vector<T>& data) {
T result = 0;
for(unsigned int i = 0; i < data.size(); ++i)
result += data[i];
return result;
}
template<class T>
void copy(const std::vector<T> & src, std::vector<T>& dest) {
std::copy(src.begin(), src.end(), dest.begin());
}
template<class T>
T dot(const std::vector<T>& a, const std::vector<T>& b) {
return BLAS::dot((int)a.size(), &a[0], &b[0]);
}
template<class T>
void scale(T factor, std::vector<T>& data) {
BLAS::scale((int)data.size(), factor, &data[0]);
}
template<class T>
void add_scaled(T alpha, const std::vector<T>& x, std::vector<T>& y) { // y = y + alpha*x
BLAS::add_scaled((int)x.size(), alpha, &x[0], &y[0]);
}
#endif