I've got this Python function which I'm trying to @jit
, but I can't really get around it (it's the first time I try jitting something, so I'm here to learn more than anything). I'll include the code (commented) and I'll explain what it does briefly:
def pwrchk(n, m):
no_prob = [] #The list that will contain the exponents
for i in range(2, m+1): #Start from 2 because 1 is useless
power = n**i
is_good = True #If this becomes false later, there's a zero.
for j in range(math.floor(math.log(power, 10)) + 1):
#The formula in the range is the number of digits of 'power'
digit = power % 10 #Returns the last digit so it can be checked
if digit in digits:
is_good = False #This is the check
power = 0
break
power = power // 10 #Gets rid of the digit just checked
if is_good:
no_prob.append(i) #Append to the list of "good" exponents
return no_prob
This function computes n^i
, with 2 < i < m
, and checks if n^i
contains a zero in its digits, and then returns a list of which exponents are such that n^i
contains no zeros. It works absolutely fine in normal Python compilation.
Since for big values of m
the execution time gets really long (I've tried m = 10^6
and it goes to a crawl), I thought of putting it in Anaconda to @jit
it. The problem is that when I use the @jit
decorator it tells me that it keeps falling back to object mode, so I can't compile it in nopython
mode.
I tried changing the lists to numpy
arrays and populating them with the powers of n
out of the for
cycle, changing math.floor(math.log(power, 10))
using numpy
to manage the arrays, nothing.
Am I doing something wrong? I'm sure there's a simple explanation to it that's just going over my head, but as said before I'm kinda new to Numba, so if I'm doing something really dumb please tell me, so I won't do it again in the future, and if I need to provide something else I'll update with anything needed.