Limitations in Numba

There are some instances where Numba cannot properly infer the variable types and will refuse to compile. In the following example, we define a function that takes a nested list of integers and returns the sum of the element in every sublist. In this case, Numba will raise ValueError and refuse to compile:

    a = [[0, 1, 2], 
[3, 4],
[5, 6, 7, 8]]

@nb.jit
def sum_sublists(a):
result = []
for sublist in a:
result.append(sum(sublist))
return result

sum_sublists(a)
# ValueError: cannot compute fingerprint of empty list

The problem with this code is that Numba is not able to determine the type of the list and fails. A way to fix this problem is to help the compiler determine the right type by initializing the list with a sample element and removing it at the end:

    @nb.jit
def sum_sublists(a):
result = [0]
for sublist in a:
result.append(sum(sublist))
return result[1:]

Among other features that are not yet implemented in the Numba compiler are function and class definitions, list, set and dict comprehension, generators, the with statement, and try except blocks. Note, however, that many of these features may become supported in the future.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.105.215