Allow nested lists to be passed into genned code#263
Open
bradley-solliday-skydio wants to merge 1 commit intogenerated_code_accepts_listsfrom
Open
Allow nested lists to be passed into genned code#263bradley-solliday-skydio wants to merge 1 commit intogenerated_code_accepts_listsfrom
bradley-solliday-skydio wants to merge 1 commit intogenerated_code_accepts_listsfrom
Conversation
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.
aaron-skydio
reviewed
Nov 4, 2022
Member
aaron-skydio
left a comment
There was a problem hiding this comment.
Just one comment about the type aliases, otherwise looks good
| @@ -8,14 +8,17 @@ | |||
|
|
|||
Member
There was a problem hiding this comment.
typing is not a builtin package in python 2. We could add it as a depenency of sym or something, but that seems like a bummer. I'm not actually sure what a good approach would be here - maybe @eric-skydio has ideas? For context we have this mildly-complicated type that we'd like an alias for, but ideally we don't add a runtime dependency on typing from this module (sym)
Noting that the import is actually added here, although it isn't necessary at runtime in that PR.
| ) | ||
| ) | ||
|
|
||
| return array No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is done by adding
sym.util.check_matrix_size_and_numpifyand calling it on the matrix inputs (whenuse_numba=Falseandreshape_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 anIndexErrorif it is not what was expected. It never performs a reshape on matrix arguments.Also adds the type alias
sym.util.MatrixTypeandsym.util.VectorType. This is to make the type annotations less verbose.