Skip to content

User-defined dtype (non-PyObject) in C needing destructors / deallocation? #10721

@EricCousineau-TRI

Description

@EricCousineau-TRI

Is it possible to define a non-PyObject data type which needs custom element-wise destruction?

We are specifically interested in this for an autodiff scalar, with a dynamic number of gradients -- and also a symbolic expression tree, but I'd assume they're somewhat similar.

We are currently using pybind11 for our code base, and have used NPY_OBJECT for these types, which does the job decently well until we want to have buffer views into our data.

Using a custom dtype seems to permit us to have these custom buffer views, based on tinkering I've done with numpy.core.test_rational.rational (using v1.11.0, but not seeing much change elsewhere for master).

However, it's not clear to me how I can signal a "cleanup" of an array, e.g. when resizing or when the array goes out of scope. In looking through the code and doc, there are mechanism in place for reference counting object- and record-type arrays, but nothing w.r.t. custom data structures.

Relates RobotLocomotion/drake#8116

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions