symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

Use Codegen.name as python function name #311

Closed bradley-solliday-skydio closed 1 year ago

bradley-solliday-skydio commented 1 year ago

BREAKING CHANGE: User generated python function names will change.

Previously we would call symforce.python_util.camelcase_to_snakecase on the name of a Codegen object to use as the name of the generated function. Meanwhile, we would use the name of the Codegen object, unmodified, as the name of the python file (unless the generated_file_name argument is provided to Codegen.generate_function, in which case we use that).

Unfortunately, in a number of places (like in numeric_factor.py and factor.py) we assume that the name of the generated function matches the name of the generated file it lives in. (Resulting in things breaking if the name of the Codegen object is not already in snake_case).

An example of this is Factor.generate.

To address this, in this commit I change the jinja template to use the Codegen.name as the generated function name. This way, in the default case, the generated function will match the file name. It also has the benefit of offering the user more flexibility to set the name of their generated functions.

Note, if Codegen.with_linearization is used, _factor is appended to all names (so you might end up with a residual whose name and file is CamelCase_factor).

Fixes: #299

Topic: issue_299

bradley-solliday-skydio commented 1 year ago

Reviews in this chain: └https://github.com/symforce-org/symforce/pull/311 Use Codegen.name as python function name

bradley-solliday-skydio commented 1 year ago
# head base diff date summary
0 5265f465 d8056975 diff Mar 13 18:18 PM 4 files changed, 26 insertions(+), 3 deletions(-)
1 8f3f4114 d8056975 diff Mar 13 18:19 PM 0 files changed
2 94b4b997 d8056975 diff Mar 14 18:20 PM 1 file changed, 4 insertions(+), 2 deletions(-)