Hi forum,
How can I fix these errors reported by numba. Can numba be used on complex project?
Is True
a default argument value and are these two equal:
@jit(nopython=True)
@jit
I do not like the names: nopython
, @njit
. The latter one looks like nojit
.
Thanks
Case 1:
import random
import math
import string
import uuid
from numba import jit
class K:
def __init__(self, a='', b=0.0):
self.a = a
self.b = b
def __hash__(self):
return hash((self.a, self.b))
def __eq__(self, other):
return (self.a, self.b) == (other.a, other.b)
def __lt__(self, other):
return (self.a, self.b) < (other.a, other.b)
@jit(nopython=True)
def f():
d = {}
for i in range(1_00): # 100_000_000
d[K(uuid.uuid4(), random.random())] = random.random() # line 27
d = dict(sorted(d.items(), key=lambda item: item[0])) # out of loop
f()
$ date && python3 main.py && date
Wed Mar 23 02:23:07 CST 2022
Traceback (most recent call last):
File “/Users/ljh/Documents/helloPy/appdir/main.py”, line 33, in
f()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numba/core/dispatcher.py”, line 468, in _compile_for_args
error_rewrite(e, ‘typing’)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numba/core/dispatcher.py”, line 409, in error_rewrite
raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘K’: Cannot determine Numba type of <class ‘type’>
File “main.py”, line 27:
def f():
Case 2:
a = ''.join(random.choice(string.ascii_letters) for i in range(100))
numba.core.errors.UnsupportedError: Failed in nopython mode pipeline (step: inline calls to locally defined closures)
The use of yield in a closure is unsupported.
File “main.py”, line 41:
def f():
a = ‘’.join(random.choice(string.ascii_letters) for i in range(100))
^