deferred_type
例子这在Numba 0.27和更早版本中有效。改变
fifi.py
至:
from numba import jitclass, float64, deferred_type
from toto import toto
toto_type = deferred_type()
toto_type.define(toto.class_type.instance_type)
spec = [('a',float64),('b',float64),('c',toto_type)]
@jitclass(spec)
class fifi(object):
def __init__(self, combis):
self.a = combis
self.b = 2
self.c = toto(combis)
def mySqrt(self,x):
s = x
for i in xrange(self.a):
s = (s + x/s) / 2.0
return s
然后作为输出:
$ python test.py
Script running time: 0:00:01.991600
Sqrt of 144 is 12.041595
在一些更高级的jitclass数据结构示例中可以看到此功能,例如: