I've been trying for several days to get @jit
working to speed up my code.
Finally I came across this, describing adding @jit
to object methods:
http://williamjshipman.wordpress.com/2013/12/24/learning-python-eight-ways-to-filter-an-image
I have a class called GentleBoostC
and I want to speed up the method within it that's called train
.
train
accepts three arguments (a 2D array, a 1D array, and an integer), and returns nothing.
This is what I have in code:
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
But I keep getting an indentation error, pointing to the line that defines the train function. There is nothing wrong with my indents. I have re-indented my entire code. And if I comment out the line with @jit
, then there are no problems.
Here's the exact error:
@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