numba对于numpy的支持是最完善的,对于python中的list、dict、tuple等数据类型要不就是不支持优化要不就是支持优化但是使用存在一定的局限性,所以比较建议尽量把输入用numpy的方式表示起来。
有时候为了方便,我们希望numba所修饰的函数能够接受结构体类型的参数该怎么办,因为python中没有显式的struct函数,只有class函数可以用来充当struct来用。
import numpy
class Point():
"""
Arguments:
domain: the domain of random generated coordinates x,y,z,
default=1.0
Attributes:
x, y, z: coordinates of the point
"""
def __init__(self, domain=1.0):
self.x = domain * numpy.random.random()
self.y = domain * numpy.random.random()
self.z = domain * numpy.random.random()
def distance(self, other):
return ((self.x - other.x)**2 +
(self.y - other.y)**2 +
(self.z - other.z)**2)**.5
class Particle(Point):
"""
Attributes:
m: m