Asking about the dict in numba
See original GitHub issueDear Numba team I have using your library to optimize my code but when I apply it, I caught a trouble. Can you help me to fix it?
@jit
def encode2char_safe(input_lines, char_dict):
unk = char_dict['<u>']
forw_lines = [list(map(lambda m: list(map(lambda t: char_dict.get(t, unk), m)), line)) for line in input_lines]
return forw_lines
and the error
numba.core.errors.TypingError: Failed in object mode pipeline (step: convert make_function into JIT functions)
Cannot capture the non-constant value associated with variable 'char_dict' in a function that will escape.
def encode2char_safe(input_lines, char_dict):
<source elided>
unk = char_dict['<u>']
forw_lines = [list(map(lambda m: list(map(lambda t: char_dict.get(t, unk), m)), line)) for line in input_lines]
^
This error may have been caused by the following argument(s):
- argument 1: cannot determine Numba type of <class 'dict'>
can you help me to use numba to optimize my code. Thank you in advance and I hope to hearing from you soon.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Supported Python features - Numba
Currently, calling dict() translates to calling numba.typed.Dict() . Numba only supports the use of dict() without any arguments. Such use is semantically ...
Read more >Dictionaries as argument in numba - python - Stack Overflow
To achieve this, Numba has a typed dictionary, numba.typed.Dict , for which the type-inference mechanism must be able to infer the key-value ...
Read more >How to use a sequence as dict key? - #23 by ulupo - Support
I need to index a dict with sequences. In non-numba mode I normally use tuples, but in numba I can't because the tuple()...
Read more >numba/numba - Gitter
Dict in parallel in functions that are compiled with nogil=True ? would someone give a good ... I want to ask how numba...
Read more >Numba Public Discussion - Google Groups
Dear Ismael, thank you for asking about this issue on the Numba mailinglist. ... Dict.empty( key_type=numba.uint32, value_type=node_instance )) ```. unread,.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m afraid that I don’t think there is a way to fix this without hitting more problems, perhaps take a look at the 5 minute guide to find out what Numba is best at and whether it’s a good fit for your problem? I’d also suggest trying to simplify code as much as possible, it makes it easier for Numba to work out what to do (i.e.
map
s withlambda
s are really hard to analyse!).I will close this issue now, as I believe it has been resolved. If this is not the case, please don’t hesitate to reopen this or open a new one.