General Computing
regex find-and-replace tabs indentation indent
Updated Mon, 03 Oct 2022 12:28:23 GMT

Find and replace in Notepad++: How to insert above line with same amount of indents?


I need to replace, in a large number of Python files with many function definitions, all occurrences of

def some_func(foo, bar):

with

@jit(parallel=True)
def some_func(foo, bar):

with whatever level of indentation def some_func(foo, bar) has.

Example: I want to replace

def some_func_1(foo, bar):
    def some_func_2(foo, bar):
        def some_func_3(foo, bar):
def some_func_4(foo, bar):

with

@jit(parallel=True)
def some_func_1(foo, bar):
    @jit(parallel=True)
    def some_func_2(foo, bar):
        @jit(parallel=True)
        def some_func_3(foo, bar):
@jit(parallel=True)
def some_func_4(foo, bar):

Motivation: I want to "brute-force accelerate/parallelize" a FDTD simulation package without having to rewrite the entire codebase by making use of numba's automatic parallelization with @jit.

PS.: Any comment/critique of this naive approach of (ab)using @jit is also welcome (e.g. if this wouldn't work at all)!




Solution

A better solution may be using jit_module to jit all your functions automatically





Comments (1)

  • +1 – It may be a better solution to this particular problem, but long term learning a bit of Regex is a better solution. — Jul 26, 2022 at 03:47