Hi,
I am new to Numba,
I am trying to create a dictionary with uint
as keys and a list of uint
as values and the size (number of keys) of the dictionary will be a few hundred million or a few 10s of billions. So to gain speed and efficiency over the python dictionary I came across Numba and would like to use it.
Python = 3.7.7
Numba = 0.53.1
from numba import types, typed, njit
@njit
def numba_dict(list_of_lists):
key_dtype = types.uint64
value_dtype = types.uint8
bf_sparse_dict = typed.Dict.empty(
key_type=key_dtype, value_type=types.ListType(value_dtype)
)
for idx, inner_list in enumerate(list_of_lists):
for key in inner_list:
if key not in bf_sparse_dict:
bf_sparse_dict[key] = typed.List.empty_list(value_dtype)
bf_sparse_dict[key].append(idx)
else:
bf_sparse_dict[key].append(idx)
return bf_sparse_dict
When I try to run this function from a python file I get the following error
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<class 'numba.core.types.containers.ListType'>) found for
signature:
>>> ListType(class(uint8))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'ListType': File: numba/core/extending.py: Line 39.
With argument(s): '(class(uint8))':
Rejected as the implementation raised a specific error:
TypingError: List() argument must be iterable
raised from /home/ssk/anaconda3/envs/zarrtest/lib/python3.7/site-packages/numba/typed/typedlist.py:561
During: resolving callee type: Function(<class 'numba.core.types.containers.ListType'>)
During: typing of call at bitarray_leveldb_sparse_index.py (270)
File "bitarray_leveldb_sparse_index.py", line 270:
def numba_dict(bloomfilters_list):
<source elided>
bf_sparse_dict = typed.Dict.empty(
key_type=types.uint64, value_type=types.ListType(types.uint8)
But the same piece of code works completely fine on an interpreter from command line (i.e without compilation with @njit
decorator)
Any pointer to what I am doing wrong would be really helpful.
Thank you!