我试图通过尝试一些简单的算法来理解numbapro中jit / vectorize背后的语义。这是miller-rabin素性测试,我想随后多次运行。
这很好用
from numbapro import jit , guvectorize , vectorize, uint64, int32, int8, bool_
import random
@jit(bool_(uint64,int32),target='cpu')
def is_prime(n,k):
if n % 2 == 0:
return False
# n-1 as 2^s * d
dn = n - 1
s1 = 0
while dn % 2 == 0:
dn = dn >> 1
s1 += 1
for j in range(k):
a1 = random.randint(2,n-2)
x = pow(a1,dn) % n
if x == 1 or x == n - 1:
continue
for i in range(s1):
x = (x * x) % n
if x == 1:
return False
if x == n - 1:
break
return True
但用
替换装饰器@vectorize(bool_(uint64,int32),target='cpu')
给出错误
Traceback (most recent call last):
File "h:\users\mushfaque.cradle\documents\visual studio 2013\Projects\EulerPraxis\EulerPraxis\EulerPraxis.py", line 12, in <module>
@vectorize(int8(uint64,int32),target='cpu')
File "H:\Apps\Anaconda3\lib\site-packages\numba\npyufunc\decorators.py", line 67, in wrap
for fty in ftylist:
TypeError: 'NotImplementedType' object is not callable
我知道vectorize应该用在ufuncs上,但是我错过了什么来使它成为一个ufunc?
答案 0 :(得分:0)
我已经解决了这个问题。