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

numpy: Request for user-defined types? (beyond structured dtypes and dtype=object) #2259

Open
EricCousineau-TRI opened this issue Jun 21, 2020 · 0 comments

Comments

@EricCousineau-TRI
Copy link
Collaborator

EricCousineau-TRI commented Jun 21, 2020

I realized that I didn't create an upstream issue, so I'm placing this here.

Background for NumPy

Basically, NumPy can allow to do custom dtypes through 3 different mechanisms (that I'm aware of):

  1. Structured Types (pybind11 documentation)
  2. dtype=object - see this PR: Add ability to create object matrices #1152
  3. User-defined dtypes: See NumPy issue: User-defined dtype (non-PyObject) in C needing destructors / deallocation? numpy/numpy#10721 (there may be better docs, but I need to find 'em...)

The focus of this issue supporting (3).

(TODO for myself: Replace above issue links with NumPy / pybind11 docs)

Current State for pybind11

pybind11 itself already supports (1):
https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#structured-types

Supporting (2) was done by Robin Deits, we have refined it in our RobotLocomotion/pybind11 fork, and have made an upstream PR to pybind11 in #1152.

Supporting (3) is a bit of a finicky problem, as alluded in numpy/numpy#10721.
Motivated by RobotLocomotion/drake#8116, I made an old prototype / integration branch here: RobotLocomotion/drake#8452

Related pybind11 issues / PRs:

I also have not revisited this in about ~1.5 years, may come back around to it.

FTR @eric-wieser has provided some suggestions and workarounds on some of the related threads. I'll admit that I haven't yet had time to process them to a full extent, and will post here once I am able. (Sorry Eric!)

@EricCousineau-TRI EricCousineau-TRI changed the title numpy: Request for user-defined types? (not dtype=object) numpy: Request for user-defined types? (not structured dtypes nor dtype=object) Jun 21, 2020
@EricCousineau-TRI EricCousineau-TRI changed the title numpy: Request for user-defined types? (not structured dtypes nor dtype=object) numpy: Request for user-defined types? (beyond structured dtypes and dtype=object) Jun 21, 2020
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

No branches or pull requests

1 participant