diff --git a/setup.py b/setup.py index 5e2bcf7441b32f66df1bb0e79913f4bb17c1d600..6e49b1c8c6801ecd7183fb0d70371a214a6271c6 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os from setuptools import setup @@ -35,8 +34,7 @@ def find_git_revision(tree_root): (git_rev, _) = p.communicate() import sys - if sys.version_info >= (3,): - git_rev = git_rev.decode() + git_rev = git_rev.decode() git_rev = git_rev.rstrip() diff --git a/sumpy/codegen.py b/sumpy/codegen.py index 40a5df57bcdd43b7d42db53fcb7da2001958ed97..ffcf445f8d4bda2b3cbe7a8e3e0fffba7e4bc387 100644 --- a/sumpy/codegen.py +++ b/sumpy/codegen.py @@ -692,7 +692,7 @@ def to_loopy_insns(assignments, vector_names=frozenset(), pymbolic_expr_maps=(), assignments = [(name, convert_expr(name, expr)) for name, expr in assignments] from pytools import UniqueNameGenerator - name_gen = UniqueNameGenerator(set([name for name, expr in assignments])) + name_gen = UniqueNameGenerator({name for name, expr in assignments}) result = [] bessel_sub = BesselSubstitutor( diff --git a/sumpy/e2e.py b/sumpy/e2e.py index 550cb17339b20fbec15dabcb26b6c27151c9dd70..dac3e174074e8075f753ad70d44ef1311d311fa4 100644 --- a/sumpy/e2e.py +++ b/sumpy/e2e.py @@ -180,7 +180,7 @@ class E2EFromCSR(E2EBase): from sumpy.codegen import to_loopy_insns return to_loopy_insns( sac.assignments.items(), - vector_names=set(["d"]), + vector_names={"d"}, pymbolic_expr_maps=[self.tgt_expansion.get_code_transformer()], retain_names=tgt_coeff_names, ) @@ -336,7 +336,7 @@ class M2LUsingTranslationClassesDependentData(E2EFromCSR): from sumpy.codegen import to_loopy_insns return to_loopy_insns( sac.assignments.items(), - vector_names=set(["d", "src_coeffs", "data"]), + vector_names={"d", "src_coeffs", "data"}, pymbolic_expr_maps=[self.tgt_expansion.get_code_transformer()], retain_names=tgt_coeff_names, complex_dtype=to_complex_dtype(result_dtype), @@ -550,7 +550,7 @@ class M2LGenerateTranslationClassesDependentData(E2EBase): from sumpy.codegen import to_loopy_insns return to_loopy_insns( sac.assignments.items(), - vector_names=set(["d"]), + vector_names={"d"}, pymbolic_expr_maps=[self.tgt_expansion.get_code_transformer()], retain_names=tgt_coeff_names, complex_dtype=to_complex_dtype(result_dtype), @@ -671,7 +671,7 @@ class M2LPreprocessMultipole(E2EBase): from sumpy.codegen import to_loopy_insns return to_loopy_insns( sac.assignments.items(), - vector_names=set(["d"]), + vector_names={"d"}, pymbolic_expr_maps=[self.tgt_expansion.get_code_transformer()], retain_names=preprocessed_src_coeff_names, complex_dtype=to_complex_dtype(result_dtype), @@ -780,7 +780,7 @@ class M2LPostprocessLocal(E2EBase): from sumpy.codegen import to_loopy_insns return to_loopy_insns( sac.assignments.items(), - vector_names=set(["d"]), + vector_names={"d"}, pymbolic_expr_maps=[self.tgt_expansion.get_code_transformer()], retain_names=tgt_coeff_names, complex_dtype=to_complex_dtype(result_dtype), diff --git a/sumpy/expansion/local.py b/sumpy/expansion/local.py index 493e70456f89c38951a19ffea1bf654dd8d3dec6..145a043b8302cf217254cb2c3898acf9a65315fd 100644 --- a/sumpy/expansion/local.py +++ b/sumpy/expansion/local.py @@ -414,8 +414,8 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): order=self.order + src_expansion.order, max_mi=tuple(max_mi)) srcplusderiv_full_coeff_ids = \ srcplusderiv_terms_wrangler.get_full_coefficient_identifiers() - srcplusderiv_ident_to_index = dict((ident, i) for i, ident in - enumerate(srcplusderiv_full_coeff_ids)) + srcplusderiv_ident_to_index = {ident: i for i, ident in + enumerate(srcplusderiv_full_coeff_ids)} # The vector has the kernel derivatives and depends only on the distance # between the two centers @@ -458,8 +458,8 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): src_rscale): circulant_matrix_mis, needed_vector_terms, max_mi = \ self._m2l_translation_classes_dependent_data_mis(src_expansion) - circulant_matrix_ident_to_index = dict((ident, i) for i, ident in - enumerate(circulant_matrix_mis)) + circulant_matrix_ident_to_index = {ident: i for i, ident in + enumerate(circulant_matrix_mis)} # Calculate the input vector for the circulant matrix input_vector = [0] * len(circulant_matrix_mis) @@ -483,8 +483,8 @@ class VolumeTaylorLocalExpansionBase(LocalExpansionBase): tgt_rscale, sac): circulant_matrix_mis, needed_vector_terms, max_mi = \ self._m2l_translation_classes_dependent_data_mis(src_expansion) - circulant_matrix_ident_to_index = dict((ident, i) for i, ident in - enumerate(circulant_matrix_mis)) + circulant_matrix_ident_to_index = {ident: i for i, ident in + enumerate(circulant_matrix_mis)} if self.use_fft_for_m2l: n = len(circulant_matrix_mis) diff --git a/sumpy/expansion/multipole.py b/sumpy/expansion/multipole.py index 7a567cefee9f0f6ac1ab1dc9888793d5921e6288..112c719013a2189bca1d8635aab499746b37745c 100644 --- a/sumpy/expansion/multipole.py +++ b/sumpy/expansion/multipole.py @@ -299,8 +299,8 @@ class VolumeTaylorMultipoleExpansionBase(MultipoleExpansionBase): # {{{ simpler, functionally equivalent code if not _fast_version: - src_mi_to_index = dict((mi, i) for i, mi in enumerate( - src_expansion.get_coefficient_identifiers())) + src_mi_to_index = {mi: i for i, mi in enumerate( + src_expansion.get_coefficient_identifiers())} result = [0] * len(self.get_full_coefficient_identifiers()) for i, mi in enumerate(src_expansion.get_coefficient_identifiers()): diff --git a/sumpy/kernel.py b/sumpy/kernel.py index 6d84c5aaa7d04e0e9c9bde490971aae281770e49..a2b6baa8798ca373bfd56ebdd9993a0188c1fc1a 100644 --- a/sumpy/kernel.py +++ b/sumpy/kernel.py @@ -645,9 +645,9 @@ class ElasticityKernel(ExpressionKernel): def __new__(cls, dim, icomp, jcomp, viscosity_mu="mu", poisson_ratio="nu"): if poisson_ratio == 0.5: - instance = super(ElasticityKernel, cls).__new__(StokesletKernel) + instance = super().__new__(StokesletKernel) else: - instance = super(ElasticityKernel, cls).__new__(cls) + instance = super().__new__(cls) return instance def __init__(self, dim, icomp, jcomp, viscosity_mu="mu", poisson_ratio="nu"): diff --git a/sumpy/tools.py b/sumpy/tools.py index 669a3d63321f79972c5f39d14c90ca9b5fb46fc4..b43dedbf2717b7a57ceeecbc38ccc20b83d696ad 100644 --- a/sumpy/tools.py +++ b/sumpy/tools.py @@ -102,7 +102,7 @@ def add_to_sac(sac, expr): return sym.Symbol(name) -class ExprDerivativeTaker(object): +class ExprDerivativeTaker: """Facilitates the efficient computation of (potentially) high-order derivatives of a given :mod:`sympy` expression *expr* while attempting to maximize the number of common subexpressions generated. @@ -233,7 +233,7 @@ class LaplaceDerivativeTaker(ExprDerivativeTaker): """ def __init__(self, expr, var_list, rscale=1, sac=None): - super(LaplaceDerivativeTaker, self).__init__(expr, var_list, rscale, sac) + super().__init__(expr, var_list, rscale, sac) self.scaled_var_list = [add_to_sac(self.sac, v/rscale) for v in var_list] self.scaled_r = add_to_sac(self.sac, sym.sqrt(sum(v**2 for v in self.scaled_var_list))) @@ -302,7 +302,7 @@ class RadialDerivativeTaker(ExprDerivativeTaker): Takes the derivatives of a radial function. """ import sumpy.symbolic as sym - super(RadialDerivativeTaker, self).__init__(expr, var_list, rscale, sac) + super().__init__(expr, var_list, rscale, sac) empty_mi = (0,) * len(var_list) self.cache_by_mi_q = {(empty_mi, 0): expr} self.r = sym.sqrt(sum(v**2 for v in var_list)) @@ -702,7 +702,7 @@ class OrderedSet(MutableSet): def __repr__(self): if not self: return f"{self.__class__.__name__}()" - return "{}({!r})".format(self.__class__.__name__, list(self)) + return f"{self.__class__.__name__}({list(self)!r})" def __eq__(self, other): if isinstance(other, OrderedSet): diff --git a/test/test_kernels.py b/test/test_kernels.py index 363e3e30dc1c3a661c0c4c8a233805abf008a68e..cfc62ea7c40ad48e5940fbde48f998a00d2bbbf0 100644 --- a/test/test_kernels.py +++ b/test/test_kernels.py @@ -854,7 +854,7 @@ def test_m2l_toeplitz(): actual_output = local_expn.translate_from(mpole_expn, src_coeff_exprs, src_rscale, dvec, tgt_rscale, sac=None) - replace_dict = dict((d, np.random.rand(1)[0]) for d in dvec) + replace_dict = {d: np.random.rand(1)[0] for d in dvec} for sym_a, sym_b in zip(expected_output, actual_output): num_a = sym_a.xreplace(replace_dict) num_b = sym_b.xreplace(replace_dict) diff --git a/test/test_misc.py b/test/test_misc.py index 88c9f385247a7c690ce644a00d83fe9531de91a3..d10278b1d0f2e2b5170abbc1467afdc0f51cbc65 100644 --- a/test/test_misc.py +++ b/test/test_misc.py @@ -332,7 +332,7 @@ def test_diff_op_stokes(): actual_output = pde.to_sym() x, y, z = syms = symbols("x0, x1, x2") funcs = symbols("f0, f1, f2, f3", cls=Function) - u, v, w, p = [f(*syms) for f in funcs] + u, v, w, p = (f(*syms) for f in funcs) eq1 = u.diff(x, x) + u.diff(y, y) + u.diff(z, z) - p.diff(x) eq2 = v.diff(x, x) + v.diff(y, y) + v.diff(z, z) - p.diff(y) diff --git a/test/test_tools.py b/test/test_tools.py index 018a95ed9e727e806da34f47d45fd7d22c88f222..a3d2a9f1a5d476cf2a109869ae52174203f948df 100644 --- a/test/test_tools.py +++ b/test/test_tools.py @@ -1,5 +1,3 @@ -from __future__ import division, absolute_import, print_function - __copyright__ = "Copyright (C) 2020 Isuru Fernando" __license__ = """