You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the existing issues and didn't find my feature already requested there
Feature description
Currently, the easiest way to serialize numpy.ndarrays using cbor2 is something like (neglecting error checks)
import numpy as np
import cbor2
x = np.ones(10)
y = cbor2.dumps(x, default=lambda x, y: x.encode(y.tolist()))
This requires numpy to traverse the array and convert it to a Python list, which is then handed off to cbor2 for another traversal - there are several traversals and transient allocations involved.
Because both Numpy and CBOR have clean C APIs, would you consider a direct conversion implemented in the C extension module? It's worth noting that the orjson JSON library does this already.
Use case
Low-overhead serialization of numpy arrays.
The text was updated successfully, but these errors were encountered:
The combination of (1) and (2) seems ideal, with (1) as a fastpath and (2) as a fallback. I'm optimistic Python ndarrays carry enough type metadata to decide between them without traversing the array.
(3) seems easy to rule out, and I'm only including it to say so out loud.
Things to check first
Feature description
Currently, the easiest way to serialize numpy.ndarrays using cbor2 is something like (neglecting error checks)
This requires numpy to traverse the array and convert it to a Python list, which is then handed off to cbor2 for another traversal - there are several traversals and transient allocations involved.
Because both Numpy and CBOR have clean C APIs, would you consider a direct conversion implemented in the C extension module? It's worth noting that the orjson JSON library does this already.
Use case
Low-overhead serialization of numpy arrays.
The text was updated successfully, but these errors were encountered: