【发布时间】:2017-08-28 17:45:04
【问题描述】:
试图弄清楚如何在使用 jitclass 时跳过类方法。
有一个相当大的递归模型(几乎是一个巨大的 for 循环),它 - 给定路径相关的计算,不能用直接 Numpy 向量化。
该类通过一系列 numpy 数组运行,通常具有 numba 友好的语法,但是我有一个部分以有序的方式调用一些方法:
def operations(self, i, ops_order_config):
ops_dict = self.ops_dict
for index in range(len(waterfall_config)):
try:
if isinstance(ops_config[index], tuple):
ops_dict[ops_config[index][0]](i, ops_config[index][1])
else:
ops_dict[ops_config[index]](i)
except KeyError:
pass
模型的这一部分对于灵活性非常重要——“配置”是一个有序的元组列表,其中包含要调用的适当方法和相应的参数。 ops_dict 包含实际的自我。从配置中调用,带有适当的参数。
如果我正在制作一个 jitclass,有什么办法可以跳过这个字典方面的 jitting 吗?
【问题讨论】:
标签: python numpy dictionary numba