From dab98fad966aedf5a6010dfef3a0a9a9a3e4961e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ren=C3=A9=20He=C3=9F?= <rene.hess@iwr.uni-heidelberg.de>
Date: Wed, 29 Mar 2017 09:32:06 +0200
Subject: [PATCH] PEP8

---
 python/dune/perftool/pdelab/driver.py         |  2 +-
 python/dune/perftool/pdelab/geometry.py       |  2 +-
 python/dune/perftool/pdelab/localoperator.py  |  8 ++--
 python/dune/perftool/pdelab/tensors.py        |  4 +-
 python/dune/perftool/sumfact/sumfact.py       | 42 +++++++++----------
 .../ufl/extract_accumulation_terms.py         |  8 ++--
 .../dune/perftool/ufl/modified_terminals.py   |  1 -
 .../ufl/transformations/axiparallel.py        |  1 -
 python/dune/perftool/ufl/visitor.py           |  1 -
 9 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/python/dune/perftool/pdelab/driver.py b/python/dune/perftool/pdelab/driver.py
index aaf4c092..7347f6f9 100644
--- a/python/dune/perftool/pdelab/driver.py
+++ b/python/dune/perftool/pdelab/driver.py
@@ -1782,7 +1782,7 @@ def generate_driver(formdatas, data):
         assert(any(_driver_data['form'].ufl_cell().cellname() in x for x in
                    ["vertex", "interval", "quadrilateral", "hexahedron"]))
         # In case of operator conunting we only assemble the matrix and evaluate the residual
-        #assemble_matrix_timer()
+        # assemble_matrix_timer()
         evaluate_residual_timer()
         apply_jacobian_timer()
     elif is_stationary():
diff --git a/python/dune/perftool/pdelab/geometry.py b/python/dune/perftool/pdelab/geometry.py
index 9da0f1ee..58122feb 100644
--- a/python/dune/perftool/pdelab/geometry.py
+++ b/python/dune/perftool/pdelab/geometry.py
@@ -290,7 +290,7 @@ def name_unit_inner_normal():
 def type_jacobian_inverse_transposed(restriction):
     if get_option('turn_off_diagonal_jacobian'):
         dim = world_dimension()
-        return "typename Dune::FieldMatrix<double,{},{}>".format(dim,dim)
+        return "typename Dune::FieldMatrix<double,{},{}>".format(dim, dim)
     else:
         geo = type_cell_geometry(restriction)
         return "typename {}::JacobianInverseTransposed".format(geo)
diff --git a/python/dune/perftool/pdelab/localoperator.py b/python/dune/perftool/pdelab/localoperator.py
index 1a5f8faf..24f7e937 100644
--- a/python/dune/perftool/pdelab/localoperator.py
+++ b/python/dune/perftool/pdelab/localoperator.py
@@ -431,14 +431,14 @@ def visit_integrals(integrals):
             domain = accterm.argument.argexpr.ufl_domain()
             if measure == "cell":
                 set_subst_rule("integration_factor_cell1",
-                               uc.QuadratureWeight(domain)*uc.Abs(uc.JacobianDeterminant(domain)))
+                               uc.QuadratureWeight(domain) * uc.Abs(uc.JacobianDeterminant(domain)))
                 set_subst_rule("integration_factor_cell2",
-                               uc.Abs(uc.JacobianDeterminant(domain))*uc.QuadratureWeight(domain))
+                               uc.Abs(uc.JacobianDeterminant(domain)) * uc.QuadratureWeight(domain))
             else:
                 set_subst_rule("integration_factor_facet1",
-                               uc.FacetJacobianDeterminant(domain)*uc.QuadratureWeight(domain))
+                               uc.FacetJacobianDeterminant(domain) * uc.QuadratureWeight(domain))
                 set_subst_rule("integration_factor_facet2",
-                               uc.QuadratureWeight(domain)*uc.FacetJacobianDeterminant(domain))
+                               uc.QuadratureWeight(domain) * uc.FacetJacobianDeterminant(domain))
 
             get_backend(interface="accum_insn")(visitor, accterm, measure, subdomain_id)
 
diff --git a/python/dune/perftool/pdelab/tensors.py b/python/dune/perftool/pdelab/tensors.py
index aa154bdb..a3953799 100644
--- a/python/dune/perftool/pdelab/tensors.py
+++ b/python/dune/perftool/pdelab/tensors.py
@@ -48,14 +48,14 @@ def define_identity(name, expr):
     i = identity_iname("i", expr.ufl_shape[0])
     j = identity_iname("j", expr.ufl_shape[1])
     instruction(assignee=prim.Subscript(prim.Variable(name), (prim.Variable(i), prim.Variable(j))),
-                expression=prim.If(prim.Comparison(prim.Variable(i),"==",prim.Variable(j)),1,0),
+                expression=prim.If(prim.Comparison(prim.Variable(i), "==", prim.Variable(j)), 1, 0),
                 forced_iname_deps_is_final=True,
                 )
 
 
 @kernel_cached
 def pymbolic_identity(expr):
