簡體   English   中英

如何使用 numba.njit 運行成員 function

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM