`from numba import jit, cuda,njit
import numpy as np
import numba as nb
from timeit import default_timer as timer
from numba.core.errors import NumbaDeprecationWarning, NumbaPendingDeprecationWarning
import warnings
warnings.simplefilter('ignore')
# normal function to run on cpu
class test:
def func(self,a):
for i in range(100000000):
a+= 1
print(a)
@nb.jit() # throw Error because of exception handling
def func2(self):
try:
print('main block')
except Exception:
print('handler block')
# @nb.jit() # it's Working
# def func2(self,a):
# for i in range(100000000):
# a+= 1
# print(a)
if __name__=="__main__":
t=test()
start = timer()
t.func(10)
print("without GPU:", timer()-start)
start = timer()
t.func2()
print("with GPU:", timer()-start)`
我的期望:
100000010 没有 GPU:4.227983299992047 100000010 带 GPU:0.48296340001979843
抛出这个错误:-
numba.core.errors.NumbaNotImplementedError:对象模式管道失败(步骤:对象模式后端)
参数 0:无法确定