Skip to content

Commit 3e543e8

Browse files
[SymForce-External] Always raise IndexError if wrong shape genned code
Always raise IndexError if wrong shape genned code 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: - I also moved the jinja code for checking the array size and reshaping if appropriate to a seperate macro (`check_size_and_reshape`). This was purely for readability. - In the unit test I added, I only test with `reshape_vectors=True`. As a practical matter, I didn't test with `reshape_vectors=False` because our test infrastructure already present checks that the input vector of a function equals the output of a function. But if `reshape_vectors=False`, since the input is simply too large, the code silently works, producing an output of the correct size (i.e., smaller than the input vector, meaning they're not equal). I didn't want to go through the work of changing `assert_config_works` because it would make the function more complicated, and it seems strange to test that the function gives a "correct" output when you give it an invalid input. Closes #250 GitOrigin-RevId: b19c5ea8fa1967687dacf3e2fb6c39a9021f80e0
1 parent 6828030 commit 3e543e8

File tree

24 files changed

+409
-58
lines changed

24 files changed

+409
-58
lines changed

gen/python/sym/ops/atan_camera_cal/camera_ops.py

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/atan_camera_cal/lie_group_ops.py

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/double_sphere_camera_cal/camera_ops.py

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/double_sphere_camera_cal/lie_group_ops.py

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/equirectangular_camera_cal/camera_ops.py

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/equirectangular_camera_cal/lie_group_ops.py

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/linear_camera_cal/camera_ops.py

+28-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/python/sym/ops/linear_camera_cal/lie_group_ops.py

+14-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)