diff --git a/pystencils/astnodes.py b/pystencils/astnodes.py index 7bce77e0dd99926d71ccbfc6bf2c5722e84c99f1..98c552e460364f70c70ee836b0a97ed873102b75 100644 --- a/pystencils/astnodes.py +++ b/pystencils/astnodes.py @@ -117,7 +117,7 @@ class Conditional(Node): if self.true_block: repr += '\n\t{}) '.format(self.true_block) if self.false_block: - repr = 'else: '.format(self.false_block) + repr = 'else: ' repr += '\n\t{} '.format(self.false_block) return repr @@ -421,7 +421,7 @@ class LoopOverCoordinate(Node): def new_loop_with_different_body(self, new_body): result = LoopOverCoordinate(new_body, self.coordinate_to_loop_over, self.start, self.stop, self.step, self.is_block_loop) - result.prefix_lines = [l for l in self.prefix_lines] + result.prefix_lines = [lo for lo in self.prefix_lines] return result def subs(self, subs_dict): diff --git a/pystencils/backends/cuda_backend.py b/pystencils/backends/cuda_backend.py index d590d65b4082e72745658f0b06eb152d64872944..393ececd660a5338ed95fea44e0360db7758f1b1 100644 --- a/pystencils/backends/cuda_backend.py +++ b/pystencils/backends/cuda_backend.py @@ -7,7 +7,7 @@ from pystencils.interpolation_astnodes import DiffInterpolatorAccess, Interpolat with open(join(dirname(__file__), 'cuda_known_functions.txt')) as f: lines = f.readlines() - CUDA_KNOWN_FUNCTIONS = {l.strip(): l.strip() for l in lines if l} + CUDA_KNOWN_FUNCTIONS = {lo.strip(): lo.strip() for lo in lines if lo} def generate_cuda(astnode: Node, signature_only: bool = False) -> str: diff --git a/pystencils/backends/opencl_backend.py b/pystencils/backends/opencl_backend.py index 3ab7f820ea30adebf584977625b2e559f897ca27..8df1fbc07bf5c6f6610b9b4e9dd8fc399d22937f 100644 --- a/pystencils/backends/opencl_backend.py +++ b/pystencils/backends/opencl_backend.py @@ -8,7 +8,7 @@ from pystencils.fast_approximation import fast_division, fast_inv_sqrt, fast_sqr with open(join(dirname(__file__), 'opencl1.1_known_functions.txt')) as f: lines = f.readlines() - OPENCL_KNOWN_FUNCTIONS = {l.strip(): l.strip() for l in lines if l} + OPENCL_KNOWN_FUNCTIONS = {lo.strip(): lo.strip() for lo in lines if lo} def generate_opencl(astnode: Node, signature_only: bool = False) -> str: diff --git a/pystencils/cpu/kernelcreation.py b/pystencils/cpu/kernelcreation.py index 38ce169af754fae27d80cadfa993ac83a03e0999..6c060fade5ff4ac300b8aa6d1947363286f0d923 100644 --- a/pystencils/cpu/kernelcreation.py +++ b/pystencils/cpu/kernelcreation.py @@ -177,8 +177,8 @@ def add_openmp(ast_node, schedule="static", num_threads=True, collapse=None, ass wrapper_block = ast.PragmaBlock('#pragma omp parallel' + threads_clause, body.take_child_nodes()) body.append(wrapper_block) - outer_loops = [l for l in filtered_tree_iteration(body, LoopOverCoordinate, stop_type=SympyAssignment) - if l.is_outermost_loop] + outer_loops = [lo for lo in filtered_tree_iteration(body, LoopOverCoordinate, stop_type=SympyAssignment) + if lo.is_outermost_loop] assert outer_loops, "No outer loop found" if assume_single_outer_loop and len(outer_loops) > 1: raise ValueError("More than one outer loop found, only one outer loop expected") @@ -194,7 +194,7 @@ def add_openmp(ast_node, schedule="static", num_threads=True, collapse=None, ass num_threads = multiprocessing.cpu_count() if loop_range is not None and loop_range < num_threads and not collapse: - contained_loops = [l for l in loop_to_parallelize.body.args if isinstance(l, LoopOverCoordinate)] + contained_loops = [lo for lo in loop_to_parallelize.body.args if isinstance(lo, LoopOverCoordinate)] if len(contained_loops) == 1: contained_loop = contained_loops[0] try: diff --git a/pystencils/cpu/vectorization.py b/pystencils/cpu/vectorization.py index 12b492cf452e27220b3013ac6339aeaf6073c051..8a30341f6f192e1851638bb3f3bc090f27bd5865 100644 --- a/pystencils/cpu/vectorization.py +++ b/pystencils/cpu/vectorization.py @@ -83,7 +83,7 @@ def vectorize_inner_loops_and_adapt_load_stores(ast_node, vector_width, assume_a """Goes over all innermost loops, changes increment to vector width and replaces field accesses by vector type.""" all_loops = filtered_tree_iteration(ast_node, ast.LoopOverCoordinate, stop_type=ast.SympyAssignment) inner_loops = [n for n in all_loops if n.is_innermost_loop] - zero_loop_counters = {l.loop_counter_symbol: 0 for l in all_loops} + zero_loop_counters = {lo.loop_counter_symbol: 0 for lo in all_loops} for loop_node in inner_loops: loop_range = loop_node.stop - loop_node.start @@ -95,7 +95,8 @@ def vectorize_inner_loops_and_adapt_load_stores(ast_node, vector_width, assume_a loop_node.stop = new_stop else: cutting_point = modulo_floor(loop_range, vector_width) + loop_node.start - loop_nodes = [l for l in cut_loop(loop_node, [cutting_point]).args if isinstance(l, ast.LoopOverCoordinate)] + loop_nodes = [lo for lo in cut_loop(loop_node, + [cutting_point]).args if isinstance(lo, ast.LoopOverCoordinate)] assert len(loop_nodes) in (0, 1, 2) # 2 for main and tail loop, 1 if loop range divisible by vector width if len(loop_nodes) == 0: continue diff --git a/pystencils/gpucuda/indexing.py b/pystencils/gpucuda/indexing.py index eb212119ac8505ac5bf4db3112ef645b8e793f80..f63541dfa2eaf2b48bf64c0754a367736187d327 100644 --- a/pystencils/gpucuda/indexing.py +++ b/pystencils/gpucuda/indexing.py @@ -206,8 +206,8 @@ class BlockIndexing(AbstractIndexing): sorted_block_size = sorted_block_size[:-1] result = list(block_size) - for l, bs in zip(reversed(layout), sorted_block_size): - result[l] = bs + for lo, bs in zip(reversed(layout), sorted_block_size): + result[lo] = bs return tuple(result[:len(layout)]) def max_threads_per_block(self): diff --git a/pystencils/kerncraft_coupling/kerncraft_interface.py b/pystencils/kerncraft_coupling/kerncraft_interface.py index 37a5109de80b0c975a5cb30043316e1c1e8e9e9e..d7380ff4f9c06da71ed2e81414e800e3aa3ed099 100644 --- a/pystencils/kerncraft_coupling/kerncraft_interface.py +++ b/pystencils/kerncraft_coupling/kerncraft_interface.py @@ -46,8 +46,8 @@ class PyStencilsKerncraftKernel(KernelCode): self._keep_intermediates = debug_print # Loops - inner_loops = [l for l in filtered_tree_iteration(ast, LoopOverCoordinate, stop_type=SympyAssignment) - if l.is_innermost_loop] + inner_loops = [lo for lo in filtered_tree_iteration(ast, LoopOverCoordinate, stop_type=SympyAssignment) + if lo.is_innermost_loop] if len(inner_loops) == 0: raise ValueError("No loop found in pystencils AST") else: diff --git a/pystencils/stencil.py b/pystencils/stencil.py index 359a0a29492c537957b8e24a952fa7e052ee898f..4f667b52d56645e7a083b15216f5a85d2842b7cf 100644 --- a/pystencils/stencil.py +++ b/pystencils/stencil.py @@ -179,7 +179,7 @@ def coefficient_list(expr, matrix_form=False): for i in range(-max_offsets[0], max_offsets[0] + 1)] for j in y_range] for k in range(-max_offsets[2], max_offsets[2] + 1)] - return [sp.Matrix(l) for l in result] if matrix_form else result + return [sp.Matrix(lo) for lo in result] if matrix_form else result else: raise ValueError("Can only handle fields with 1,2 or 3 spatial dimensions") diff --git a/pystencils/transformations.py b/pystencils/transformations.py index 5b44eb3e1b0b5c0622a4369bbcc8c77ebd16e616..86ce0c54dc64d66ce6893c51148079cdbf630e20 100644 --- a/pystencils/transformations.py +++ b/pystencils/transformations.py @@ -351,14 +351,14 @@ def get_base_buffer_index(ast_node, loop_counters=None, loop_iterations=None): base buffer index - required by 'resolve_buffer_accesses' function """ if loop_counters is None or loop_iterations is None: - loops = [l for l in filtered_tree_iteration(ast_node, ast.LoopOverCoordinate, ast.SympyAssignment)] + loops = [lo for lo in filtered_tree_iteration(ast_node, ast.LoopOverCoordinate, ast.SympyAssignment)] loops.reverse() parents_of_innermost_loop = list(parents_of_type(loops[0], ast.LoopOverCoordinate, include_current=True)) assert len(loops) == len(parents_of_innermost_loop) assert all(l1 is l2 for l1, l2 in zip(loops, parents_of_innermost_loop)) - loop_iterations = [(l.stop - l.start) / l.step for l in loops] - loop_counters = [l.loop_counter_symbol for l in loops] + loop_iterations = [(lo.stop - lo.start) / lo.step for lo in loops] + loop_counters = [lo.loop_counter_symbol for lo in loops] field_accesses = ast_node.atoms(AbstractField.AbstractAccess) buffer_accesses = {fa for fa in field_accesses if FieldType.is_buffer(fa.field)} @@ -659,11 +659,11 @@ def split_inner_loop(ast_node: ast.Node, symbol_groups): and which no symbol in a symbol group depends on, are not updated! """ all_loops = ast_node.atoms(ast.LoopOverCoordinate) - inner_loop = [l for l in all_loops if l.is_innermost_loop] + inner_loop = [lo for lo in all_loops if lo.is_innermost_loop] assert len(inner_loop) == 1, "Error in AST: multiple innermost loops. Was split transformation already called?" inner_loop = inner_loop[0] assert type(inner_loop.body) is ast.Block - outer_loop = [l for l in all_loops if l.is_outermost_loop] + outer_loop = [lo for lo in all_loops if lo.is_outermost_loop] assert len(outer_loop) == 1, "Error in AST, multiple outermost loops." outer_loop = outer_loop[0] @@ -1077,7 +1077,7 @@ def remove_conditionals_in_staggered_kernel(function_node: ast.KernelFunction, i """Removes conditionals of a kernel that iterates over staggered positions by splitting the loops at last or first and last element""" - all_inner_loops = [l for l in function_node.atoms(ast.LoopOverCoordinate) if l.is_innermost_loop] + all_inner_loops = [lo for lo in function_node.atoms(ast.LoopOverCoordinate) if lo.is_innermost_loop] assert len(all_inner_loops) == 1, "Transformation works only on kernels with exactly one inner loop" inner_loop = all_inner_loops.pop() @@ -1265,7 +1265,7 @@ def loop_blocking(ast_node: ast.KernelFunction, block_size) -> int: number of dimensions blocked """ loops = [ - l for l in filtered_tree_iteration( + lo for lo in filtered_tree_iteration( ast_node, ast.LoopOverCoordinate, stop_type=ast.SympyAssignment) ] body = ast_node.body