This code:
import numpy as np, numba as nb
@nb.njit(fastmath=True, locals=dict(image=nb.float32[:, :], peakMin=nb.float32))
def getProfile(image, peakMin=16):
h, w = image.shape
ds = np.zeros(h, dtype='f4')
ps = np.full(h, peakMin, dtype='i4')
cs = np.zeros(2, dtype='f4')
for ir in range(h):
for ic in range(3, w-4):
a, b, c, d, e, f, g = image[ir, ic-3:ic+4]
if (peakH := max(d-a, d-g)) > ps[ir] and a < b < c < d > e > f > g:
l0 = max(a, g)
l1 = (d+l0)/2
for i, l in enumerate([l0, l1]):
if a <= l < b:
x0 = (l-a)/(b-a) - 3
elif b <= l < c:
x0 = (l-b)/(c-b) - 2
else:
x0 = (l-c)/(d-c) - 1
if g <= l < f:
x1 = 3 - (l-g)/(f-g)
elif f <= l < e:
x1 = 2 - (l-f)/(e-f)
else:
x1 = 1 - (l-e)/(d-e)
cs[i] = (x0+x1)/2
ds[ir] = 2*cs[1]-cs[0] + ic
return ds
a = np.random.randint(255, size=(16, 16)).astype('f4')
print(getProfile(a))
produces the following output:
Traceback (most recent call last):
File "/home/paul/upwork/debone/code/profiler/so-17.py", line 40, in <module>
print(getProfile(a))
^^^^^^^^^^^^^
File "/home/paul/upwork/debone/code/profiler/.venv/lib/python3.11/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
error_rewrite(e, 'typing')
File "/home/paul/upwork/debone/code/profiler/.venv/lib/python3.11/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)
Type of variable '$322call.31' cannot be determined, operation: unknown operation, location: unknown location (0:0)
File "unknown location", line 0:
<source missing, REPL/exec in use?>
Is there anything I can do to get this function compiled?