EDIT: I realized that numba says you cannot edit the dictionary parallel, so I’d lose the ability to parallelize if I did this and that is probably not worth the trade off.
Hello! I am attempting to precalculate a lookup table for an entire 2d grid - I successfully did it with a 2d array holding the results, but it would be faster to access if I had a dictionary instead. Here is what I currently have:
from numba.typed import Dict
from numba.core import types
@numba.jit(parallel=True)
def numba_create_world_lookup_table(local_x_scale, local_y_scale, local_height, local_width):
lookup_table = Dict.empty(types.unicode_type, numba.float64[:])
for x in numba.prange(local_width + 1):
for y in numba.prange(local_height + 1):
key = (x,y)
scaled_x_coord = x / local_x_scale
scaled_y_coord = y / local_y_scale
lookup_table[key] = (scaled_x_coord, scaled_y_coord)
return lookup_table
I have tried a 2d dict, using a str as a key and a few other things with no luck.
I get the following error:
No implementation of function Function(<built-in function setitem>) found for signature:
>>> setitem(DictType[unicode_type,array(float64, 1d, A)]<iv=None>, unicode_type, reflected list(float64)<iv=None>)
There are 16 candidate implementations:
- Of which 14 did not match due to:
Overload of function 'setitem': File: <numerous>: Line N/A.
With argument(s): '(DictType[unicode_type,array(float64, 1d, A)]<iv=None>, unicode_type, reflected list(float64)<iv=None>)':
No match.
- Of which 2 did not match due to:
Overload in function 'impl_setitem': File: numba\typed\dictobject.py: Line 706.
With argument(s): '(DictType[unicode_type,array(float64, 1d, A)]<iv=None>, unicode_type, reflected list(float64)<iv=None>)':
Rejected as the implementation raised a specific error:
NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering)
Cannot cast reflected list(float64)<iv=None> to array(float64, 1d, A): %"inserted.parent.1" = insertvalue {i8*, i8*} %"inserted.meminfo.2", i8* %"arg.value.1", 1
During: lowering "castedval = call $38load_global.5(value, $52load_deref.8, func=$38load_global.5, args=[Var(value, dictobject.py:714), Var($52load_deref.8, dictobject.py:716)], kws=(), vararg=None, varkwarg=None, target=None)" at C:\Projects\mpegs\venv\Lib\site-packages\numba\typed\dictobject.py (716)
raised from C:\Projects\mpegs\venv\Lib\site-packages\numba\core\base.py:704
During: typing of setitem at C:\Projects\mpegs\venv\Lib\site-packages\numba\typed\typeddict.py (34)
File "..\..\venv\Lib\site-packages\numba\typed\typeddict.py", line 34:
def _setitem(d, key, value):
d[key] = value
^