python-blosc
python-blosc copied to clipboard
Use memoryview.itemsize if no default provided
If I give blosc.compress a memoryview object it would be possible to learn the typesize automatically.
In [1]: import numpy as np
In [2]: x = np.ones(5, dtype='i4')
In [3]: x.data
Out[3]: <memory at 0x7fe710bf0408>
In [4]: x.data.itemsize
Out[4]: 4
In [5]: import blosc
In [6]: blosc.compress(x.data, typesize=x.data.itemsize)
Out[6]: b'\x02\x01\x13\x04\x14\x00\x00\x00\x14\x00\x00\x00$\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00'
If you think that is useful, pull-requests will be accepted. :+1:
@mrocklin I would implement this next perhaps, will it still be of value to you?
Not of concrete value, no. I specify this myself. I think it is a sensible default for the project though.
Closing after no activity for long time. FWIW, there is full support for views and objects supporting the buffer protocol in next-generation python-blosc2.