python-blosc icon indicating copy to clipboard operation
python-blosc copied to clipboard

Use memoryview.itemsize if no default provided

Open mrocklin opened this issue 9 years ago • 3 comments

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'

mrocklin avatar Oct 24 '16 18:10 mrocklin

If you think that is useful, pull-requests will be accepted. :+1:

esc avatar Oct 24 '16 18:10 esc

@mrocklin I would implement this next perhaps, will it still be of value to you?

esc avatar Nov 18 '18 19:11 esc

Not of concrete value, no. I specify this myself. I think it is a sensible default for the project though.

mrocklin avatar Nov 18 '18 19:11 mrocklin

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.

FrancescAlted avatar Dec 07 '22 17:12 FrancescAlted