summaryrefslogtreecommitdiff
path: root/src/strats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/strats.c')
-rw-r--r--src/strats.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/strats.c b/src/strats.c
new file mode 100644
index 0000000..1c5ce53
--- /dev/null
+++ b/src/strats.c
@@ -0,0 +1,52 @@
+#include <stdlib.h>
+
+static inline void
+product (size_t n,
+ size_t omega,
+ const double *restrict temporal_dependency,
+ const double *restrict vector,
+ double *restrict out)
+{
+ size_t i;
+ #pragma omp parallel for
+ for (i = 0; i < n; i++)
+ {
+ size_t j;
+ out[i] = 0;
+ /* Backward: */
+ for (j = 0; j < omega; j++)
+ {
+ if (i > j)
+ {
+ const double x = vector[i - j - 1];
+ const double coefficient = temporal_dependency[j];
+ out[i] += coefficient * (vector[i] - x);
+ }
+ }
+ /* Forward: */
+ for (j = 0; j < omega; j++)
+ {
+ if (i + j + 1 < n)
+ {
+ const double x = vector[i + j + 1];
+ const double coefficient = temporal_dependency[j];
+ out[i] += coefficient * (vector[i] - x);
+ }
+ }
+ }
+}
+
+void
+strats_compute_laplacian_matrix_product (int *n,
+ int *d,
+ int *omega,
+ double *temporal_dependency,
+ double *x,
+ double *out)
+{
+ int j;
+ for (j = 0; j < *d; j++)
+ {
+ product (*n, *omega, temporal_dependency, x + j * (*n), out + j * (*n));
+ }
+}