diff --git a/src/main.cc b/src/main.cc index 3a11feb..8a3bab5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -192,4 +192,4 @@ main(int argc, char **argv) { _linkedlist(); _vectoralgebra(); return 0; -} +} \ No newline at end of file diff --git a/src/math/vectoralgebra.cc b/src/math/vectoralgebra.cc index aca15ad..4b05ec1 100644 --- a/src/math/vectoralgebra.cc +++ b/src/math/vectoralgebra.cc @@ -32,25 +32,34 @@ MathVectorAlgebra::Cubic(int a, int b, int c, int d, std::vector &x) { * * @return Pointer to array of y values (output) */ + +#include + std::vector MathVectorAlgebra::Convolve(int offset, std::vector &h, std::vector &x) { int m = h.size(); int n = x.size(); - int sum_h = 0; + double sum_h = 0; std::vector y = std::vector(n); + + #pragma omp parallel for reduction(+:sum_h) for (int i = 0; i < m; i += 1) { sum_h += std::abs(h[i]); } + if (sum_h == 0) { sum_h = 1; } + + #pragma omp parallel for for (int i = 0; i < n; i += 1) { - y[i] = 0; + double temp = 0; for (int j = 0; j < m; j += 1) { if (i - offset + j >= 0 && i - offset + j < n) { - y[i] += h[j] * x[i - offset + j] / sum_h; + temp += h[j] * x[i - offset + j]; } } + y[i] = temp / sum_h; } return y; } \ No newline at end of file