0

我有以下类定义:

class GentleBoostC(object):
    def __init__(self):
        # do init stuff

    # add jit in order to speed up the code
    @jit 
    @void (float_[:,:],int_[:],int_)
    def train(self, X, y, H):
        # train do stuff

然后,在另一个文件中,我这样做:

import GentleBoostC as gbc

# initialize the 2D array X_train, the 1D array y_train, and the integer boosting_rounds

gentlebooster = gbc.GentleBoostC()
gentlebooster.train(X_train,y_train,boosting_rounds)

但后来我得到这个错误:

Traceback (most recent call last):
  File "C:\Users\app\Documents\Python Scripts\gbc_classifier_train.py", line 53, in <module>
    gentlebooster.train(X_train,y_train,boosting_rounds)
TypeError: _jit_decorator() takes exactly 1 argument (4 given)

我发现装饰器很混乱,直到这个错误我才意识到实现也jit使用了装饰器!或者至少我猜是这样。

4

1 回答 1

1

这里存在三个问题:

1) 最新的 Numba(0.14 版)不支持 jitting 类或类方法(jitting 类在 0.12 重构中丢失,但可能很快会重新添加)。

2) 没有 void 装饰器(尽管它可能存在于以前的版本中——我不记得了)。

3) jit 装饰器中没有正确指定函数签名。它应该类似于:@jit(void(float_[:,:], int_[:], int_)) 用于接受 2d float 数组、1d int 数组和 int 的函数,并且不返回任何内容。您也可以将其指定为字符串:@jit('void(f4[:,:], i4[:], i4')

于 2014-09-19T22:07:26.020 回答