--------------------------------------------------------------------------------------------------------------
@jitclass #编译Python类,为类生成代码,并指定每个字段的类型.
--------------------------------------------------------------------------------------------------------------
@jitclass #编译Python类,为类生成代码,并指定每个字段的类型.
from numba import jitclass
from numba import int32, float32
spec = [ ('value', int32), ('array', float32[:]), ]
@jitclass(spec)
class Bag(object):
def __init__(self, value): #必须定义,否则包含垃圾数据
self.value = value
self.array = np.zeros(value, dtype=np.float32)
@property
def size(self): #可定义方法和属性(仅限getter和setter)
return self.array.size
def increment(self, val):
for i in range(self.size):
self.array[i] = val
return self.array
a=Bag(4)
a.size
a.increment(100)# array([100., 100., 100., 100., 100.],dtype=float32)
--------------------------------------------------------------------------------------------------------------
来源:CSDN
作者:tcy23456
链接:https://blog.csdn.net/tcy23456/article/details/103963048