-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
42 lines (32 loc) · 939 Bytes
/
utils.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
#include "utils.h"
std::vector<double> elem_add(const std::vector<double> &lhs, const std::vector<double> &rhs)
{
size_t n = lhs.size();
assert((n == rhs.size()) && "Tried to add vector without equal length");
std::vector<double> output(lhs);
for (size_t i = 0; i < n; i++)
{
output.at(i) += rhs.at(i);
}
return output;
}
std::vector<double> operator+(const std::vector<double> &lhs, const std::vector<double> &rhs)
{
size_t n = lhs.size();
assert((n == rhs.size()) && "Tried to add vector without equal length");
std::vector<double> output(lhs);
for (size_t i = 0; i < n; i++)
{
output.at(i) += rhs.at(i);
}
return output;
};
std::vector<double> operator*(const double &scale, const std::vector<double> &rhs)
{
std::vector<double> output(rhs);
for (size_t i = 0; i < rhs.size(); i++)
{
output.at(i) *= scale;
}
return output;
};