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

后端 未结 1 697
既然无缘
既然无缘 2021-01-03 13:22

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: h

相关标签:
1条回答
  • 2021-01-03 13:57

    From what I can see from the documentation, you cannot apply the decorator to a method; the error you see is from the JIT parser not handling the source code indentation when not in the context of a class statement.

    If you want the body of that method to be compiled, you'll need to factor it out to a separate function, and call that function from the method:

    @jit(void(object_, float_[:,:], int_[:], int_)) 
    def train_function(instance, X, y, H):
        # do stuff
    
    class GentleBoostC(object):
        def train(self, X, y, H):
            train_function(self, X, y, H)    
    
    0 讨论(0)
提交回复
热议问题