from numba import njit, prange
# from skimage.draw import line_nd
import numpy as np
import random
def _round_safe(coords):
if len(coords) > 1 and coords[0] % 1 == 0.5 and coords[1] - coords[0] == 1:
_round_function = np.floor
else:
_round_function = np.round
return _round_function(coords).astype(int)
def line_nd(start, stop, *, endpoint=False, integer=True):
start = np.asarray(start)
stop = np.asarray(stop)
npoints = int(np.ceil(np.max(np.abs(stop - start))))
if endpoint:
npoints += 1
coords = np.linspace(start, stop, num=npoints, endpoint=endpoint).T
if integer:
for dim in range(len(start)):
coords[dim, :] = _round_safe(coords[dim, :])
coords = coords.astype(int)
return tuple(coords)
@njit(parallel=True)
def get_all(a1):
for i1 in prange(1,999999): # Use prange for parallelism
a11 = random.randint(100, 10000)
start = np.asarray((11*a11*0.01, 22*a11*0.02, 33*a11*0.03))
stop = np.asarray((66.1, 77.1, 99.1))
line_nd(start,stop)
get_all(1)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Untyped global name ‘line_nd’: Cannot determine Numba type of <class ‘function’>
File “测试1.py”, line 35:
def get_all(a1):
stop = np.asarray((66.1, 77.1, 99.1))
line_nd(start,stop)
^
During: Pass nopython_type_inference