Whenever I try to use @jit on my class method, I get IndentationError: unexpected indent

admin

Administrator
Staff member
I've been trying for several days to get
Code:
@jit
working to speed up my code.
Finally I came across this, describing adding
Code:
@jit
to object methods:
<a href="http://williamjshipman.wordpress.com/2013/12/24/learning-python-eight-ways-to-filter-an-image" rel="nofollow">http://williamjshipman.wordpress.com/2013/12/24/learning-python-eight-ways-to-filter-an-image</a>

I have a class called
Code:
GentleBoostC
and I want to speed up the method within it that's called
Code:
train
.
Code:
train
accepts three arguments (a 2D array, a 1D array, and an integer), and returns nothing.

This is what I have in code:

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
Code:
@jit
, then there are no problems.

Here's the exact error:

Code:
   @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