Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to mpk (?) #8

Open
craffel opened this issue Apr 9, 2016 · 0 comments
Open

Switch to mpk (?) #8

craffel opened this issue Apr 9, 2016 · 0 comments

Comments

@craffel
Copy link
Owner

craffel commented Apr 9, 2016

Loading seems to be 10-50x faster than deepdish/h5, size is comparable to compressed h5, and types are preserved completely:

import msgpack
import msgpack_numpy
msgpack_numpy.patch()
import numpy as np

with open('temp/blah.mpk', 'w') as f:
    d = {'hey': np.array([1, 2, 3]),
         'cool': np.array(0., dtype=np.float32),
         'me': 10.,
         'you': 10,
         'stuff': ['a', [1, 2, 3], {'cool': 10}, np.array([1., 3.])],
         'string': 'boom'}
    for k, v in d.items():
        print k, type(v), v
        if isinstance(v, np.ndarray):
            print v.dtype
    f.write(msgpack.packb(d))
me <type 'float'> 10.0
string <type 'str'> boom
hey <type 'numpy.ndarray'> [1 2 3]
int64
stuff <type 'list'> ['a', [1, 2, 3], {'cool': 10}, array([ 1.,  3.])]
you <type 'int'> 10
cool <type 'numpy.ndarray'> 0.0
float32
with open('temp/blah.mpk') as g:
    d = msgpack.load(g)
    for k, v in d.items():
        print k, type(v), v
        if isinstance(v, np.ndarray):
            print v.dtype
me <type 'float'> 10.0
string <type 'str'> boom
hey <type 'numpy.ndarray'> [1 2 3]
int64
stuff <type 'list'> ['a', [1, 2, 3], {'cool': 10}, array([ 1.,  3.])]
you <type 'int'> 10
cool <type 'numpy.ndarray'> 0.0
float32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant