symforce.codegen.similarity_index module#

class SimilarityIndex(config, inputs, outputs, return_key, sparse_matrices)[source]#

Bases: object

Contains all the information needed to assess if two Codegen objects would generate the same function, modulo function name and docstring.

WARNING: SimilarityIndex is hashable despite being mutable. This means you should be careful when storing it as a key of a dict, as ordinary keys are immutable.

config: codegen_config.CodegenConfig#
inputs: Values#
outputs: Values#
return_key: T.Optional[str]#
sorted_sparse_matrices: T.Tuple[str, ...]#
sparse_matrices: dataclasses.InitVar[T.Iterable[str]]#
static from_codegen(co)[source]#

Returns the SimilarityIndex of a Codegen object.

If co1 and co2 are two Codegen objects, then from_codegen(co1) == from_codegen(co2) if and only if the function generated by co1.generate_function() is the same as that of co2.generate_function() (up to differences in function name and docstrings).


co (Codegen) –

Return type:



WARNING: SimilarityIndex is mutable, and you must be mindful of the fact that keys of dicts are supposed to be immutable.

If seeking to use a SimilarityIndex in a dict as a key, encapsulate this to make sure others aren’t able to modify the object after it has been hashed.

Return type: