-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
pydrake: Support user-defined dtype for AutoDiffXd
and Expression
#8116
Comments
Self notes:
Current plan:
Issues:
|
Posted an update here: #8315 (comment) Take away is, this seems to be possible, modulo incurring some memory leaks from the NumPy side, per numpy/numpy#10721. There may be some ways around them, but no ways that should affect functionality (as long as we're not depending on the lifetime of our scalars). |
Follow-up response from #8392 (
Understood that we do not want bleeding-edge versions, definitely for something as popular for My intent is to do these optional non-API-changing patches until the feature itself reaches upstream The specific patch I'd want to implement is to address numpy/numpy#10721. |
@EricCousineau-TRI I guess I'm not completely clear on what you're proposing for Drake master as it relates to numpy. If there are affordances where power users can set their If the proposal is to have the default build incorporate such fixes, then I am skeptical that everyone else would be able to ignore what's going on and have the work only fall on your shoulders. If you have a draft commit with what the changes to Drake would look like, that might clear things up for me about what kind of complexity we are talking about. I don't think any of this prevents you from pushing a bug fix to upstream, but whether and how Drake uses that is the question. Maybe I should wait for an draft of the Drake changes before trying to speculate more? |
I agree with @jwnimmer-tri, though my dislike of forks and patches may even be greater. Something would have to be absolutely and undisputedly critical for a patch of something to be justified, other it is opening us up to maintenance and compatibility problems for very moderate gain. I already feel like we are digging ourselves in a hole with pybind11. In most cases, I would say patch upstream and wait or make alternative plans. |
AutoDiffXd
and Expression
AutoDiffXd
and Expression
AutoDiffXd
and Expression
AutoDiffXd
and Expression
(Personal acct) Was looking at pybind/pybind11#1731, and stumbled across this: (At a glance, though, it doesn't seem to interface with NumPy UFunc objects; instead, it just writes its own???) |
@EricCousineau-TRI a could months ago you changed this from team "kitware" to "manipulation". It seems like a pydrake / bindings question, so should be "kitware"? Or did I misunderstand? |
Er... I don't remember... Happy to switch it back. |
Checking in on this one. I'm writing lots of trajectory optimization code for underactuated right now that looks like e.g.:
I believe that this is the issue that would support adding constraints with the array-type |
No blockers, just haven't upped it in the priority queue. Want me to schedule this for Q2? |
yes, please, if it fits. i think it would add a lot of value. |
Note that our minimum required version of |
EDIT(2020/07/11): Making another top-level summary:
This is one way to achieve reference semantics between C++ and Python for custom dtypes (between Eigen and NumPy), and also some slightly more concrete behavior than what
dtype=object
offers.Eric Weister has suggested some ways to override the container (I think), but I had yet to visit that - this will probably be the best way to achieve what I want, I think?
Overall, this has dropped in priority just b/c using
dtype=object
is sufficiently workable for now, but I would love to revisit this once I have the time.EDIT(2020/06/21): Made upstream issue: pybind/pybind11#2259
Per this comment:
pybind/pybind11#1152 (comment)
We can return
Eigen::Ref<>
inpybind
which, if it has a reference return-value-policy and has a parent, will be converted to anumpy.ndarray
which is a view to the original data (not a copy of the data). This holds for both immutable and mutable references.However, custom object data types are presently cast using the effective equivalent of
np.array(..., dtype=object)
, which means the matrix data as a whole will not be aliased.Resolution is to (a) see if there's a way to do the custom NumPy data types. If that is not feasible, then (b)
pydrake
should change its semantics to always "mutate" using parent container mutators / return values (which requries extra copying - blech).Relates #7660, specifically for transmogrification, supporting AutoDiffXd, Symbolic, etc.
PR breakdown (as of 2019-01-28), in order:
pybind11
autodiff
as user-defined typeRelates:
e_xv == e_yv
? #10411np.sqrt(AutoDiffXd(0.))
encounters divide-by-zero warning #10451The text was updated successfully, but these errors were encountered: