如何jitclass下面的简单线程

时间:2017-12-26 16:00:59

标签: python numba

我有以下线程类和一个简单(Axis)类,它是平台的一部分。我想jitclass这两个类,但我的任何尝试都失败了。

class Axis(object):
    """
    :param config: configuration file
    :type config: ConfigParser
    """

    def __init__(self, config):
        self.config = config

class Platform(threading.Thread):
    """
    :param config: configuration file
    :type config: ConfigParser
    :param platformType: type of platform
    :type platformType: int
    """

    def __init__(self, config, platformType):
        threading.Thread.__init__(self)
        self.running = False
        self.platformType = platformType
        self.trace = False
        self.lock = threading.Event()
        self.syncLock = threading.Lock()
        self.axis = Axis(config)

有想法或参考的人吗?

1 个答案:

答案 0 :(得分:1)

您只能将numba数据类型的类作为属性进行jit编译。 例如,这有效:

from numba import jitclass, float64

axisspec = [('x', float64), ('y', float64)]

@jitclass(axisspec)
class Axis(object):

    def __init__(self, x, y):
        self.x = x
        self.y = y

Numba适合数字运算,不适用于一般的Python对象。 您的案例看起来更像是PyPy的应用程序。

相关问题