symforce.codegen.codegen_config module

class ZeroEpsilonBehavior(value)[source]

Bases: Enum

Options for what to do when attempting to generate code with the default epsilon set to 0

FAIL = 0
WARN = 1
ALLOW = 2
class RenderTemplateConfig(autoformat=True, custom_preamble='')[source]

Bases: object

Arguments to template_util.render_template

Parameters:
  • autoformat (bool) – Run a code formatter on the generated code

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

autoformat: bool = True
custom_preamble: str = ''
__init__(autoformat=True, custom_preamble='')
Parameters:
  • autoformat (bool) –

  • custom_preamble (str) –

class CodegenConfig(doc_comment_line_prefix, line_length, use_eigen_types, render_template_config=<factory>, cse_optimizations=None, zero_epsilon_behavior=<factory>)[source]

Bases: object

Base class for backend-specific arguments for code generation.

Parameters:
  • doc_comment_line_prefix (str) – Prefix applied to each line in a docstring, e.g. “ * “ for C++ block-style docstrings

  • 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

  • render_template_config (RenderTemplateConfig) – Configuration for template rendering, see RenderTemplateConfig for more information

  • cse_optimizations (Union[Literal[‘basic’], Sequence[Tuple[Callable, Callable]], None]) – Optimizations argument to pass to sf.cse

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

doc_comment_line_prefix: str
line_length: int
use_eigen_types: bool
render_template_config: RenderTemplateConfig
cse_optimizations: Optional[Union[Literal['basic'], Sequence[Tuple[Callable, Callable]]]] = None
zero_epsilon_behavior: ZeroEpsilonBehavior
abstract 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:

str

abstract classmethod template_dir()[source]

Directory for jinja templates.

Return type:

Path

abstract templates_to_render(generated_file_name)[source]

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

Parameters:

generated_file_name (str) –

Return type:

List[Tuple[str, str]]

abstract printer()[source]

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

Return type:

CodePrinter

static format_data_accessor(prefix, index)[source]

Format data for accessing a data array in code.

Parameters:
  • prefix (str) –

  • index (int) –

Return type:

str

abstract 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]

Parameters:
  • key (str) –

  • i (int) –

  • j (int) –

  • shape (Tuple[int, int]) –

Return type:

str

abstract static format_eigen_lcm_accessor(key, i)[source]

Format accessor for eigen_lcm types.

Parameters:
  • key (str) –

  • i (int) –

Return type:

str

__init__(doc_comment_line_prefix, line_length, use_eigen_types, render_template_config=<factory>, cse_optimizations=None, zero_epsilon_behavior=<factory>)
Parameters:
  • doc_comment_line_prefix (str) –

  • line_length (int) –

  • use_eigen_types (bool) –

  • render_template_config (RenderTemplateConfig) –

  • cse_optimizations (Union[Literal[‘basic’], Sequence[Tuple[Callable, Callable]], None]) –

  • zero_epsilon_behavior (ZeroEpsilonBehavior) –