vendredi 17 juillet 2020

Error while using numba in a loop with if any and if all

I am performing Pareto optimization of min-min type of a data set (i.e. data1 in code below) with 118800000 points. The code below is performing really slow and I couldn't get any result after running it for 6 hours. I am trying to use numba to increase the speed. But I get the following error. How can I rewrite the loop or fix the error to be able to use numba? Or there is a better approach?

Error

TypingError: Failed in nopython mode pipeline (step: nopython frontend) Untyped global name 'all': cannot determine Numba type of <class 'builtin_function_or_method'>

File "", line 8: def identify_pareto(data1): for j in range(population_size): if all(data1[j] <= data1[i]) and any(data1[j] < data1[i]): ^

This is not usually a problem with Numba itself but instead often caused by the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit: http://numba.pydata.org/numba-doc/dev/reference/pysupported.html and http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

For more information about typing errors and how to debug them visit: http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message and traceback, along with a minimal reproducer at: https://github.com/numba/numba/issues/new

Code

from numba import jit,float32
@jit(nopython=True)
def identify_pareto(data1):
    population_size = data1.shape[0]
    population_ids = np.arange(population_size)
    pareto_front = np.ones(population_size, dtype=bool)
    for i in range(population_size):
        for j in range(population_size):
            if all(data1[j] <= data1[i]) and any(data1[j] < data1[i]):
                pareto_front[i] = 0
                break
    return population_ids[pareto_front]
pareto = identify_pareto(data1)

Aucun commentaire:

Enregistrer un commentaire