我已经尝试了好几天了@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
但我不断收到缩进错误,指向定义训练函数的行。我的缩进没有任何问题。我已经重新缩进了整个代码。如果我注释掉该行@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