我可以从这里看到:NumbaPro Example在Anaconda工作时加速python的最简单方法就是简单地执行以下操作:
from numba import autojit
@autojit
def myfunction(params):
#do something
但是,我的情况略有不同,我在课堂上有一个功能,我想这可能就是我得到这个错误的原因:
class GentleBoostC:
File "C:\Users\app\Documents\Python Scripts\gentleboost_c_class.py", line 64, in GentleBoostC
@autojit
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 183, in autojit
nopython=nopython, locals=locals, **kwargs)(func)
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 164, in _autojit_decorator
compilerimpl = compiler_cls(env, f, nopython, flags, template_signature)
File "C:\Users\app\Anaconda\lib\site-packages\numba\wrapping\compiler.py", line 78, in __init__
self.ast = functions._get_ast(py_func)
File "C:\Users\app\Anaconda\lib\site-packages\numba\functions.py", line 89, in _get_ast
ast.PyCF_ONLY_AST | flags, True)
File "C:\Users\app\Documents\Python Scripts\gentleboost_c_class.py", line 1
def train(self, X, y, H):
^
IndentationError: unexpected indent
我的代码如下:
from sklearn.externals.six.moves import zip
import numpy as np
import statsmodels.api as sm
import math
from skimage import data, io, filter, color, exposure
from numba import autojit
class GentleBoostC:
# some initializer functions
@autojit
def train(self, X, y, H):
# do something
错误表示@autojit
行的缩进有问题,但是没有。如果我正在使用课程,是否有不同的方法可以使用它?我尝试在类定义之前添加行@autojit
,但这也不起作用。