因此,根据How to use Python Class with Numba给出的问题和答案 以及numba https://numba.pydata.org/numba-doc/dev/user/jitclass.html
的参考页我试图在这种环境下编译一个类。
最初,我为该类定义了一个规范,并添加了相应的签名
@jitclass(spec)
在类定义之前。就像参考资料和先前的答案一样。
spec = [('max_k_w',float64),
('max_k_o',float64),
('lw',float64),
('ew',float64),
('tw',float64),
('lo',float64),
('eo',float64),
('to',float64),
('u0',float64),
('mu_w',float64),
('mu_o',float64)]
@jitclass(spec)
class LET_Perm():
self.params = {
"max_kr_w" : max_k_w,
"max_kr_o" : max_k_o,
"L_w_coeff(Moghadasi2015)" : lw,
"E_w_coeff(Moghadasi2015)" : ew,
"T_w_coeff(Moghadasi2015)" : tw,
"L_o_coeff(Moghadasi2015)" : lo,
"E_o_coeff(Moghadasi2015)" : eo,
"T_o_coeff(Moghadasi2015)" : to,
"residual_w" : u_0,
"viscosity_o" : mu_w,
"viscosity_w" : mu_o
}
# model definitions and parameters
max_k_w = self.params["max_kr_w"]
max_k_o = self.params["max_kr_o"]
在下面的许多行中,我将此类称为
bl = LET_Perm(0.533,0.781,4.02,2.0,0.41,1,1.18,1.28,0.2,0.97,1.74)
我在类中定义了相应的属性函数(我假设我们只编写此语句一次,说从现在开始,该类内部以及以后的所有函数都将经历numba过程。)
不幸的是,在运行脚本时,我收到下一条消息:
File "let_perm.py", line 40:
def __init__(self,max_k_w=0.533,max_k_o=0.781,lw=4.02,ew=2.0,tw=0.41,
<source elided>
"viscosity_o" : mu_w,
"viscosity_w" : mu_o
^
[1] During: resolving callee type: jitclass.LET_Perm#5606fa569e48<max_k_w:float64,max_k_o:float64,lw:float64,ew:float64,tw:float64,lo:float64,eo:float64,to:float64,u0:float64,mu_w:float64,mu_o:float64>
[2] During: typing of call at <string> (3)
我知道参数应该是浮点数,但是在类中将它们视为浮点数。...self.params []对象建立了等效性吗?