question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asking about the dict in numba

See original GitHub issue

Dear 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:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stuartarchibaldcommented, Jul 22, 2020

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. maps with lambdas are really hard to analyse!).

0reactions
esccommented, Jul 27, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found