[英]How to run a member function with numba.njit
I have a class called medium
and I want to increase the perfomance of a method of this class called train
.我有一个名为medium
的 class ,我想提高这种名为train
的 class 方法的性能。
def train(self, episodeLength, T, doPlot = False, doSave = False, savePath = "./", meanTargetRewardInvAgent = None, collectiveTargetMeanReward = None):
However, this method uses the keyword self
a lot, and when I call the method like this但是,这个方法经常使用关键字self
,当我这样调用方法时
trainCompiled = numba.njit(medium.train)
trainCompiled(episodeLength, T, doPlot = True, doSave = True, savePath = s_savePath)
it gives它给
Failed in nopython mode pipeline (step: analyzing bytecode)
Variable 'self' is not defined.
and when I pass medium class instance as a parameter to trainCompiled
as当我将中等 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)
So, long story short, how can I run a member function using numba.njit
?所以,长话短说,我如何使用numba.njit
?
You should look jit classes .你应该看看jit classes 。 "All methods of a jitclass are compiled into nopython functions". “一个 jitclass 的所有方法都被编译成 nopython 函数”。 Thus, you should decorate your class medium
with @jitclass
.因此,您应该使用@jitclass
装饰您的 class medium
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.