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.- Parameters:
config (codegen_config.CodegenConfig) –
inputs (Values) –
outputs (Values) –
return_key (T.Optional[str]) –
sparse_matrices (dataclasses.InitVar[T.Iterable[str]]) –
- config: codegen_config.CodegenConfig#
- static from_codegen(co)[source]#
Returns the
SimilarityIndex
of aCodegen
object.If co1 and co2 are two
Codegen
objects, thenfrom_codegen(co1) == from_codegen(co2)
if and only if the function generated byco1.generate_function()
is the same as that ofco2.generate_function()
(up to differences in function name and docstrings).- Parameters:
co (Codegen) –
- Return type:
- __hash__()[source]#
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: