symforce-org / symforce

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

Swap out sm.sign in python for something efficient #76

Open aaron-skydio opened 2 years ago

aaron-skydio commented 2 years ago

The PythonCodePrinter spits out this nonsense for sign, because math.copysign(1, x) wouldn't give 0 for x == 0:

0.0 if x[4] - 1 == 0 else math.copysign(1, x[4] - 1)

When a lot of these are used like in logic.py it really blows up numba's compilation time; it would be nice if we could do something more efficient for those.