Skip to content

Add a way serialize arrays to string/bytes #963

@ev-br

Description

@ev-br

In data-apis/array-api-compat#345, a user wanted to json-serialize an Array API object. At the moment, this seems to require manually converting to a list of python int/float/bool objects.

For converting an array into a binary blob, we can export a DLPack capsule, but it does not seem to be serializable further:

In [28]: bytes(np.asarray([1, 2, 3]).__dlpack__())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[28], line 1
----> 1 bytes(np.asarray([1, 2, 3]).__dlpack__())

TypeError: cannot convert 'PyCapsule' object to bytes

Serialization was previously discussed in #266; the difference here is scope: I'm only proposing to add a way to byte-export a dlpack capsule.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions