我正在使用 numpy 1.8.x 和 numba。我有一个名为 的函数train
,它具有以下定义:
@autojit
def train_function( X, y, H):
它返回一个 3D numpy 数组。
然后我有一个类,它调用这个函数,如下所示:
class GentleBoostC(object):
# different methods including init
# and now the train function
def train(self, X, y, H):
self.g_per_round = train_function(X,y,H)
然后我实例化这个类并用它来训练一个对象。
# initiate the variables X_train, y_train and boosting_rounds
gentlebooster = gbc.GentleBoostC() # gbc has already been imported
gentlebooster.train(X_train,y_train,boosting_rounds)
但后来我得到这个错误:
gentlebooster.train(X_train,y_train,boosting_rounds)
File "C:\Users\app\Documents\Python Scripts\gentleboost_c_class_jit_v7_nolimit.py", line 299, in train
self.g_per_round = train_function(self,X, y, H)
File "C:\Anaconda\lib\site-packages\numba\dispatcher.py", line 152, in typeof_pyval
dtype = numpy_support.from_dtype(val.dtype)
File "C:\Anaconda\lib\site-packages\numba\numpy_support.py", line 61, in from_dtype
raise NotImplementedError(dtype)
NotImplementedError: object
这里出了什么问题?
编辑
查看文档,它说:
异常 NotImplementedError
此异常源自
RuntimeError
. 在用户定义的基类中,抽象方法在需要派生类覆盖方法时应该引发此异常。
这将如何转化为我的情况?
编辑
有关我如何调用 train 函数的更多详细信息:
#img_hogs and sample_labels have already been populated above, both are numpy arrays
X_train = np.array(img_hogs)
y_train = np.array(sample_labels)
boosting_rounds = 7
gentlebooster = gbc.GentleBoostC()
gentlebooster.train(X_train,y_train,boosting_rounds)