我已经尝试了几天来@jit
加快我的代码速度。最后我遇到了这个,描述添加@jit
到对象方法:
http ://williamjshipman.wordpress.com/2013/12/24/learning-python-eight-ways-to-filter-an-image
我有一个名为的类GentleBoostC
,我想加快其中名为train
.
train
接受三个参数(一个二维数组、一个一维数组和一个整数),并且不返回任何内容。
这就是我在代码中的内容:
import numba
from numba import jit, autojit, int_, void, float_, object_
class GentleBoostC(object):
# lots of functions
# and now the function I want to speed up
@jit (void(object_,float_[:,:],int_[:],int_))
def train(self, X, y, H):
# do stuff
但我不断收到缩进错误,指向定义 train 函数的行。我的缩进没有任何问题。我重新缩进了我的整个代码。如果我用 注释掉该行@jit
,那么就没有问题。
这是确切的错误:
@jit (void(object_,float_[:,:],int_[:],int_))
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 224, in _jit_decorator
nopython=nopython, func_ast=func_ast, **kwargs)
File "C:\Users\app\Anaconda\lib\site-packages\numba\decorators.py", line 133, in compile_function
func_env = pipeline.compile2(env, func, restype, argtypes, func_ast=func_ast, **kwds)
File "C:\Users\app\Anaconda\lib\site-packages\numba\pipeline.py", line 133, in compile2
func_ast = functions._get_ast(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_jit_v5_nolimit.py", line 1
def train(self, X, y, H):
^
IndentationError: unexpected indent