Skip to content

Blosc2 arrays should accept data from PyTorch/JAX/TensorFlow containers #512

@FrancescAlted

Description

@FrancescAlted

Right now, this is not the case:

import numpy as np
import blosc2
import torch

# Create an empty array
dset_out = blosc2.empty(shape=(10,), dtype=np.int64)

a = torch.from_numpy(np.arange(10))
dset_out[:] = np.asarray(a)  # this works
dset_out[:] = a   # this does not

output:

Traceback (most recent call last):
  File "/Users/faltet/blosc/python-blosc2/blosc2-torch-ingest.py", line 10, in <module>
    dset_out[:] = a   # this does not
    ~~~~~~~~^^^
  File "/Users/faltet/blosc/python-blosc2/src/blosc2/ndarray.py", line 4241, in __setitem__
    return super().set_slice((start, stop), value)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "blosc2/blosc2_ext.pyx", line 2544, in blosc2.blosc2_ext.NDArray.set_slice
TypeError: a bytes-like object is required, not 'Tensor'

Process finished with exit code 1

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions