atom-moyer / getpy

A Vectorized Python Dict/Set
MIT License
115 stars 14 forks source link

How to use MultiDict #3

Closed fjsj closed 4 years ago

fjsj commented 4 years ago

Hi, thanks for this lib! I see MultiDict is mentioned on the README, but I couldn't find tests for it.

Is it already supported? Is it possible to store sets of ints in a MultiDict?

atom-moyer commented 4 years ago

Yes. Dict(int, Set(int)) is implemented. I am not sure that I wanted to keep the current api, so consider it alpha stages. However, I use it for a project and I like the interface.

fjsj commented 4 years ago

Nice, how can I set values to a MultiDict? Tried this:

s = gp.Set(np.dtype('i8'))
s.add([1,2,3])
m = gp.MultiDict(np.dtype('i8'), np.dtype('i8'))
m[1] = s

But got TypeError at the last line.

atom-moyer commented 4 years ago

Sorry I forgot to answer this over the weekend.

The syntax for this is:

m = gp.MultiDict(np.dtype('i8'), np.dtype('i8'))

for i in [1,2,3]:
    m[1] = i

It will handle the multi-value set automatically. You just add one key-value pair at a time (or vectorized).

atom-moyer commented 4 years ago

Vectorized example:

m = gp.MultiDict(np.dtype('i8'), np.dtype('i8'))

keys = np.array([1,1,1])
values = np.array([1,2,3])

m[keys] = values