From f58babba69e1bafcc25e65b2687896d2fe51ce06 Mon Sep 17 00:00:00 2001
From: schottenhamml <helen.schottenhamml@fau.de>
Date: Wed, 28 Aug 2024 14:11:06 +0200
Subject: [PATCH] Fix flake warnings.

---
 src/lbmpy/flow_statistics.py | 17 +++++++++--------
 tests/test_welford.py        | 10 +++++++---
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/lbmpy/flow_statistics.py b/src/lbmpy/flow_statistics.py
index cdba1656..d4c7e308 100644
--- a/src/lbmpy/flow_statistics.py
+++ b/src/lbmpy/flow_statistics.py
@@ -14,8 +14,8 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
     the sum of squares / sum of cubes is given.
 
     The mean value is directly updated in the mean vector field.
-    The variance / covariance must be retrieved in a post-processing step. Let :math `M_{2,n}` denote the value of the sum of
-    squares after the first :math `n` samples. According to Welford the biased sample variance
+    The variance / covariance must be retrieved in a post-processing step. Let :math `M_{2,n}` denote the value of the
+    sum of squares after the first :math `n` samples. According to Welford the biased sample variance
     :math `\sigma_n^2` and the unbiased sample variance :math `s_n^2` are given by
 
     .. math ::
@@ -78,7 +78,7 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
     if welford_sum_of_cubes_field is not None:
         assert welford_sum_of_squares_field is not None
 
-    ### actual assignments
+    # actual assignments
 
     counter = sp.Symbol('counter')
     delta = sp.symbols(f"delta_:{dim}")
@@ -108,11 +108,12 @@ def welford_assignments(field, mean_field, sum_of_squares_field=None, sum_of_cub
                     for k in range(dim):
                         idx = (i * dim + j) * dim + k
                         main_assignments.append(ps.Assignment(
-                            welford_sum_of_cubes_field.at_index(idx), welford_sum_of_cubes_field.at_index(idx)
-                                                                      - delta[k] / counter * welford_sum_of_squares_field(i * dim + j)
-                                                                      - delta[j] / counter * welford_sum_of_squares_field(k * dim + i)
-                                                                      - delta[i] / counter * welford_sum_of_squares_field(j * dim + k)
-                                                                      + delta2[i] * (2 * delta[j] - delta2[j]) * delta[k]
+                            welford_sum_of_cubes_field.at_index(idx),
+                            welford_sum_of_cubes_field.at_index(idx)
+                            - delta[k] / counter * welford_sum_of_squares_field(i * dim + j)
+                            - delta[j] / counter * welford_sum_of_squares_field(k * dim + i)
+                            - delta[i] / counter * welford_sum_of_squares_field(j * dim + k)
+                            + delta2[i] * (2 * delta[j] - delta2[j]) * delta[k]
                         ))
 
     return main_assignments
diff --git a/tests/test_welford.py b/tests/test_welford.py
index acb3bbab..f374c727 100644
--- a/tests/test_welford.py
+++ b/tests/test_welford.py
@@ -40,7 +40,7 @@ def test_welford(order, dim):
     # set random seed
     np.random.seed(42)
     n = int(1e4)
-    x = np.random.normal(size=n*dim).reshape(n, dim)
+    x = np.random.normal(size=n * dim).reshape(n, dim)
 
     analytical_mean = np.zeros(dim)
     analytical_covariance = np.zeros(dim**2)
@@ -53,13 +53,17 @@ def test_welford(order, dim):
     # calculate analytical covariances
     for i in range(dim):
         for j in range(dim):
-            analytical_covariance[i * dim + j] = (np.sum((x[:, i] - analytical_mean[i]) * (x[:, j] - analytical_mean[j]))) / n
+            analytical_covariance[i * dim + j] \
+                = (np.sum((x[:, i] - analytical_mean[i]) * (x[:, j] - analytical_mean[j]))) / n
 
     # calculate analytical third-order central moments
     for i in range(dim):
         for j in range(dim):
             for k in range(dim):
-                analytical_third_order_moments[(i * dim + j) * dim + k] = (np.sum((x[:, i] - analytical_mean[i]) * (x[:, j] - analytical_mean[j]) * (x[:, k] - analytical_mean[k]))) / n
+                analytical_third_order_moments[(i * dim + j) * dim + k] \
+                    = (np.sum((x[:, i] - analytical_mean[i])
+                              * (x[:, j] - analytical_mean[j])
+                              * (x[:, k] - analytical_mean[k]))) / n
 
     # Time loop
     counter = 1
-- 
GitLab