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

Always raise IndexError if wrong shape genned code #250

Closed bradley-solliday-skydio closed 1 year ago

bradley-solliday-skydio commented 1 year ago

Currently, if the reshape_vectors field of the PythonConfig is True and use_numba is False, the only way an IndexError will be raised from generated code is if an out of bounds index is used on one of the inputs.

Consequently, this means that if you pass in a vector which is large enough (say, a row vector where a column vector is needed, but only the first entry of the column vector is needed), the code will silently work.

This is probably not what the user would want, and is inconsistent with what we do when use_numba=True (where we check that the input shape is exactly something allowed).

So, I've changed the generated code use_numba=False code to be more analagous to the use_numba=True code.

Other notes: