I mean in principle those suggestions are perfectly sensible and in terms of code running to completion, they make sense.
I just find very frustrating I can get bar
work if I write things out completely:
@jit
def baz(x, y):
# CUT CUT CUT
def bar(y):
# Do something with x and y
# potentially very long function
# that I might want to reuse somewhere else
return x + y
# CUT CUT CUT
s = 0
for i in range(10):
s += bar(y)
return s
but not if I want to extract it outside… even when forcing numba-side inline…
@jit(inline="always")
def foo(x):
def bar(y):
# Do something with x and y
# potentially very long function
# that I might want to reuse somewhere else
return x + y
return bar
@jit
def baz(x, y):
# CUT CUT CUT
bar = foo(x)
# CUT CUT CUT
s = 0
for i in range(10):
s += bar(y)
return s
With anything other than scalar types, LLVM cannot assume x
is gonna be constant throughout the loop and therefore won’t generate vectorised code (well maybe in reduction code like this). In the first instance, I don’t believe bar
will specialise over x
anyway (will just be inlined). The second case would force specialisation or at least might be enough from LLVM to understand x
is constant…