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

Allow nested lists to be passed into genned code #263

Open bradley-solliday-skydio opened 2 years ago

bradley-solliday-skydio commented 2 years ago

This is done by adding sym.util.check_matrix_size_and_numpify and calling it on the matrix inputs (when use_numba=False and reshape_vectors=True). This function converts list arguments to ndarrays and checks that the shape is what is expected.

Note, numpy only raises a deprecation warning if a ragged nested list is passed in.

If use_numba=True, just performs an inline check on the shape of the input, raising an IndexError if it is not what was expected. It never performs a reshape on matrix arguments.

Also adds the type alias sym.util.MatrixType and sym.util.VectorType. This is to make the type annotations less verbose.