vendredi 24 juin 2022

numba @jit(nopython=True): Refactor function that uses dictionary with lists as values

I have several functions that I want to use numba @jit(nopython=True) for, but they all rely on the following function:

def getIslands(labels2D,ignoreSea=True):
    islands = {}
    width = labels2D.shape[1]
    height = labels2D.shape[0]
    for x in range(width):
        for y in range(height):
            label = labels2D[y,x]
            if ignoreSea and label == -1:
                continue
            if label in islands:
                islands[label].append((x,y))
            else:
                islands[label] = [(x,y)]
    return islands

Is there any way to redesign this function so it's compatible with numba @jit(nopython=True)? The JIT fails since the function uses features of python dictionaries that are not supported (i.e., dictionaries containing lists as values.)

numba==0.52.0

Aucun commentaire:

Enregistrer un commentaire