From ac7eb1deed5aaf39cfca9d4b710ebfa7243eefce Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 28 Oct 2018 14:31:34 -0500 Subject: [PATCH] Placate flake8 3.6 --- sumpy/__init__.py | 3 +-- sumpy/assignment_collection.py | 2 +- sumpy/expansion/level_to_order.py | 2 +- sumpy/kernel.py | 4 ++-- sumpy/p2p.py | 28 ++++++++++++++-------------- sumpy/qbx.py | 24 ++++++++++++------------ sumpy/toys.py | 6 ++---- test/test_cse.py | 10 +++++----- test/test_matrixgen.py | 4 ++-- 9 files changed, 40 insertions(+), 43 deletions(-) diff --git a/sumpy/__init__.py b/sumpy/__init__.py index 8bece3a2..fd0fc515 100644 --- a/sumpy/__init__.py +++ b/sumpy/__init__.py @@ -61,8 +61,7 @@ CACHING_ENABLED = True CACHING_ENABLED = ( "SUMPY_NO_CACHE" not in os.environ - and - "CG_NO_CACHE" not in os.environ) + and "CG_NO_CACHE" not in os.environ) def set_caching_enabled(flag): diff --git a/sumpy/assignment_collection.py b/sumpy/assignment_collection.py index a12a17fd..96d078a0 100644 --- a/sumpy/assignment_collection.py +++ b/sumpy/assignment_collection.py @@ -51,7 +51,7 @@ class _SymbolGenerator(object): def _normalize(self, base): # Strip off any _N suffix, to avoid generating conflicting names. import re - base = re.split("_\d+$", base)[0] + base = re.split(r"_\d+$", base)[0] return base if base != "" else "expr" def __call__(self, base="expr"): diff --git a/sumpy/expansion/level_to_order.py b/sumpy/expansion/level_to_order.py index 44d86ee2..8f012e55 100644 --- a/sumpy/expansion/level_to_order.py +++ b/sumpy/expansion/level_to_order.py @@ -131,7 +131,7 @@ class SimpleExpansionOrderFinder(object): laplace_order = int(np.ceil( (np.log(self.tol) - np.log(self.err_const_laplace)) - / + / # noqa: W504 np.log( np.sqrt(tree.dimensions)/3 ) - 1)) diff --git a/sumpy/kernel.py b/sumpy/kernel.py index 3ce0bb8d..99222f68 100644 --- a/sumpy/kernel.py +++ b/sumpy/kernel.py @@ -600,7 +600,7 @@ class StokesletKernel(ExpressionKernel): r = pymbolic_real_norm_2(d) expr = ( -var("log")(r)*(1 if icomp == jcomp else 0) - + + + # noqa: W504 d[icomp]*d[jcomp]/r**2 ) scaling = -1/(4*var("pi")*mu) @@ -610,7 +610,7 @@ class StokesletKernel(ExpressionKernel): r = pymbolic_real_norm_2(d) expr = ( (1/r)*(1 if icomp == jcomp else 0) - + + + # noqa: W504 d[icomp]*d[jcomp]/r**3 ) scaling = -1/(8*var("pi")*mu) diff --git a/sumpy/p2p.py b/sumpy/p2p.py index d8fdadf4..4c4eb945 100644 --- a/sumpy/p2p.py +++ b/sumpy/p2p.py @@ -136,10 +136,10 @@ class P2PBase(KernelComputation, KernelCacheWrapper): lp.GlobalArg("targets", None, shape=(self.dim, "ntargets")), lp.ValueArg("nsources", None), - lp.ValueArg("ntargets", None)] + - ([lp.GlobalArg("target_to_source", None, shape=("ntargets",))] - if self.exclude_self else []) + - gather_loopy_source_arguments(self.kernels)) + lp.ValueArg("ntargets", None)] + + ([lp.GlobalArg("target_to_source", None, shape=("ntargets",))] + if self.exclude_self else []) + + gather_loopy_source_arguments(self.kernels)) def get_kernel(self): raise NotImplementedError @@ -171,8 +171,8 @@ class P2P(P2PBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [ + self.get_default_src_tgt_arguments() + + [ lp.GlobalArg("strength", None, shape="nstrengths, nsources", dim_tags="sep,C"), lp.GlobalArg("result", None, @@ -241,8 +241,8 @@ class P2PMatrixGenerator(P2PBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [lp.GlobalArg("result_%d" % i, dtype, + self.get_default_src_tgt_arguments() + + [lp.GlobalArg("result_%d" % i, dtype, shape="ntargets,nsources") for i, dtype in enumerate(self.value_dtypes)]) @@ -307,13 +307,13 @@ class P2PMatrixBlockGenerator(P2PBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [ + self.get_default_src_tgt_arguments() + + [ lp.GlobalArg("srcindices", None, shape="nresult"), lp.GlobalArg("tgtindices", None, shape="nresult"), lp.ValueArg("nresult", None) - ] + - [lp.GlobalArg("result_%d" % i, dtype, shape="nresult") + ] + + [lp.GlobalArg("result_%d" % i, dtype, shape="nresult") for i, dtype in enumerate(self.value_dtypes)]) loopy_knl = lp.make_kernel( @@ -415,8 +415,8 @@ class P2PFromCSR(P2PBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [ + self.get_default_src_tgt_arguments() + + [ lp.GlobalArg("box_target_starts", None, shape=None), lp.GlobalArg("box_target_counts_nonchild", diff --git a/sumpy/qbx.py b/sumpy/qbx.py index 79de1544..0d4359b6 100644 --- a/sumpy/qbx.py +++ b/sumpy/qbx.py @@ -158,8 +158,8 @@ class LayerPotentialBase(KernelComputation, KernelCacheWrapper): lp.GlobalArg("expansion_radii", None, shape="ntargets"), lp.ValueArg("nsources", None), - lp.ValueArg("ntargets", None)] + - gather_loopy_source_arguments(self.kernels)) + lp.ValueArg("ntargets", None)] + + gather_loopy_source_arguments(self.kernels)) def get_kernel(self): raise NotImplementedError @@ -201,11 +201,11 @@ class LayerPotential(LayerPotentialBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [lp.GlobalArg("strength_%d" % i, + self.get_default_src_tgt_arguments() + + [lp.GlobalArg("strength_%d" % i, None, shape="nsources", order="C") - for i in range(self.strength_count)] + - [lp.GlobalArg("result_%d" % i, + for i in range(self.strength_count)] + + [lp.GlobalArg("result_%d" % i, None, shape="ntargets", order="C") for i in range(len(self.kernels))]) @@ -275,8 +275,8 @@ class LayerPotentialMatrixGenerator(LayerPotentialBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [lp.GlobalArg("result_%d" % i, + self.get_default_src_tgt_arguments() + + [lp.GlobalArg("result_%d" % i, dtype, shape="ntargets, nsources", order="C") for i, dtype in enumerate(self.value_dtypes)]) @@ -339,13 +339,13 @@ class LayerPotentialMatrixBlockGenerator(LayerPotentialBase): loopy_insns, result_names = self.get_loopy_insns_and_result_names() kernel_exprs = self.get_kernel_exprs(result_names) arguments = ( - self.get_default_src_tgt_arguments() + - [ + self.get_default_src_tgt_arguments() + + [ lp.GlobalArg("srcindices", None, shape="nresult"), lp.GlobalArg("tgtindices", None, shape="nresult"), lp.ValueArg("nresult", None) - ] + - [lp.GlobalArg("result_%d" % i, dtype, shape="nresult") + ] + + [lp.GlobalArg("result_%d" % i, dtype, shape="nresult") for i, dtype in enumerate(self.value_dtypes)]) loopy_knl = lp.make_kernel([ diff --git a/sumpy/toys.py b/sumpy/toys.py index 5177d869..9bc68ae5 100644 --- a/sumpy/toys.py +++ b/sumpy/toys.py @@ -564,8 +564,7 @@ def combine_inner_outer(psource_inner, psource_outer, radius, center=None): ball_one = OneOnBallPotential(psource_inner.toy_ctx, center, radius) return ( psource_inner * ball_one - + - psource_outer * (1 - ball_one)) + + psource_outer * (1 - ball_one)) def combine_halfspace(psource_pos, psource_neg, axis, center=None): @@ -575,8 +574,7 @@ def combine_halfspace(psource_pos, psource_neg, axis, center=None): halfspace_one = HalfspaceOnePotential(psource_pos.toy_ctx, center, axis) return ( psource_pos * halfspace_one - + - psource_neg * (1-halfspace_one)) + + psource_neg * (1-halfspace_one)) def combine_halfspace_and_outer(psource_pos, psource_neg, psource_outer, diff --git a/test/test_cse.py b/test/test_cse.py index d6a2c0f0..703e8c9f 100644 --- a/test/test_cse.py +++ b/test/test_cse.py @@ -134,8 +134,8 @@ def test_cse_not_possible(): assert substs == [] assert reduced == [x + y] # issue 6329 - eq = (meijerg((1, 2), (y, 4), (5,), [], x) + - meijerg((1, 3), (y, 4), (5,), [], x)) + eq = (meijerg((1, 2), (y, 4), (5,), [], x) + + meijerg((1, 3), (y, 4), (5,), [], x)) assert cse(eq) == ([], [eq]) @@ -251,9 +251,9 @@ def test_issue_4499(): from sympy import Tuple, S B = Function('B') # noqa G = Function('G') # noqa - t = Tuple(* - (a, a + S(1)/2, 2*a, b, 2*a - b + 1, (sqrt(z)/2)**(-2*a + 1)*B(2*a - - b, sqrt(z))*B(b - 1, sqrt(z))*G(b)*G(2*a - b + 1), + t = Tuple( + *(a, a + S(1)/2, 2*a, b, 2*a - b + 1, (sqrt(z)/2)**(-2*a + 1)*B(2*a + - b, sqrt(z))*B(b - 1, sqrt(z))*G(b)*G(2*a - b + 1), sqrt(z)*(sqrt(z)/2)**(-2*a + 1)*B(b, sqrt(z))*B(2*a - b, sqrt(z))*G(b)*G(2*a - b + 1), sqrt(z)*(sqrt(z)/2)**(-2*a + 1)*B(b - 1, sqrt(z))*B(2*a - b + 1, sqrt(z))*G(b)*G(2*a - b + 1), diff --git a/test/test_matrixgen.py b/test/test_matrixgen.py index 01ebaa0e..2c07b40a 100644 --- a/test/test_matrixgen.py +++ b/test/test_matrixgen.py @@ -251,8 +251,8 @@ def test_p2p_direct(ctx_getter, exclude_self, factor, lpot_id): index_set = index_set.get(queue) for i in range(index_set.nblocks): - assert la.norm(index_set.block_take(blk, i) - - index_set.take(mat, i)) < eps + assert la.norm(index_set.block_take(blk, i) + - index_set.take(mat, i)) < eps # You can test individual routines by typing -- GitLab