-    name = "identity_{}_{}".format(expr.ufl_shape[0],expr.ufl_shape[1])
+    name = "identity_{}_{}".format(expr.ufl_shape[0], expr.ufl_shape[1])
     temporary_variable(name,
                        shape=expr.ufl_shape,
                        shape_impl=('fm',),
diff --git a/python/dune/perftool/sumfact/sumfact.py b/python/dune/perftool/sumfact/sumfact.py
index 73952843..a91079f5 100644
--- a/python/dune/perftool/sumfact/sumfact.py
+++ b/python/dune/perftool/sumfact/sumfact.py
@@ -221,7 +221,6 @@ def generate_accumulation_instruction(visitor, accterm, measure, subdomain_id):
                                               depends_on=insn_dep,
                                               within_inames=frozenset(visitor.inames))})
 
-
         inames = tuple(accum_iname((accterm.argument.restriction, restriction), mat.rows, i)
                        for i, mat in enumerate(a_matrices))
 
@@ -260,7 +259,6 @@ def generate_accumulation_instruction(visitor, accterm, measure, subdomain_id):
                 assert ft == 'jacobian'
                 direct_output = accum
 
-
         # Add a sum factorization kernel that implements the multiplication
         # with the test function (stage 3)
         pref_pos = i if accterm.new_indices else None
@@ -298,8 +296,8 @@ def generate_accumulation_instruction(visitor, accterm, measure, subdomain_id):
             if get_global_context_value("dry_run", False):
                 dummy = "dummy"
                 globalarg(dummy, dtype=np.float64)
