Numba dictionary(list) and numpy structured arrays?

Does numba dictionaries recognize numpy structured arrays?

Here is a simple example,

pointDtype = np.dtype([('x', 'f4'),('y', 'f4'),('z', 'f4')])
pointNBtype = nb.from_dtype(pointDtype)

p0 = np.array((0,0,0), dtype= pointNBtype)

dct = nb.typed.Dict.empty(nb.i8, pointNBtype)

Up to here all goes okay. But now if you want to enter p0 into the dictionary as such,

dct[1] = p0

you get an error???

I run into a similar issue trying to use a numba.typed.List

You’re confusing pointNBtype with array-of-pointNBtype. The value type of your dict is not an array.

to clarify, this is not about numpy structured arrays. what you’re doing won’t work with dtype=float64, either.

Okay @nelson2005 , I admit I must be confused. As it is p0 currently defined, how would you specify a numba dictionary to store it using an integer as a key?

Okay I see what is now going on.

I defined p0 originally to be,

p0 = np.array((0,0,0), dtype= pointNBtype)

without square brackets around it. When it should have been,

p0 = np.array([(0,0,0)], dtype= pointNBtype)

if so, then defining the dictionary as such (following up on a comment by @nelson2005),

dct = nb.typed.Dict.empty(nb.i8, pointNBtype[::1])
dct[0] = p0

works just fine. Similarly,

lst = nb.typed.List.empty_list(pointNBtype[::1])

this works for a list.