jacinle.jit.cython.jit_compile#
Classes
Functions
|
JIT compile a simple Python function with Cython. |
Class CythonCompiledFunction
Class CythonJITCompiler
- class CythonJITCompiler[source]#
Bases:
object
- __new__(**kwargs)#
- all_funcs = {}#
- args_re = re.compile("([a-zA-Z_][a-zA-Z_0-9]*)( )*:( )*'?(([a-zA-Z_][a-zA-Z_0-9]*\\.)*([a-zA-Z_][a-zA-Z_0-9]*))(\\[.*?\\])?'?", re.MULTILINE)#
- cdef_function_re = re.compile("^([ \t]*)def (.*?)( )*->( )*'?(([a-zA-Z_][a-zA-Z_0-9]*\\.)*([a-zA-Z_][a-zA-Z_0-9]*))'?(\\[.*?\\])?", re.MULTILINE)#
- cdef_re = re.compile("^([ \t]+)([a-zA-Z_][a-zA-Z_0-9]*)( )*:( )*'?(([a-zA-Z_][a-zA-Z_0-9]*\\.)*([a-zA-Z_][a-zA-Z_0-9]*))(\\[.*?\\])?'?", re.MULTILINE)#
- decorator_cleanup_re = re.compile('^([ \t]*)@jit_cython.*\n', re.MULTILINE)#
- dependency_visitor = <jacinle.jit.cython.jit_compile._DependencyNodeVisitor object>#
- setup_template = "\nfrom setuptools import setup, Extension\nimport numpy as np\n\nsetup(\n name='{func_name}',\n ext_modules=[\n Extension('{func_name}', sources=['{func_name}.pyx'], include_dirs=[np.get_include()], annotate=True)\n ]\n)\n"#
- source_header = '\nimport numpy as np\ncimport numpy as np\ncimport cython\n'#
Functions
- jit_cython(f=None, *, name=None, force_update=False, boundscheck=True, wraparound=True)[source]#
JIT compile a simple Python function with Cython. Currently, only support functions with built-in Python functions and numpy operations (and arrays). This function uses Python annotations to determine the types of the arguments and return values. Therefore, to maximize performance, you should try to annotate all arguments and variables used. See examples/cython/jit_example.py for more details.
Example
@jit_cython(boundscheck=False, wraparound=False) def f(x: int): return x + 1 @jit_cython def sum(x: np.ndarray, n: int): i: int s: float = 0.0 for i in range(n): s += x[i] return s