-                instruction(assignee = prim.Variable(dummy),
-                            expression = result,
+                instruction(assignee=prim.Variable(dummy),
+                            expression=result,
                             forced_iname_deps=frozenset(inames),
                             forced_iname_deps_is_final=True,
                             depends_on=insn_dep,
@@ -350,29 +348,29 @@ def _sf_permutation_heuristic(permutations, stage):
     """
     def cost(perm, stage):
         cost = 0
-        for i in range(0,len(perm)-2):
-            if stage==1:
-                if perm[i+1]>perm[i+2]:
+        for i in range(0, len(perm) - 2):
+            if stage == 1:
+                if perm[i + 1] > perm[i + 2]:
                     cost += 1
-            if stage==3:
-                if perm[0]>perm[i+1]:
+            if stage == 3:
+                if perm[0] > perm[i + 1]:
                     cost += 1
         return cost
 
-    perm = min(permutations, key=lambda i:cost(i,stage))
+    perm = min(permutations, key=lambda i: cost(i, stage))
     return perm
 
 
 def _sf_flop_cost(a_matrices):
     """Computational cost of sumfactorization with this list of a_matrices
     """
-    cost = 0;
+    cost = 0
     for l in range(len(a_matrices)):
         cost_m = 1
         cost_n = 1
-        for i in range(l+1):
+        for i in range(l + 1):
             cost_m *= a_matrices[i].rows
-        for i in range(l,len(a_matrices)):
+        for i in range(l, len(a_matrices)):
             cost_n *= a_matrices[i].cols
         cost += cost_m * cost_n
     return cost
@@ -393,12 +391,12 @@ def _sf_permutation_strategy(a_matrices, stage):
     for permutation in itertools.permutations(perm_a_matrices):
         perm, series = zip(*permutation)
         cost = _sf_flop_cost(series)
-        perm_cost.append((perm,cost))
+        perm_cost.append((perm, cost))
 
     # Find minimal cost and all permutations with that cost
     _, costs = zip(*perm_cost)
     minimal_cost = min(costs)
-    minimal_cost_permutations = [p[0] for p in perm_cost if p[1]==minimal_cost]
+    minimal_cost_permutations = [p[0] for p in perm_cost if p[1] == minimal_cost]
 
     # Use heuristic to pic one of the minimal cost permutations
     perm = _sf_permutation_heuristic(minimal_cost_permutations, stage)
@@ -413,7 +411,7 @@ def _permute_forward(t, perm):
 
 
 def _permute_backward(t, perm):
-    tmp = [None]*len(t)
+    tmp = [None] * len(t)
     for i, pos in enumerate(perm):
         tmp[pos] = t[i]
     return tuple(tmp)
@@ -500,9 +498,9 @@ def sum_factorization_kernel(a_matrices,
     if get_global_context_value("dry_run", False):
         return SumfactKernel(a_matrices, buf, stage, preferred_position, restriction), frozenset()
 
-    ftags = ",".join(["f"]*len(a_matrices))
+    ftags = ",".join(["f"] * len(a_matrices))
     novec_ftags = ftags
-    ctags = ",".join(["c"]*len(a_matrices))
+    ctags = ",".join(["c"] * len(a_matrices))
     vec_shape = ()
     if next(iter(a_matrices)).vectorized:
         ftags = ftags + ",vec"
@@ -611,7 +609,7 @@ def sum_factorization_kernel(a_matrices,
         #
         # If we are in the last step we reverse the permutation.
         output_shape = tuple(out_shape[1:]) + (out_shape[0],)
-        if l == len(a_matrices)-1:
+        if l == len(a_matrices) - 1:
             output_shape = _permute_backward(output_shape, perm)
         out = get_buffer_temporary(buf,
                                    shape=output_shape + vec_shape,
@@ -629,12 +627,12 @@ def sum_factorization_kernel(a_matrices,
         # Here we also move the new direction (out_inames[0]) to the
         # end and reverse permutation
         output_inames = tuple(prim.Variable(i) for i in out_inames[1:]) + (prim.Variable(out_inames[0]),)
-        if l == len(a_matrices)-1:
+        if l == len(a_matrices) - 1:
             output_inames = _permute_backward(output_inames, perm)
 
         # In case of direct output we directly accumulate the result
         # of the Sumfactorization into some global data structure.
-        if l == len(a_matrices)-1 and direct_output is not None:
+        if l == len(a_matrices) - 1 and direct_output is not None:
             ft = get_global_context_value("form_type")
             if ft == 'residual' or ft == 'jacobian_apply':
                 globalarg(direct_output, dtype=np.float64, shape=output_shape, dim_tags=novec_ftags)
@@ -644,7 +642,7 @@ def sum_factorization_kernel(a_matrices,
                 globalarg(direct_output,
                           dtype=np.float64,
                           shape=output_shape + output_shape,
-                          dim_tags = novec_ftags + "," + novec_ftags)
+                          dim_tags=novec_ftags + "," + novec_ftags)
                 # TODO the next line should get its inames from
                 # elsewhere. This is *NOT* robust (but works right
                 # now)
diff --git a/python/dune/perftool/ufl/extract_accumulation_terms.py b/python/dune/perftool/ufl/extract_accumulation_terms.py
index 4dbebbb8..15aef688 100644
--- a/python/dune/perftool/ufl/extract_accumulation_terms.py
+++ b/python/dune/perftool/ufl/extract_accumulation_terms.py
@@ -135,16 +135,16 @@ def split_into_accumulation_terms(expr):
                 # - Propagating the identity in step 4.
                 # - Replacing (\nabla v)_{k,l} by I_{k,l} after step 4.
                 if len(set(indexed_test_arg.index._indices)) < len(indexed_test_arg.index._indices):
-                    if len(indexed_test_arg.index._indices)>2:
+                    if len(indexed_test_arg.index._indices) > 2:
                         raise NotImplementedError("Test argument with more than three indices and double occurence ist not implemented.")
                     mod_index_map = {indexed_test_arg.index: MultiIndex((newi[0], newi[1]))}
                     mod_indexed_test_arg = replace_expression(indexed_test_arg.expr,
-                                                              replacemap = mod_index_map)
+                                                              replacemap=mod_index_map)
                     rep = Product(Indexed(Identity(2),
-                                          MultiIndex((newi[0],indexed_test_arg.index[0]))),
+                                          MultiIndex((newi[0], indexed_test_arg.index[0]))),
                                   mod_indexed_test_arg)
                     backmap.update({mod_indexed_test_arg:
-                                    Indexed(Identity(2), MultiIndex((newi[0],newi[1])))})
+                                    Indexed(Identity(2), MultiIndex((newi[0], newi[1])))})
                     replacement.update({indexed_test_arg.expr: rep})
                     indexmap.update({indexed_test_arg.index[0]: newi[0]})
                 else:
diff --git a/python/dune/perftool/ufl/modified_terminals.py b/python/dune/perftool/ufl/modified_terminals.py
index b5d2f2c5..50dd3315 100644
--- a/python/dune/perftool/ufl/modified_terminals.py
+++ b/python/dune/perftool/ufl/modified_terminals.py
@@ -168,7 +168,6 @@ class _ModifiedArgumentExtractor(MultiFunction):
         else:
             self.expr(o)
 
-
     positive_restricted = pass_on
     negative_restricted = pass_on
     function_view = pass_on
diff --git a/python/dune/perftool/ufl/transformations/axiparallel.py b/python/dune/perftool/ufl/transformations/axiparallel.py
index 6d7e53e4..4ded73a7 100644
--- a/python/dune/perftool/ufl/transformations/axiparallel.py
+++ b/python/dune/perftool/ufl/transformations/axiparallel.py
@@ -49,7 +49,6 @@ class LocalDiagonalJITReplacer(MultiFunction):
         else:
             return self.reuse_if_untouched(o, *tuple(self.call(op) for op in o.ufl_operands))
 
-
     def index_sum(self, o):
         # Check if we want to replace an index here and store it in
         # local_replacemap
diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py
index 711f92bf..96f1cb85 100644
--- a/python/dune/perftool/ufl/visitor.py
+++ b/python/dune/perftool/ufl/visitor.py
@@ -296,7 +296,6 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker):
 
         return ret
 
-
     #
     # Handler for conditionals, use pymbolic base implementation
     #
-- 
GitLab