我试图通过尝试一些简单的算法来理解 numbapro 中 jit/vectorize 背后的语义。这是米勒拉宾素性测试,我想随后运行多次。
这工作正常
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
我知道应该在 ufunc 上使用矢量化,但是我缺少什么来使它成为 ufunc?