There are several ways to inline in Python
Besides numba
and similar JIT compilers ( which retain their own inline caches ), that may help you in JIT-code-reuse, as you denoted in numerous re-call of the unspecified function,
there are several ways how to inline into Python code.
Inline symbolic x86 ASM
assembly language into python
from pyasm import Program
from pyasm.data import String
from pyasm.macro import syscall
from pyasm.instructions import mov, ret, push, add
from pyasm.registers import eax, ebx, ecx, edx, ebp
import sys
def example():
msg = 'Hello World!'
prog = Program( # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
#
### ASSUME NOTHING - a lovely ASM note to always remember & self.remind
mov(ebx, 1),
mov(ecx, String(msg)),
mov(edx, len(msg)),
syscall('write'),
ret(),
# _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
)
fun = prog.compile()
fun()
if __name__ == '__main__':
example()
Inline almost c
language into python
from pycca.cc import CCode, Function, Assign, Return
code = CCode( [ Function( 'int', 'add_one', [( 'int', 'x' )],
[
Assign( x='x + 1' ),
Return('x')
])
])
print code.dump_asm()
print "3 + 1 = %d" % code.add_one( 3 )
For details & other options look at >>> this
Inline c
language into python
( since 2001 )
import PyInline, __main__
m = PyInline.build( language = "C",
targetmodule = __main__,
code = """
/*_______________________________WORLDS-OF-C*/
double my_C_adder( double a, double b )
{
return a + b;
}
/*_______________________________WORLDS-OF-C*/
"""
)
print my_C_adder( 4.5, 5.5 ) # Should print out "10.0"
Another approach at >>> PyInline