Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nested lists to be passed into genned code #263

Open
wants to merge 1 commit into
base: generated_code_accepts_lists
Choose a base branch
from

Conversation

bradley-solliday-skydio
Copy link
Collaborator

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.

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.
Copy link
Member

@aaron-skydio aaron-skydio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment about the type aliases, otherwise looks good

@@ -8,14 +8,17 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants