[英]How to run a member function with numba.njit
我有一個名為medium
的 class ,我想提高這種名為train
的 class 方法的性能。
def train(self, episodeLength, T, doPlot = False, doSave = False, savePath = "./", meanTargetRewardInvAgent = None, collectiveTargetMeanReward = None):
但是,這個方法經常使用關鍵字self
,當我這樣調用方法時
trainCompiled = numba.njit(medium.train)
trainCompiled(episodeLength, T, doPlot = True, doSave = True, savePath = s_savePath)
它給
Failed in nopython mode pipeline (step: analyzing bytecode)
Variable 'self' is not defined.
當我將中等 class 實例作為參數傳遞給trainCompiled
時
some keyword arguments unexpected
File "/Volumes/Junction/Workspace/CellDev/NonEqui to ML/MLtoPhysics/AnnihilationModel/mltophysics-MxNet/main.py", line 39, in <module>
trainCompiled(medium, episodeLength, T, doPlot = True, doSave = True, savePath = s_savePath)
所以,長話短說,我如何使用numba.njit
?
你應該看看jit classes 。 “一個 jitclass 的所有方法都被編譯成 nopython 函數”。 因此,您應該使用@jitclass
裝飾您的 class medium
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.