symforce.codegen.backends.python.python_config module#

class PythonConfig(doc_comment_line_prefix='', line_length=100, use_eigen_types=True, render_template_config=<factory>, cse_optimizations=None, zero_epsilon_behavior=<factory>, normalize_results=True, use_numba=False, reshape_vectors=True, return_2d_vectors=False)[source]#

Bases: CodegenConfig

Code generation config for the Python backend.

  • doc_comment_line_prefix (str) – Prefix applied to each line in a docstring

  • line_length (int) – Maximum allowed line length in docstrings; used for formatting docstrings.

  • use_eigen_types (bool) – Use eigen_lcm types for vectors instead of lists

  • autoformat – Run a code formatter on the generated code

  • custom_preamble – An optional string to be prepended on the front of the rendered template

  • cse_optimizations (Literal['basic'] | ~typing.Sequence[~typing.Tuple[~typing.Callable, ~typing.Callable]] | None) – Optimizations argument to pass to sf.cse

  • zero_epsilon_behavior (ZeroEpsilonBehavior) – What should codegen do if a default epsilon is not set?

  • normalize_results (bool) – Should function outputs be explicitly projected onto the manifold before returning?

  • use_numba (bool) – Add the @numba.njit decorator to generated functions. This will greatly speed up functions by compiling them to machine code, but has large overhead on the first call and some overhead on subsequent calls, so it should not be used for small functions or functions that are only called a handful of times. It also currently requires the the inputs and outputs of the function are scalars, vectors, or matrices.

  • reshape_vectors (bool) – Allow rank 1 ndarrays to be passed in for row and column vectors by automatically reshaping the input.

  • return_2d_vectors (bool) – Return all matrices as 2d ndarrays if True. If False and a matrix has either only 1 row or only 1 column, return as a 1d ndarray.

  • render_template_config (RenderTemplateConfig) –

doc_comment_line_prefix: str = ''#
line_length: int = 100#
use_eigen_types: bool = True#
use_numba: bool = False#
reshape_vectors: bool = True#
return_2d_vectors: bool = False#
classmethod backend_name()[source]#

String name for the backend. This should match the directory name in codegen/backends and will be used to namespace by backend in generated code.

Return type:


classmethod template_dir()[source]#

Directory for jinja templates.

Return type:



Given a single symbolic function’s filename, provide one or more Jinja templates to render and the relative output paths where they should go.


generated_file_name (str) –

Return type:

List[Tuple[str, str]]


Return an instance of the code printer to use for this language.

Return type:


format_matrix_accessor(key, i, j, *, shape)[source]#

Format accessor for 2D matrices.

Raises an index exception if either of the following is false:

0 <= i < shape[0]
0 <= j < shape[1]
Return type:


static format_eigen_lcm_accessor(key, i)[source]#

Format accessor for eigen_lcm types.

Return type: